@samitouri / QOSami-HFS / commits / d5cb5b41

support alpha-paging with inverted order

Massimo Melina committed Jul 4, 2026 at 12:07 UTC d5cb5b412b975573ada279d7ecda8a6f05894643
1 file changed +12 -15
frontend/src/Paging.ts
+12 -15
@@ -41,8 +41,8 @@ export const Paging = memo(({ nPages, current, pageSize, list, changePage, chang
41 const from = _.floor(current, -1)
42 const to = from + 10
43 const snap = useSnapState()
44 - const showAlphabet = snap.sort_by === 'name' && !snap.invert_order
45 - const alphabetGroups = useMemo(() => showAlphabet ? getAlphabetGroups(list) : [], [list, showAlphabet])
44 + const alphabetGroups = useMemo(() => snap.sort_by === 'name' ? getAlphabetGroups(list, snap.invert_order) : [],
45 + [list, snap.sort_by, snap.invert_order])
46 useEffect(() => {
47 if (!alphabetGroups.length)
48 setAlphabetOpen(false)
@@ -118,28 +118,25 @@ function AlphabetPaging({ groups, open, toggleOpen, close, changePage }: Alphabe
118 )
119 }
120
121 -function getAlphabetGroups(list: DirEntry[]) {
121 +function getAlphabetGroups(list: DirEntry[], invertOrder: boolean) {
122 const groups: AlphabetGroup[] = []
123 const seen = new Set<string>()
124 list.forEach((entry, index) => {
125 - const label = getAlphabetGroup(entry.name)
125 + const first = Array.from(entry.name.trim())[0] || ''
126 + if (!first) return
127 + const latin = first.normalize('NFD').replace(/\p{Diacritic}/gu, '').toUpperCase()
128 + const upper = first.toLocaleUpperCase()
129 + const label = /^[A-Z]$/.test(latin) ? latin
130 + : /\p{Letter}/u.test(upper) ? upper
131 + : ''
132 if (!label) return
133 if (seen.has(label)) return
134 seen.add(label)
135 groups.push({ label, index })
136 })
137 // the list order can include non-letter entries and custom filename collation; the index stays tied to the first real entry
132 - return groups.length > 1 ? groups.sort((a, b) => getHFS().textSortCompare(a.label, b.label)) : []
133 -}
134 -
135 -function getAlphabetGroup(name: string) {
136 - const first = Array.from(name.trim())[0] || ''
137 - if (!first) return ''
138 - const latin = first.normalize('NFD').replace(/\p{Diacritic}/gu, '').toUpperCase()
139 - if (/^[A-Z]$/.test(latin))
140 - return latin
141 - const upper = first.toLocaleUpperCase()
142 - return /\p{Letter}/u.test(upper) ? upper : ''
138 + const order = invertOrder ? -1 : 1
139 + return groups.length > 1 ? groups.sort((a, b) => order * getHFS().textSortCompare(a.label, b.label)) : []
140 }
141
142 export function scrollIntoView(el: Element | undefined | null, block: ScrollLogicalPosition) {