better code: centralized wiki links
Massimo Melina committed
May 5, 2023 at 15:30 UTC
a54b30603a005d2f00f2702349ad04cba6aca490
5 files changed
+21
-12
admin/src/CustomHtmlPage.ts
+4
-4
@@ -3,14 +3,13 @@
3
import { createElement as h, Fragment, useEffect, useMemo, useState } from 'react';
4
import { Field, SelectField } from '@hfs/mui-grid-form'
5
import { apiCall, useApiEx } from './api'
6
-import { Alert, Box, Link } from '@mui/material'
6
+import { Alert, Box } from '@mui/material'
7
import Editor from 'react-simple-code-editor'
8
-import { Dict, IconBtn, isCtrlKey, modifiedSx, reloadBtn } from './misc';
8
+import { Dict, IconBtn, isCtrlKey, modifiedSx, reloadBtn, wikiLink } from './misc';
9
import { Save } from '@mui/icons-material'
10
import _ from 'lodash'
11
import { useDebounce } from 'usehooks-ts'
12
import md from './md'
13
-import { REPO_URL } from './HomePage'
13
14
export default function CustomHtmlPage() {
15
const { data, reload } = useApiEx<{ sections: Dict<string> }>('get_custom_html')
@@ -30,7 +29,8 @@ export default function CustomHtmlPage() {
29
return h(Fragment, {},
30
h(Alert, { severity: 'info' },
31
md("Add HTML code to some parts of the Front-end. It's saved to file `custom.html`, that you can edit directly with your editor of choice. "),
33
- h(Link, { href: REPO_URL + "wiki/customization", target: 'help' }, "More help")),
32
+ wikiLink('customization', "More help")
33
+ ),
34
h(Box, { display: 'flex', alignItems: 'center', gap: 1, mb: 1 },
35
h(SelectField as Field<string>, { label: "Section", value: sec, options, onChange: setSec }),
36
reloadBtn(reload),
admin/src/HomePage.ts
+2
-4
@@ -3,7 +3,7 @@
3
import { createElement as h, useState } from 'react'
4
import { Box, Button, LinearProgress, Link } from '@mui/material'
5
import { apiCall, useApi, useApiEx, useApiList } from './api'
6
-import { Btn, dontBotherWithKeys, InLink, objSameKeys, onlyTruthy, prefix, wait } from './misc'
6
+import { Btn, dontBotherWithKeys, InLink, objSameKeys, onlyTruthy, prefix, REPO_URL, wait, wikiLink } from './misc'
7
import { BrowserUpdated as UpdateIcon, CheckCircle, Error, Info, Launch, Warning } from '@mui/icons-material'
8
import md from './md'
9
import { state, useSnapState } from './state'
@@ -14,8 +14,6 @@ import { Account } from './AccountsPage'
14
import _ from 'lodash'
15
import { subscribeKey } from 'valtio/utils'
16
17
-export const REPO_URL = 'https://github.com/rejetto/hfs/'
18
-
17
interface ServerStatus { listening: boolean, port: number, error?: string, busy?: string }
18
19
interface Status {
@@ -76,7 +74,7 @@ export default function HomePage() {
74
reloadCfg()
75
}
76
}, "ignore this warning"),
79
- SOLUTION_SEP, h(Link, { target: 'help', href: REPO_URL + 'wiki/Proxy-warning' }, "Explanation")
77
+ SOLUTION_SEP, wikiLink('Proxy-warning', "Explanation")
78
),
79
status.frpDetected && entry('warning', `FRP is detected. It should not be used with "type = tcp" with HFS. Possible solutions are`,
80
h('ol',{},
admin/src/OptionsPage.ts
+3
-3
@@ -5,7 +5,7 @@ import { createElement as h, Fragment, useEffect, useRef } from 'react';
5
import { apiCall, useApi, useApiEx } from './api'
6
import { state, useSnapState } from './state'
7
import { Info, Refresh, Warning } from '@mui/icons-material'
8
-import { Dict, modifiedSx, with_ } from './misc'
8
+import { Dict, modifiedSx, wikiLink, with_ } from './misc'
9
import {
10
Form,
11
BoolField,
@@ -18,7 +18,7 @@ import {
18
} from '@hfs/mui-grid-form';
19
import FileField from './FileField'
20
import { alertDialog, closeDialog, confirmDialog, formDialog, newDialog, toast, waitDialog } from './dialog'
21
-import { proxyWarning, REPO_URL } from './HomePage'
21
+import { proxyWarning } from './HomePage'
22
import _ from 'lodash';
23
import { proxy, subscribe, useSnapshot } from 'valtio'
24
@@ -286,7 +286,7 @@ function AllowedReferer({ label, value, onChange, error }: FieldProps<string>) {
286
}
287
288
function WildcardsSupported() {
289
- return h(Link, { target: 'help', href: REPO_URL + 'wiki/Wildcards' }, "Wildcards supported")
289
+ return wikiLink('Wildcards', "Wildcards supported")
290
}
291
292
function suggestMakingCert() {
admin/src/misc.ts
+8
@@ -197,3 +197,11 @@ export function Flex({ gap='.8em', vert=false, children=null, props={}, ...rest
197
...props
198
}, children)
199
}
200
+
201
+
202
+export const REPO_URL = 'https://github.com/rejetto/hfs/'
203
+export const WIKI_URL = REPO_URL + '/wiki/'
204
+
205
+export function wikiLink(uri: string, content: ReactNode) {
206
+ return h(Link, { href: WIKI_URL + uri, target: 'help' }, content)
207
+}
\ No newline at end of file
mui-grid-form/index.ts
+4
-1
@@ -41,7 +41,10 @@ export interface FieldDescriptor<T=any> {
41
export type Field<T> = FC<FieldProps<T>>
42
43
export type Promisable<T> = T | Promise<T>
44
-interface FieldApi { getError: () => Promisable<ValidationError>, [rest: string]: any }
44
+interface FieldApi {
45
+ // provide getError if you want your error to be visible by the Form component
46
+ getError: () => Promisable<ValidationError>, [rest: string]: any
47
+}
48
export interface FieldProps<T> {
49
label?: string | ReactElement
50
value?: T