fix: admin/fs: crash changing link #137
Massimo Melina committed
Mar 6, 2023 at 11:31 UTC
5c053312e6903444904cd194b13d3393971383d9
2 files changed
+5
-5
admin/src/FileForm.ts
+4
-4
@@ -21,7 +21,7 @@ import _ from 'lodash'
21
import FileField from './FileField'
22
import { alertDialog, useDialogBarColors } from './dialog'
23
import yaml from 'yaml'
24
-import { ContentCopy, Delete, Edit } from '@mui/icons-material'
24
+import { Check, ContentCopy, Delete, Edit } from '@mui/icons-material'
25
26
interface Account { username: string }
27
@@ -180,7 +180,7 @@ interface LinkFieldProps extends FieldProps<string> {
180
}
181
function LinkField({ value, urls, }: LinkFieldProps) {
182
const { data, error, reload } = useApiEx('get_config', { only: ['base_url'] })
183
- const base = data?.base_url
183
+ const base: string | undefined = data?.base_url
184
const link = (base || (urls ? urls[0] : '')) + encodeURI(value||'')
185
return h(Box, { display: 'flex', },
186
h(DisplayField, {
@@ -215,12 +215,12 @@ function LinkField({ value, urls, }: LinkFieldProps) {
215
key: u,
216
selected: u === v,
217
onClick: () => set(u),
218
- }, u))
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",
223
- value: urls.includes(v) ? '' : v.slice(proto.length),
223
+ value: !v || urls.includes(v) ? '' : v.slice(proto.length),
224
onChange: v => set(proto + v),
225
start: proto,
226
sx: { mt: 2 }
admin/src/VfsPage.ts
+1
-1
@@ -38,7 +38,7 @@ export default function VfsPage() {
38
}, [vfs])
39
const sideBreakpoint = 'md'
40
const isSideBreakpoint = useBreakpoint(sideBreakpoint)
41
- const [status] = useApi(window.location.host === 'localhost' && 'get_status')
41
+ const [status] = useApi('get_status')
42
const urls = useMemo(() =>
43
typeof status === 'object' && _.sortBy(
44
Object.values(status.urls?.https || status.urls?.http || {}) as string[],