@samitouri / QOSami-HFS / commits / 17f82ac5

fix: using 'search' when listing was just started led to inconsistent state

Massimo Melina committed Feb 26, 2024 at 10:26 UTC 17f82ac53424b0c25a6424b1b039f3668666a4b1
1 file changed +6 -5
frontend/src/menu.ts
+6 -5
@@ -28,12 +28,12 @@ export function MenuPanel() {
28
29 const {t} = useI18N()
30
31 - const [started1secAgo, setStarted1secAgo] = useStateMounted(false)
31 + const [justStarted, setJustStarted] = useStateMounted(false)
32 useEffect(() => {
33 if (!stopSearch) return
34 - setStarted1secAgo(false)
35 - setTimeout(() => setStarted1secAgo(true), 1000)
36 - }, [stopSearch, setStarted1secAgo])
34 + setJustStarted(false)
35 + setTimeout(() => setJustStarted(true), 1000)
36 + }, [stopSearch, setJustStarted])
37
38 // passing files as string in the url should allow 1-2000 items before hitting the url limit of 64KB. Shouldn't be a problem, right?
39 const ofs = location.pathname.length
@@ -119,7 +119,7 @@ export function MenuPanel() {
119 )
120
121 function getSearchProps() {
122 - return stopSearch && started1secAgo ? {
122 + return stopSearch && justStarted ? { // don't change the state of the search button immediately to avoid it flicking at every folder change
123 id: 'search-stop-button',
124 icon: 'stop',
125 label: t`Stop list`,
@@ -143,6 +143,7 @@ export function MenuPanel() {
143 async onClick() {
144 state.remoteSearch = await promptDialog(t('search_msg', "Search this folder and sub-folders"),
145 { title: t`Search`, onSubmit: x => x.includes('/') ? throw_(t`Invalid value`) : x }) || ''
146 + state.stopSearch?.()
147 }
148 }
149 }