plugins: entry.getDefaultIcon
Massimo Melina committed
May 24, 2023 at 15:46 UTC
8e899b7dd38bbb7827b3fb5be24e36eec03288d7
3 files changed
+9
-4
dev-plugins.md
+2
-1
@@ -201,6 +201,7 @@ This is a list of available frontend-events, with respective object parameter an
201
- `cantOpen: boolean` true if current user has no permission to open this entry
202
- `getNext/getPrevious: ()=>Entry` return next/previous Entry in list
203
- `getNextFiltered/getPreviousFiltered: ()=>Entry` as above, but considers the filtered-list instead
204
+ - `getDefaultIcon: ()=>ReactElement` produces the default icon for this entry
205
- output `Html`
206
- `afterEntryName`
207
- you receive each entry of the list, and optionally produce HTML code that will be added after the name of the entry.
@@ -261,7 +262,7 @@ HFS will scan through them in inverted alphabetical order searching for a compat
262
## API version history
263
264
- 8.2 (v0.46.0)
264
- - entry.getNext, getPrevious, getNextFiltered, getPreviousFiltered
265
+ - entry.getNext, getPrevious, getNextFiltered, getPreviousFiltered, getDefaultIcon
266
- 8.1 (v0.45.0) should have been 0.44.0 but forgot to update number
267
- full URL support for frontend_js and frontend_css
268
- custom.html
frontend/src/BrowseFiles.ts
+2
-2
@@ -100,7 +100,7 @@ function FilesList() {
100
return h(Fragment, {},
101
h('ul', { ref, className: 'dir', ...acceptDropFiles(can_upload && enqueue) },
102
msgInstead ? h('p', {}, msgInstead)
103
- : theList.slice(offset, offset + pageSize * (1+extraPages)).map((entry: DirEntry, idx) =>
103
+ : theList.slice(offset, offset + pageSize * (1+extraPages)).map((entry, idx) =>
104
h(Entry, {
105
key: entry.n,
106
midnight,
@@ -235,7 +235,7 @@ export function getEntryIcon(entry: DirEntry) {
235
return h(CustomCode, {
236
name: 'entryIcon',
237
props: { entry },
238
- ifEmpty: () => hIcon(entry.isFolder ? 'folder' : 'file')
238
+ ifEmpty: () => entry.getDefaultIcon()
239
})
240
}
241
frontend/src/state.ts
+5
-1
@@ -3,6 +3,7 @@
3
import _ from 'lodash'
4
import { proxy, useSnapshot } from 'valtio'
5
import { subscribeKey } from 'valtio/utils'
6
+import { hIcon } from './misc'
7
8
export const state = proxy<{
9
stopSearch?: ()=>void,
@@ -119,10 +120,13 @@ export class DirEntry {
120
getPreviousFiltered() {
121
return this.getSibling(-1, state.filteredList)
122
}
122
- getSibling(ofs: number, list: DirList=state.list) {
123
+ getSibling(ofs: number, list: DirList=state.list) { // i'd rather make this private, but valtio is messing with types, causing problems in FilesList()
124
return list[ofs + list.findIndex(x => x.n === this.n)]
125
}
126
127
+ getDefaultIcon() {
128
+ return hIcon(this.isFolder ? 'folder' : 'file')
129
+ }
130
}
131
export type DirList = DirEntry[]
132