better code
Massimo Melina committed
Jul 4, 2026 at 12:03 UTC
e3c2bcdd7441a4787d845e170bdc27735230587b
2 files changed
+5
-5
frontend/src/BrowseFiles.ts
-1
@@ -251,7 +251,6 @@ function FilesList() {
251
atBottom,
252
pageSize,
253
list: theList as DirEntry[],
254
- showAlphabet: snap.sort_by === 'name' && !snap.invert_order,
254
changePage,
255
changePageToIndex,
256
})
frontend/src/Paging.ts
+5
-4
@@ -2,7 +2,7 @@
2
3
import { createElement as h, memo, useEffect, useMemo, useRef, useState } from 'react'
4
import _ from 'lodash'
5
-import { DirEntry } from './state'
5
+import { DirEntry, useSnapState } from './state'
6
import { domOn, getHFS, hIcon } from './misc'
7
import i18n from './i18n'
8
const { t } = i18n
@@ -15,7 +15,6 @@ interface PagingProps {
15
atBottom: boolean
16
pageSize: number
17
list: DirEntry[]
18
- showAlphabet: boolean
18
changePage: (newPage:number, goBottom?:boolean) => void
19
changePageToIndex: (entryIndex: number) => void
20
}
@@ -25,7 +24,7 @@ interface AlphabetGroup {
24
index: number
25
}
26
28
-export const Paging = memo(({ nPages, current, pageSize, list, showAlphabet, changePage, changePageToIndex, atBottom }: PagingProps) => {
27
+export const Paging = memo(({ nPages, current, pageSize, list, changePage, changePageToIndex, atBottom }: PagingProps) => {
28
const [alphabetOpen, setAlphabetOpen] = useState(false)
29
useEffect(() => {
30
document.body.style.overflowY = 'scroll'
@@ -41,6 +40,8 @@ export const Paging = memo(({ nPages, current, pageSize, list, showAlphabet, cha
40
const shrink = nPages > 20
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])
46
useEffect(() => {
47
if (!alphabetGroups.length)
@@ -69,7 +70,7 @@ export const Paging = memo(({ nPages, current, pageSize, list, showAlphabet, cha
70
className: atBottom ? 'toggled' : undefined,
71
onClick(){ changePage(nPages-1, true) }
72
}, hIcon('to_end')),
72
- Boolean(alphabetGroups.length) && h(AlphabetPaging, {
73
+ alphabetGroups.length > 0 && h(AlphabetPaging, {
74
groups: alphabetGroups,
75
open: alphabetOpen,
76
toggleOpen: () => setAlphabetOpen(x => !x),