let user access the folder of a file in a search-result
Massimo Melina committed
Jan 1, 2022 at 21:39 UTC
bcb4a52b280060cf508601c2405b6138b73e6acb
4 files changed
+16
-4
frontend/src/BrowseFiles.ts
+12
-2
@@ -43,10 +43,16 @@ function File({ n, m, c, s, hidden }: DirEntry & { hidden:boolean }) {
43
const base = usePath()
44
const isDir = n.endsWith('/')
45
const t = m||c ||null
46
- const href = n.replace(/#/g, encodeURIComponent)
46
+ const containerDir = isDir ? '' : n.substring(0, n.lastIndexOf('/')+1)
47
+ if (containerDir)
48
+ n = n.substring(containerDir.length)
49
+ const href = fix(containerDir + n)
50
return h('li', { style:hidden ? { display:'none' } : null },
51
isDir ? h(Link, { to: base+href }, hIcon('folder'), n)
49
- : h('a', { href }, hIcon('file'), n),
52
+ : h(Fragment, {},
53
+ containerDir && h(Link, { to: base+fix(containerDir), className:'container-folder' }, hIcon('file'), containerDir ),
54
+ h('a', { href }, !containerDir && hIcon('file'), n)
55
+ ),
56
h('div', { className:'entry-props' },
57
s !== undefined && h(Fragment, {},
58
h('span', { className:'entry-size' }, formatBytes(s)),
@@ -57,3 +63,7 @@ function File({ n, m, c, s, hidden }: DirEntry & { hidden:boolean }) {
63
h('div', { style:{ clear:'both' } })
64
)
65
}
66
+
67
+function fix(s:string) {
68
+ return s.replace(/#/g, encodeURIComponent)
69
+}
frontend/src/icons.ts
+1
-1
@@ -18,7 +18,7 @@ document.fonts.ready.then(async ()=> {
18
state.iconsClass = name.replace(/ /g,'-').toLowerCase()
19
})
20
21
-export function Icon({ name, className, ...props }: { name:string, className?:string, style?:any }) {
21
+export function Icon({ name, className='', ...props }: { name:string, className:string, style?:any }) {
22
name = SYS_ICONS[name] || name
23
const { iconsClass } = useSnapState()
24
return h('span',{
frontend/src/index.scss
+3
@@ -114,6 +114,9 @@ ul.dir {
114
& .icon {
115
margin-right: .3em;
116
}
117
+ &.container-folder:hover {
118
+ text-decoration: underline;
119
+ }
120
}
121
& .entry-props {
122
float: right;
todo.md
-1
@@ -1,5 +1,4 @@
1
# To do
2
-- let user access the folder of a file in a search-result
2
- anti-csrf
3
- file sorting
4
- folders before?