admin/fs: better ux with 'change link'

Massimo Melina committed Mar 9, 2023 at 13:24 UTC 11101a9ce0c164217c8206ae20cee7a5108ec138
3 files changed +8 -6
admin/src/FileForm.ts
+5 -4
@@ -14,7 +14,7 @@ import {
14 StringField
15 } from '@hfs/mui-grid-form'
16 import { apiCall, useApiEx } from './api'
17 -import { formatBytes, IconBtn, isEqualLax, modifiedSx, newDialog, onlyTruthy } from './misc'
17 +import { formatBytes, IconBtn, isEqualLax, modifiedSx, newDialog, onlyTruthy, prefix } from './misc'
18 import { reloadVfs, VfsNode, VfsPerms, Who } from './VfsPage'
19 import md from './md'
20 import _ from 'lodash'
@@ -218,10 +218,11 @@ function LinkField({ value, urls, }: LinkFieldProps) {
218 }, u, u === v && h(Check, { sx: { ml: 2 } })))
219 ),
220 h(StringField, {
221 - label: "Custom address",
222 - helperText: "Use this field if you need to enter a different address",
221 + label: "Custom IP or domain",
222 + helperText: md("You can type any address but *you* are responsible to make the address work.\nThis functionality is just to help you copy the link in case you have a domain or a complex network configuration."),
223 value: !v || urls.includes(v) ? '' : v.slice(proto.length),
224 - onChange: v => set(proto + v),
224 + onChange: v => set(prefix(proto, v)),
225 + onTyping: v => /^[-\w.[\]:]*$/.test(v),
226 start: proto,
227 sx: { mt: 2 }
228 }),
frontend/src/index.scss
+2 -1
@@ -370,7 +370,8 @@ button label {
370 background-color: var(--button-bg);
371 border-radius: 20px;
372 border: 1px solid var(--ghost-contrast)
373 - } }
373 + }
374 + }
375 }
376 @media (max-width: 42em) {
377 :root { --ghost-contrast: #8883; } /* phones have different curve */
src/misc.ts
+1 -1
@@ -98,7 +98,7 @@ onFirstEvent(process, ['exit', 'SIGQUIT', 'SIGTERM', 'SIGINT', 'SIGHUP'], signal
98 export function onFirstEvent(emitter:EventEmitter, events: string[], cb: (...args:any[])=> void) {
99 let already = false
100 for (const e of events)
101 - emitter.on(e, (...args) => {
101 + emitter.once(e, (...args) => {
102 if (already) return
103 already = true
104 cb(...args)