#272 Keep undated assets last regardless of album sort order

This commit is contained in:
Alan Grainger
2026-07-27 12:27:03 +12:00
parent 0f972782dc
commit 55bd63e3f2
2 changed files with 78 additions and 6 deletions
+19 -6
View File
@@ -4,7 +4,7 @@ import {
videoUrl
} from '../immich'
import { Response } from 'express-serve-static-core'
import { AssetType, ImageSize, SharedLink } from '../types'
import { Asset, AssetType, ImageSize, SharedLink } from '../types'
import { getConfigOption, getNumericConfigOption } from '../config/access'
import { canDownload, expiryDate, title } from '../share'
import { toString } from '../utils/text'
@@ -34,11 +34,7 @@ export async function gallery (res: Response, share: SharedLink, openItem?: numb
// contiguous / ordered.
const groupByDate = groupByDateMode()
if (groupByDate) {
const ascending = share.album?.order === 'asc'
const sortKey = (a: typeof share.assets[number]) => a.localDateTime || a.fileCreatedAt || ''
share.assets.sort((a, b) => ascending
? sortKey(a).localeCompare(sortKey(b))
: sortKey(b).localeCompare(sortKey(a)))
share.assets.sort(dateSortComparator(share.album?.order))
}
// Metadata display flags. Read once here and forwarded to the client via
@@ -171,6 +167,23 @@ function description (share: SharedLink) {
return share?.album?.description || ''
}
/**
* Comparator for the date-grouping sort: ascending when the album's order is
* `'asc'`, otherwise newest-first (individual shares and orderless albums).
* Undated assets always sort last regardless of direction, so the client's
* "Undated" group renders at the bottom.
*/
export function dateSortComparator (order?: string): (a: Asset, b: Asset) => number {
const ascending = order === 'asc'
const sortKey = (a: Asset) => a.localDateTime || a.fileCreatedAt || ''
return (a, b) => {
const ka = sortKey(a)
const kb = sortKey(b)
if (!ka || !kb) return ka ? -1 : kb ? 1 : 0 // undated always last
return ascending ? ka.localeCompare(kb) : kb.localeCompare(ka)
}
}
/**
* Normalise the operator's `ipp.gallery.groupByDate` config into a grouping
* mode. Accepts `false` (off), `true` / `'month'` (legacy = month buckets) or