plugins: frontend event 'sortCompare'

Massimo Melina committed Sep 7, 2024 at 12:21 UTC 86ab563633ba75242b5c478667a83a37556032cc
2 files changed +12 -3
dev-plugins.md
+10 -2
@@ -295,8 +295,9 @@ Some frontend-events can return Html, which can be expressed in several ways
295 - as array of ReactNode
296 - null, undefined, false and empty-string will just be discarded
297
298 -These events will receive a `def` property, with the default content that will be displayed if no callback return
299 -a valid output. You can decide to embed such default content inside your content.
298 +These events will receive a `def` property (in addition event's specific properties),
299 +with the default content that will be displayed if no callback return a valid output.
300 +You can decide to embed such default content inside your content.
301 You can produce output for such events also by adding sections (with same name as the event) to file `custom.html`.
302
303 This is a list of available frontend-events, with respective object parameter and output.
@@ -381,6 +382,12 @@ This is a list of available frontend-events, with respective object parameter an
382 - `uriChanged`
383 - DEPRECATED: use `watchState('uri', callback)` instead.
384 - parameter `{ uri: string, previous: string }`
385 +- `sortCompare`
386 + - you can decide the order of entries by comparing two entries.
387 + Return a negative value if entry `a` must appear before `b`, or positive if you want the opposite.
388 + Return zero or any falsy value if you want to leave the order to what the user decided in his options.
389 + - parameter `{ a: Entry, b: Entry }`
390 + - output `number | undefined`
391 - All of the following have no parameters and you are supposed to output `Html` that will be displayed in the described place:
392 - `afterMenuBar` between menu-bar and breadcrumbs
393 - `afterList` at the end of the files list
@@ -635,6 +642,7 @@ If you want to override a text regardless of the language, use the special langu
642 - frontend event: paste
643 - exports.customRest + HFS.customRestCall
644 - config.type: vfs_path
645 + - frontend event: sortCompare
646 - 8.891 (v0.53.0)
647 - api.openDb
648 - frontend event: menuZip
frontend/src/useFetchList.ts
+2 -1
@@ -145,7 +145,8 @@ function sort(list: DirList) {
145 const byTime = sort_by === 'time'
146 const invert = state.invert_order ? -1 : 1
147 return list.sort((a,b) =>
148 - folders_first && -compare(a.isFolder, b.isFolder)
148 + hfsEvent('sortCompare', { a, b }).find(Boolean)
149 + || folders_first && -compare(a.isFolder, b.isFolder)
150 || invert * (bySize ? compare(a.s||0, b.s||0)
151 : byExt ? localCompare(a.ext, b.ext)
152 : byTime ? compare(a.t, b.t)