@samitouri / QOSami-HFS / commits / 0873a75c

plugins: HFS.iconBtn, HFS.domOn

Massimo Melina committed Jun 9, 2024 at 19:22 UTC 0873a75c57af20ad3d29ef9792062dcf1cc3325e
3 files changed +8 -4
dev-plugins.md
+4 -1
@@ -202,7 +202,7 @@ The `api` object you get as parameter of the `init` contains the following:
202
203 - `openDb(filename, options): Promise<{ get, put, del, close, unlink, sublevel }>` LevelDB-like class for storage.
204 The specified file name will be stored in the "storage" folder of the plugin, by default.
205 - Refer to [dedicated documentation](https://www.npmjs.com/package/@rejetto/kvstorage) for details.
205 + DB is automatically closed when the plugin is unloaded. Refer to [dedicated documentation](https://www.npmjs.com/package/@rejetto/kvstorage) for details.
206
207 - `notifyClient(channel: string, eventName: string, data?: any)` send a message to those frontends that are on the same channel.
208
@@ -220,6 +220,7 @@ The HFS objects contains many properties:
220 - `logout`
221 - `prefixUrl: string` normally an empty string, it will be set in case a [reverse-proxy wants to mount HFS on a path](https://github.com/rejetto/hfs/wiki/Reverse-proxy).
222 - `state: StateObject` [object with many values in it](https://github.com/rejetto/hfs/blob/main/frontend/src/state.ts)
223 + - you'll find here some interesting values, like `username` and `loading`.
224 - `watchState(key: string, callback): function`
225 - watch the `key` property of the state object above
226 - `callback(newValue)` will be called at each change
@@ -239,6 +240,8 @@ The HFS objects contains many properties:
240 - `Icon: ReactComponent` Properties:
241 - `name: string` refer to file `icons.ts` for names, but you can also enter an emoji instead.
242 - `iconBtn(icon: string, onClick: function, props?: any)` render a React Icon Button. For icons, refer to `Icon` component.
243 +- `domOn(eventName: string, cb: function, { target }?): function` convenient alternative to addEventListener/removeEventListener.
244 + The default target is window. Returns a callback to remove the listener.
245 - `useBatch(worker, job): any`
246 - `getNotifications(channel: string, cb: (eventName: string, data:any) => void)`
247 receive messages when the backend uses `notifyClient` on the same channel.
frontend/src/misc.ts
+3 -2
@@ -4,7 +4,7 @@ import React, { createElement as h } from 'react'
4 import { iconBtn, Spinner } from './components'
5 import { newDialog, toast } from './dialog'
6 import { Icon } from './icons'
7 -import { Dict, getHFS, Html, HTTP_MESSAGES, useBatch } from '@hfs/shared'
7 +import { Dict, domOn, getHFS, Html, HTTP_MESSAGES, useBatch } from '@hfs/shared'
8 import * as cross from '../../src/cross'
9 import * as shared from '@hfs/shared'
10 import { apiCall, getNotifications, useApi } from '@hfs/shared/api'
@@ -59,7 +59,8 @@ export function hfsEvent(name: string, params?:Dict) {
59 }
60
61 const tools = {
62 - h, React, state, t, _, dialogLib, apiCall, useApi, reloadList, logout, Icon, hIcon, iconBtn, useBatch, fileShow, toast,
62 + h, React, state, t, _, dialogLib, apiCall, useApi, reloadList, logout, Icon, hIcon, iconBtn, useBatch, fileShow,
63 + toast, domOn,
64 misc: { ...cross, ...shared },
65 watchState(k: string, cb: (v: any) => void) {
66 const up = k.split('upload.')[1]
package.json
+1 -1
@@ -71,7 +71,7 @@
71 "dependencies": {
72 "@koa/router": "^12.0.1",
73 "@node-rs/crc32": "^1.6.0",
74 - "@rejetto/kvstorage": "^0.9.7",
74 + "@rejetto/kvstorage": "^0.10.0",
75 "acme-client": "^5.2.0",
76 "basic-auth": "^2.0.1",
77 "buffer-crc32": "^0.2.13",