better code
Massimo Melina committed
Jan 11, 2025 at 11:44 UTC
b8841b4b352d7f378fb0f93c3fa2e0abde2bc7a2
4 files changed
+9
-6
frontend/src/BrowseFiles.ts
+1
-1
@@ -3,7 +3,7 @@
3
import { Link, useNavigate } from 'react-router-dom'
4
import { createElement as h, Fragment, memo, MouseEvent, useCallback, useEffect, useMemo, useRef, useState,
5
useId} from 'react'
6
-import { useDocumentTitle, useEventListener, useMediaQuery, useWindowSize } from 'usehooks-ts'
6
+import { useEventListener, useMediaQuery, useWindowSize } from 'usehooks-ts'
7
import {
8
domOn, formatBytes, ErrorMsg, hIcon, onlyTruthy, noAriaTitle, prefix, isMac, isCtrlKey, hfsEvent, formatTimestamp
9
} from './misc'
frontend/src/icons.ts
+4
-3
@@ -16,6 +16,7 @@ Promise.race([documentComplete, document.fonts?.ready]).then(async () => {
16
})
17
18
interface IconProps { name:string, className?:string, alt?:string, [rest:string]: any }
19
+// name = null ? none : unicode ? unicode : "?" ? file_url : font_icon_class
20
export const Icon = memo(({ name, alt, className='', ...props }: IconProps) => {
21
if (!name) return null
22
const [emoji, clazz=name] = SYS_ICONS[name] || []
@@ -23,14 +24,14 @@ export const Icon = memo(({ name, alt, className='', ...props }: IconProps) => {
24
className += ' icon'
25
const nameIsTheIcon = name.length === 1 ||
26
name.match(/^[\uD800-\uDFFF\u2600-\u27BF\u2B00-\u2BFF\u3030-\u303F\u3297\u3299\u00A9\u00AE\u200D\u20E3\uFE0F\u2190-\u21FF\u2300-\u23FF\u2400-\u243F\u25A0-\u25FF\u2600-\u26FF\u2700-\u27BF]*$/)
26
- const nameIsFile = !nameIsTheIcon && /[.?]/.test(name)
27
+ const nameIsUrl = !nameIsTheIcon && /[/?]/.test(name)
28
const isFontIcon = iconsReady && clazz
28
- className += nameIsFile ? ' file-icon' : isFontIcon ? ` fa-${clazz}` : ' emoji-icon'
29
+ className += nameIsUrl ? ' file-icon' : isFontIcon ? ` fa-${clazz}` : ' emoji-icon'
30
return h('span',{
31
...alt ? { 'aria-label': alt } : { 'aria-hidden': true },
32
role: 'img',
33
...props,
33
- ...nameIsFile ? { style: { backgroundImage: `url(${JSON.stringify(name)})`, ...props?.style } } : undefined,
34
+ ...nameIsUrl ? { style: { backgroundImage: `url(${JSON.stringify(name)})`, ...props?.style } } : undefined,
35
className,
36
}, nameIsTheIcon ? name : isFontIcon ? null : (emoji||'#'))
37
})
frontend/src/sysIcons.ts
+1
-1
@@ -1,4 +1,4 @@
1
-export const SYS_ICONS: Record<string, [string] | [string, string | false]> = { // false means we don't have the icon, only unicode
1
+export const SYS_ICONS: Record<string, [string] | [string, string | false]> = { // undefined = font-icon name same as key ; false = no font-icon, only unicode
2
login: ['👤','user'],
3
user: ['👤','user'],
4
filter: ['✂'],
src/plugins.ts
+3
-1
@@ -128,7 +128,9 @@ async function initPlugin(pl: any, morePassedToInit?: { id: string } & Dict<any>
128
getCurrentUsername,
129
...morePassedToInit
130
})
131
- return Object.assign(pl, typeof res === 'function' ? { unload: res } : res)
131
+ Object.assign(pl, typeof res === 'function' ? { unload: res } : res)
132
+ events.emit('pluginInitialized', pl)
133
+ return pl
134
}
135
136
const already = new Set()