fix: admin: dialogs fullscreen first time

Massimo Melina committed Feb 17, 2023 at 23:21 UTC 8974b100db3b75881f833c348c53520a4fce8dbe
3 files changed +11 -11
admin/src/ConfigPage.ts
+5 -10
@@ -5,7 +5,7 @@ import { createElement as h, useEffect, useRef } from 'react';
5 import { apiCall, useApi, useApiEx } from './api'
6 import { state, useSnapState } from './state'
7 import { Info, Refresh } from '@mui/icons-material'
8 -import { Dict, modifiedSx } from './misc'
8 +import { Dict, modifiedSx, with_ } from './misc'
9 import { subscribeKey } from 'valtio/utils'
10 import {
11 Form,
@@ -225,18 +225,18 @@ function ServerPort({ label, value, onChange, getApi, status, suggestedPort=1, e
225 }
226
227 function AllowedReferer({ label, value, onChange, error }: FieldProps<string>) {
228 - const yesno = !value || value==='-'
228 + const yesNo = !value || value==='-'
229 const example = 'example.com'
230 return h(Box, { display: 'flex' },
231 h(SelectField as Field<string>, {
232 label,
233 - value: yesno ? value : example,
233 + value: yesNo ? value : example,
234 options: { "allow all": '', "forbid all": '-', "allow some": example, },
235 onChange,
236 error,
237 - sx: yesno ? undefined : { maxWidth: '11em' },
237 + sx: yesNo ? undefined : { maxWidth: '11em' },
238 }),
239 - !yesno && h(StringField, {
239 + !yesNo && h(StringField, {
240 label: "Domain to allow",
241 value,
242 placeholder: 'example.com',
@@ -309,8 +309,3 @@ async function makeCert(attributes: Record<string, string>) {
309 private_key: pki.privateKeyToPem(keys.privateKey),
310 }
311 }
312 -
313 -export function with_<T,RT>(par:T, cb: (par:T) => RT) {
314 - return cb(par)
315 -}
316 -
admin/src/dialog.ts
+1 -1
@@ -30,7 +30,7 @@ export * from '@hfs/shared/dialogs'
30 dialogsDefaults.Container = function Container(d:DialogOptions) {
31 const ref = useRef<HTMLElement>()
32 const { width, height } = useWindowSize()
33 - const mobile = Math.min(width, height) < 500
33 + const mobile = width > 0 && Math.min(width, height) < 500
34 useEffect(()=> {
35 const h = setTimeout(() => {
36 const el = ref.current
shared/index.ts
+5
@@ -80,6 +80,11 @@ export function try_(cb: () => any, onException?: (e:any) => any) {
80 return onException?.(e)
81 }
82 }
83 +
84 +export function with_<T,RT>(par:T, cb: (par:T) => RT) {
85 + return cb(par)
86 +}
87 +
88 export function domOn<K extends keyof WindowEventMap>(eventName: K, cb: (ev: WindowEventMap[K]) => void, { target=window }={}) {
89 target.addEventListener(eventName, cb)
90 return () => target.removeEventListener(eventName, cb)