fix: bad path returned searching within a real folder
Massimo Melina committed
Dec 24, 2021 at 17:31 UTC
9e2237c501d6bfeae907bfe7478e0c43087b4eda
3 files changed
+32
-25
frontend/src/Head.ts
+24
-23
@@ -2,7 +2,7 @@ import { createElement as h, Fragment, useContext, useMemo, useState } from 'rea
2
import { Link, useLocation } from 'react-router-dom'
3
import { ListContext } from './BrowseFiles'
4
import { login, logout } from './login'
5
-import { formatBytes, hIcon, prefix, wait } from './misc'
5
+import { formatBytes, hIcon, prefix } from './misc'
6
import { Spinner } from './components'
7
import { state, useSnapState } from './state'
8
import { useDebounce } from 'use-debounce'
@@ -34,28 +34,29 @@ function MenuPanel() {
34
setShowFilter(!showFilter)
35
}
36
}),
37
- h(MenuButton, {
38
- icon: 'search',
39
- label: 'Search',
40
- async onClick() {
41
- const res = prompt('Search for...')
42
- if (res === null) return
43
- if (state.stoppedSearch) {
37
+ h(MenuButton,
38
+ stopSearch ? {
39
+ icon: 'stop',
40
+ label: 'Stop list',
41
+ className: 'ani-working',
42
+ onClick() {
43
+ stopSearch()
44
+ state.stoppedSearch = true
45
+ }
46
+ } : state.remoteSearch ? {
47
+ icon: 'search_off',
48
+ label: 'Clear search',
49
+ onClick() {
50
state.remoteSearch = ''
45
- await wait(500)
51
}
47
- stopSearch?.()
48
- state.remoteSearch = res
49
- }
50
- }),
51
- stopSearch && h(MenuButton, {
52
- icon: 'stop',
53
- label: 'Stop list',
54
- onClick() {
55
- stopSearch()
56
- state.stoppedSearch = true
52
+ } : {
53
+ icon: 'search',
54
+ label: 'Search',
55
+ async onClick() {
56
+ state.remoteSearch = prompt('Search for...') ||''
57
+ }
58
}
58
- })
59
+ )
60
),
61
remoteSearch && h('div', { id:'searched' }, 'Searched for: ',remoteSearch),
62
showFilter && h('input',{
@@ -70,8 +71,8 @@ function MenuPanel() {
71
)
72
}
73
73
-function MenuButton({ icon, label, toggled, onClick }:{ icon:string, label:string, toggled?:boolean, onClick?:()=>void }) {
74
- return h('button', { title:label, onClick, className:toggled ? 'toggled' : '' },
74
+function MenuButton({ icon, label, toggled, onClick, className='' }:{ icon:string, label:string, toggled?:boolean, className?:string, onClick?:()=>void }) {
75
+ return h('button', { title:label, onClick, className:className+' '+(toggled ? 'toggled' : '') },
76
hIcon(icon),
77
h('label',{}, label))
78
}
@@ -113,7 +114,7 @@ function FolderStats() {
114
}, [list])
115
const { filteredEntries, stoppedSearch } = useSnapState()
116
return h('div', { id:'folder-stats' },
116
- stoppedSearch ? hIcon('interrupted') : loading && h(Spinner),
117
+ stoppedSearch ? hIcon('interrupted', { title:'Search was interrupted' }) : loading && h(Spinner),
118
[
119
prefix('', stats.files,' file(s)'),
120
prefix('', stats.folders, ' folder(s)'),
frontend/src/index.scss
+6
@@ -48,6 +48,12 @@ header {
48
padding: .2em;
49
}
50
51
+.ani-working { animation:1s blink infinite }
52
+
53
+@keyframes blink {
54
+ 0% {opacity: 1}
55
+ 50% {opacity: 0.1}
56
+}
57
@keyframes spin {
58
from { transform: rotate(0deg); }
59
to { transform: rotate(360deg); }
src/vfs.ts
+2
-2
@@ -137,7 +137,7 @@ export async function* walkNode(parent:VfsNode, who:string, depth:number=0, pref
137
continue
138
yield prefixPath ? { ...c, name: prefixPath+c.name } : c
139
if (depth > 0 && c)
140
- yield* walkNode(c, prefixPath+c.name+'/', depth - 1)
140
+ yield* walkNode(c, '', depth - 1, prefixPath+c.name+'/')
141
}
142
if (!source)
143
return
@@ -158,7 +158,7 @@ export async function* walkNode(parent:VfsNode, who:string, depth:number=0, pref
158
yield {
159
type: VfsNodeType.temp,
160
source: path,
161
- name: parent!.rename?.[name] || name
161
+ name: prefixPath + (parent!.rename?.[name] || name)
162
}
163
}
164
}