better code

Massimo Melina committed Feb 17, 2026 at 14:27 UTC 6cbdc6a89a9aa34c115b7bad7511a4f8bfaadde4
6 files changed +12 -11
mui-grid-form/index.ts
+5 -5
@@ -198,7 +198,7 @@ export function Form<Values extends Dict>({
198 variant: 'contained',
199 startIcon: h(Save),
200 children: "Save",
201 - loading: useDebounce(phase !== Phase.Idle), // debounce fixes click being ignored at state change, and flickering
201 + loading: useDebounce(phase !== Phase.Idle), // debounce fixes click being ignored at state change and flickering
202 ...saveBtn,
203 onClick: pleaseSubmit,
204 }) }),
@@ -206,7 +206,7 @@ export function Form<Values extends Dict>({
206 )
207 )
208
209 - function pleaseSubmit() { // we use state here to let outer component perform its state changes
209 + function pleaseSubmit() { // we use state here to let the outer component perform its state changes
210 submitAfterValidation.current = true
211 pleaseValidate()
212 }
@@ -215,7 +215,7 @@ export function Form<Values extends Dict>({
215 if (phase !== Phase.Idle) return
216 validateUpTo.current = k
217 setTimeout(() => // starting validation immediately will lose clicks on the saveBtn, so delay just a bit
218 - setPhase(cur => cur === Phase.Idle ? Phase.WaitValues : cur)) // don't interfere with ongoing process
218 + setPhase(cur => cur === Phase.Idle ? Phase.WaitValues : cur)) // don't interfere with the ongoing process
219 }
220
221 function getValueFor(k : string) {
@@ -240,7 +240,7 @@ export function Form<Values extends Dict>({
240 || false
241 }
242 catch(e) {
243 - err = String(e) // keep exception as error
243 + err = String(e)
244 }
245 errs[k] = err
246 if (!submitAfterValidation.current && k === validateUpTo.current) break
@@ -273,5 +273,5 @@ export function Form<Values extends Dict>({
273
274 export function labelFromKey(k: string) {
275 return _.upperFirst(k.indexOf('_') > 0 ? k.replace(/_/g, ' ')
276 - : k.replace(/([a-z])([A-Z])/g, (all,a,b) => a + ' ' + b.toLowerCase()))
276 + : k.replace(/([a-z])([A-Z])/g, (_all, a, b) => a + ' ' + b.toLowerCase()))
277 }
shared/index.ts
+2 -2
@@ -80,7 +80,7 @@ export function domOn<
80 options?: O
81 ) {
82 const target = options && 'target' in options ? options.target : window
83 - if (!target) return
83 + if (!target) return () => {}
84 target.addEventListener(eventName, cb as EventListener, options)
85 return () => target.removeEventListener(eventName, cb as EventListener, options)
86 }
@@ -233,7 +233,7 @@ export async function copyTextToClipboard(text: string) {
233 if (!document.execCommand('copy'))
234 throw Error('unknown')
235 }
236 - finally { undo?.() }
236 + finally { undo() }
237 }
238 }
239
src/adminApis.ts
+1 -1
@@ -222,7 +222,7 @@ const frpDebounced = debounceAsync(async () => {
222 }, { retain: 10_000 })
223
224 export function anyAccountCanLoginAdmin() {
225 - return Boolean(_.find(accounts.get(), accountCanLoginAdmin))
225 + return _.some(accounts.get(), accountCanLoginAdmin)
226 }
227
228 export function preventAdminAccess(ctx: Koa.Context) {
src/api.log.ts
+1 -1
@@ -58,7 +58,7 @@ export default {
58 return list.ready()
59 }
60 // for other logs we only provide updates. Use get_log_file to download past content
61 - if (_.some(files, x => !_.find(loggers, { name: x })) )
61 + if (_.some(files, x => !_.some(loggers, { name: x })) )
62 return list.error(HTTP_NOT_FOUND, true)
63 list.ready()
64 // unsubscribe when the connection is interrupted
src/api.vfs.ts
+2 -1
@@ -52,7 +52,7 @@ export default {
52 ...node.original || node,
53 inherited,
54 byMasks: _.isEmpty(byMasks) ? undefined : byMasks,
55 - website: Boolean(node.children?.find(isSameFilenameAs('index.html')))
55 + website: node.children?.some(isSameFilenameAs('index.html'))
56 || isFolder && source && await statWithTimeout(join(source, 'index.html')).then(() => true, () => undefined)
57 || undefined,
58 name: getNodeName(node),
@@ -70,6 +70,7 @@ export default {
70 if (props.name && props.name !== getNodeName(n)) {
71 if (!isValidFileName(props.name))
72 return new ApiError(HTTP_BAD_REQUEST, 'bad name')
73 + // check for siblings with the same name
74 const parent = await urlToNodeOriginal(dirname(uri))
75 if (parent?.children?.find(x => getNodeName(x) === props.name))
76 return new ApiError(HTTP_CONFLICT, 'name already present')
tests/test.ts
+1 -1
@@ -939,7 +939,7 @@ function reqList(uri:string, tester:Tester, params?: object, options?: ReqOption
939 }
940
941 function isInList(res:any, name:string) {
942 - return Array.isArray(res?.list) && Boolean((res.list as any[]).find(x => x.n===name))
942 + return Array.isArray(res?.list) && (res.list as any[]).some(x => x.n===name)
943 }
944
945 function rmAny(path: string) {