diff --git a/utils/libraryBrowse.ts b/utils/libraryBrowse.ts index 79fb23d..792e12a 100644 --- a/utils/libraryBrowse.ts +++ b/utils/libraryBrowse.ts @@ -184,6 +184,11 @@ export function familyRootClip(parts: LibraryClip[]): LibraryClip { return chronologicalParts(parts)[0] || parts[0] } +/** Newest part in a family — keeps extended collections at the top of date sorts. */ +export function familyActivityAt(parts: Array<{ createdAt?: number }>) { + return parts.reduce((max, part) => Math.max(max, Number(part.createdAt) || 0), 0) +} + export function familyLongestDuration(parts: LibraryClip[]) { return parts.reduce((max, part) => Math.max(max, Number(part.duration) || 0), 0) } @@ -413,7 +418,7 @@ export function buildLibraryEntries(opts: { : groupClips(clips).map(group => ({ kind: 'clip' as const, key: group.key, - createdAt: group.head.createdAt, + createdAt: familyActivityAt(group.parts), name: collectionTitle(group), group })) @@ -422,7 +427,7 @@ export function buildLibraryEntries(opts: { : groupStills(stills).map(group => ({ kind: 'still' as const, key: group.key, - createdAt: group.head.createdAt, + createdAt: familyActivityAt(group.parts), name: stillCollectionTitle(group), stillGroup: group }))