Skip to content

An open-source, self-hosted system for apps built with web technologies.

The Desktop's dialogs are React UI Dialogs, over the dimmed Desktop

zohayrslileh5a1219b07368
diff --git a/source/client/view/structure/desktop/layers/shell/dialogs/open-requests.tsx b/source/client/view/structure/desktop/layers/shell/dialogs/open-requests.tsx
index f64f5aa..0ea7cc4 100644
--- a/source/client/view/structure/desktop/layers/shell/dialogs/open-requests.tsx
+++ b/source/client/view/structure/desktop/layers/shell/dialogs/open-requests.tsx
@@ -1,56 +1,35 @@
import type { OpenRequestSnapshot } from "@phreshos/core"
import { ReactTunnel } from "@the-link/react"
-import { surfaceLifecyclePose, surfacePresenceTransition } from "@client/view/appearance/surface-presence"
-import { useReducedMotion } from "@libs/react-motion"
-import { motion } from "motion/react"
-import { useEffect, useId, useRef, useState } from "react"
+import { useState } from "react"
import { ApplicationContext, AuthManagerContext } from "@client/view/contexts"
-import ShellSurface, { shellSurfaceClassName } from "../shell-surface"
+import { useDesktopScaleContainer } from "../../../desktop-scale"
+import useShown from "./shown"
import usePromise from "@libs/react-promise"
import Alert from "@client/view/components/alert"
import usePrograms from "@client/view/structure/desktop/programs/programs"
import programIcon from "@client/view/structure/desktop/programs/program-icon"
-import { Button, Checkbox, Text, useAppearance, useScale, useTiming } from "@phreshos/react-ui"
+import { Button, Checkbox, Dialog, useAppearance, useScale } from "@phreshos/react-ui"
-/** The default Shell's choice of a Program for something that has no default one. */
+/**
+ * The default Shell's choice of a Program for something that has no default one: the first request
+ * waiting, as a Dialog over the dimmed Desktop, which a choice or Cancel ends.
+ */
export default function OpenRequests() {
const manager = AuthManagerContext.useValue().openingManager
const inbound = ReactTunnel.useFactory(manager.$inbound)
const requests = inbound.useFirstState("/requests", manager.list())
const request = requests[0]
- const surface = useRef<HTMLDialogElement>(null)
- const title = useId()
- const reducedMotion = useReducedMotion()
- const transaction = useTiming()("change")
-
- useEffect(() => {
-
- const element = surface.current
-
- if (!request || !element || element.open) return
-
- element.showModal()
-
- return () => { if (element.open) element.close() }
- }, [request?.identity])
-
- if (!request) return null
-
- return <motion.dialog
- ref={surface}
- aria-modal="true"
- aria-labelledby={title}
- initial={reducedMotion ? surfaceLifecyclePose.visible : surfaceLifecyclePose.hidden}
- animate={surfaceLifecyclePose.visible}
- transition={surfacePresenceTransition(reducedMotion, transaction)}
- onCancel={event => { event.preventDefault(); void manager.cancel(request.identity).catch(() => undefined) }}
- className={`${shellSurfaceClassName} pointer-events-auto fixed inset-0 m-auto h-fit w-[min(24rem,calc(100dvw/var(--desktop-scale)-var(--desktop-gutter)*2))] backdrop:bg-transparent`}
- >
- <ShellSurface material="full" label="Open with" labelId={title}>
- <OpenRequestView key={request.identity} request={request} />
- </ShellSurface>
- </motion.dialog>
+ const container = useDesktopScaleContainer()
+ const shown = useShown(request)
+
+ return <Dialog open={request !== undefined}>
+ <Dialog.Backdrop portalContainer={container ?? undefined} keyboardDismissable={false}>
+ <Dialog.Content style={{ width: "24rem" }}>
+ {shown && <OpenRequestView request={shown} />}
+ </Dialog.Content>
+ </Dialog.Backdrop>
+ </Dialog>
}
function OpenRequestView({ request }: Readonly<{ request: OpenRequestSnapshot }>) {
@@ -65,29 +44,29 @@ function OpenRequestView({ request }: Readonly<{ request: OpenRequestSnapshot }>
: manager.choose(request.identity, program, { always }))
const programs = request.programs.map(offered => installed.find(program => program.identity === offered.identity)).filter(program => program !== undefined)
- return <div className="grid" style={{ gap: space.medium }}>
-
- <div className="grid" style={{ gap: space.xsmall }}>
- <span className="truncate" title={request.target.uri}><Text style={{ fontWeight: 500 }}>{describe(request.target.uri)}</Text></span>
- <Text tone="secondary" size="small">{request.from ? `${request.from.process.program.name} asks to open it` : "Opened from outside the Desktop"} · {request.target.type}</Text>
- </div>
-
- <div className="grid" style={{ gap: space.xsmall }}>
- {programs.map(program => <Button key={program.identity} disabled={decision.isPending} onPress={() => decision.safeExecute(program.identity)}
- style={{ justifyContent: "flex-start" }}>
- <img src={programIcon(application.doors.program, program.assetId)} alt="" draggable={false} className="shrink-0 object-contain" style={{ width: space.large, height: space.large }} />
- {program.name}
- </Button>)}
- </div>
-
- <Checkbox size="small" checked={always} onChange={setAlways} label={`Always open ${request.target.type} with it`} />
-
- <div className="flex justify-end">
- <Button size="small" autoFocus disabled={decision.isPending} onPress={() => decision.safeExecute(null)}>Cancel</Button>
- </div>
-
- {decision.exception && <Alert className="text-sm">{String(decision.exception.current)}</Alert>}
- </div>
+ return <>
+ <Dialog.Header>
+ <Dialog.Title>Open with</Dialog.Title>
+ <Dialog.Description>
+ <span className="truncate" title={request.target.uri} style={{ display: "block", fontWeight: 500 }}>{describe(request.target.uri)}</span>
+ {request.from ? `${request.from.process.program.name} asks to open it` : "Opened from outside the Desktop"} · {request.target.type}
+ </Dialog.Description>
+ </Dialog.Header>
+ <Dialog.Body>
+ <div className="grid" style={{ gap: space.xsmall }}>
+ {programs.map(program => <Button key={program.identity} disabled={decision.isPending} onPress={() => decision.safeExecute(program.identity)}
+ style={{ justifyContent: "flex-start" }}>
+ <img src={programIcon(application.doors.program, program.assetId)} alt="" draggable={false} className="shrink-0 object-contain" style={{ width: space.large, height: space.large }} />
+ {program.name}
+ </Button>)}
+ </div>
+ <Checkbox size="small" checked={always} onChange={setAlways} label={`Always open ${request.target.type} with it`} />
+ {decision.exception && <Alert className="text-sm">{String(decision.exception.current)}</Alert>}
+ </Dialog.Body>
+ <Dialog.Footer>
+ <Button autoFocus disabled={decision.isPending} onPress={() => decision.safeExecute(null)}>Cancel</Button>
+ </Dialog.Footer>
+ </>
}
/** A short name for what is being opened: a file's name, or the address itself. */
diff --git a/source/client/view/structure/desktop/layers/shell/dialogs/permission-requests.tsx b/source/client/view/structure/desktop/layers/shell/dialogs/permission-requests.tsx
index 3fc14a4..1f0e050 100644
--- a/source/client/view/structure/desktop/layers/shell/dialogs/permission-requests.tsx
+++ b/source/client/view/structure/desktop/layers/shell/dialogs/permission-requests.tsx
@@ -1,80 +1,57 @@
import type { PermissionName, PermissionRequestSnapshot } from "@phreshos/core"
import { ReactTunnel } from "@the-link/react"
-import { surfaceLifecyclePose, surfacePresenceTransition } from "@client/view/appearance/surface-presence"
-import { useReducedMotion } from "@libs/react-motion"
-import { motion } from "motion/react"
-import { useEffect, useId, useRef } from "react"
import { AuthManagerContext } from "@client/view/contexts"
-import ShellSurface, { shellSurfaceClassName } from "../shell-surface"
import usePromise from "@libs/react-promise"
import Alert from "@client/view/components/alert"
-import { Button, useTiming } from "@phreshos/react-ui"
+import { AlertDialog, Button, Text } from "@phreshos/react-ui"
+import { useDesktopScaleContainer } from "../../../desktop-scale"
+import useShown from "./shown"
-/** Default Shell representation of raw pending permission requests. */
+/**
+ * Default Shell representation of raw pending permission requests: the first one waiting, as an
+ * AlertDialog over the dimmed Desktop, which only a decision ends.
+ */
export default function PermissionRequests() {
const manager = AuthManagerContext.useValue().permissionManager
const inbound = ReactTunnel.useFactory(manager.$inbound)
const requests = inbound.useFirstState("/requests", manager.list())
const request = requests[0]
- const surface = useRef<HTMLDialogElement>(null)
- const title = useId()
- const description = useId()
- const reducedMotion = useReducedMotion()
- const transaction = useTiming()("change")
+ const container = useDesktopScaleContainer()
+ // The request stays shown while the dialog leaves, so it does not empty as it fades.
+ const shown = useShown(request)
- useEffect(() => {
-
- const element = surface.current
-
- if (!request || !element || element.open) return
-
- element.showModal()
-
- return () => { if (element.open) element.close() }
- }, [request?.identity])
-
- if (!request) return null
-
- return <motion.dialog
- ref={surface}
- role="alertdialog"
- aria-modal="true"
- aria-labelledby={title}
- aria-describedby={description}
- initial={reducedMotion ? surfaceLifecyclePose.visible : surfaceLifecyclePose.hidden}
- animate={surfaceLifecyclePose.visible}
- transition={surfacePresenceTransition(reducedMotion, transaction)}
- onCancel={event => event.preventDefault()}
- className={`${shellSurfaceClassName} pointer-events-auto fixed inset-0 m-auto h-fit w-[min(28rem,calc(100dvw/var(--desktop-scale)-var(--desktop-gutter)*2))] backdrop:bg-transparent`}
- >
- <ShellSurface material="full" label="Permission request" labelId={title}>
- <PermissionRequestView request={request} description={description} />
- </ShellSurface>
- </motion.dialog>
+ return <AlertDialog open={request !== undefined}>
+ <AlertDialog.Backdrop portalContainer={container ?? undefined}>
+ <AlertDialog.Content style={{ width: "28rem" }}>
+ {shown && <PermissionRequestView request={shown} />}
+ </AlertDialog.Content>
+ </AlertDialog.Backdrop>
+ </AlertDialog>
}
-function PermissionRequestView({ request, description }: Readonly<{ request: PermissionRequestSnapshot, description: string }>) {
+function PermissionRequestView({ request }: Readonly<{ request: PermissionRequestSnapshot }>) {
const manager = AuthManagerContext.useValue().permissionManager
const decision = usePromise((choice: "allow" | "deny" | "cancel") => manager[choice](request.identity))
const presentation = permissionPresentation[request.name]
const program = request.from.process.program
- return <div className="grid grid-cols-[auto_minmax(0,1fr)] items-start gap-x-3 gap-y-5">
- <span aria-hidden="true" className="grid size-8 place-items-center rounded-full border border-sky-600/25 bg-sky-500/15 text-sm font-medium">?</span>
- <div className="grid gap-1">
- <h3 className="text-base font-medium">{program.name} needs {presentation.title}</h3>
- <p id={description} className="text-sm leading-6 opacity-60">{presentation.description}</p>
- {request.scope.length > 0 && <p className="text-xs leading-5 opacity-50">{request.scope.join(", ")}</p>}
- </div>
- <div className="col-span-full flex flex-wrap justify-end gap-2">
- <Button size="xsmall" disabled={decision.isPending} onPress={() => decision.safeExecute("deny")}>Deny</Button>
- <Button size="xsmall" autoFocus disabled={decision.isPending} onPress={() => decision.safeExecute("cancel")}>Cancel</Button>
- <Button size="xsmall" disabled={decision.isPending} onPress={() => decision.safeExecute("allow")}>Allow for this Program</Button>
- </div>
- {decision.exception && <Alert className="col-span-full text-sm">{String(decision.exception.current)}</Alert>}
- </div>
+ return <>
+ <AlertDialog.Header>
+ <AlertDialog.Title>{program.name} needs {presentation.title}</AlertDialog.Title>
+ <AlertDialog.Description>{presentation.description}</AlertDialog.Description>
+ </AlertDialog.Header>
+ {(request.scope.length > 0 || decision.exception) && <AlertDialog.Body>
+ {request.scope.length > 0 && <Text size="small" tone="secondary">{request.scope.join(", ")}</Text>}
+ {decision.exception && <Alert className="text-sm">{String(decision.exception.current)}</Alert>}
+ </AlertDialog.Body>}
+ <AlertDialog.Footer>
+ <Button disabled={decision.isPending} onPress={() => decision.safeExecute("deny")}>Deny</Button>
+ <Button autoFocus disabled={decision.isPending} onPress={() => decision.safeExecute("cancel")}>Cancel</Button>
+ <Button disabled={decision.isPending} onPress={() => decision.safeExecute("allow")}>Allow for this Program</Button>
+ </AlertDialog.Footer>
+ </>
}
const permissionPresentation = {
diff --git a/source/client/view/structure/desktop/layers/shell/dialogs/shown.ts b/source/client/view/structure/desktop/layers/shell/dialogs/shown.ts
new file mode 100644
index 0000000..619094e
--- /dev/null
+++ b/source/client/view/structure/desktop/layers/shell/dialogs/shown.ts
@@ -0,0 +1,11 @@
+import { useState } from "react"
+
+/**
+ * The value a dialog shows: the current one, or the last one while the dialog leaves, so its content
+ * does not empty as it fades out.
+ */
+export default function useShown<Value>(value: Value | undefined) {
+ const [shown, setShown] = useState(value)
+ if (value !== undefined && value !== shown) setShown(value)
+ return value ?? shown
+}
diff --git a/source/client/view/structure/desktop/layers/shell/dialogs/system-errors.tsx b/source/client/view/structure/desktop/layers/shell/dialogs/system-errors.tsx
index f1996ec..8fb64e0 100644
--- a/source/client/view/structure/desktop/layers/shell/dialogs/system-errors.tsx
+++ b/source/client/view/structure/desktop/layers/shell/dialogs/system-errors.tsx
@@ -1,12 +1,10 @@
import { parseSystemLogRecord, type SystemLogRecord } from "@phreshos/core"
import { ReactTunnel } from "@the-link/react"
-import { surfaceLifecyclePose, surfacePresenceTransition } from "@client/view/appearance/surface-presence"
-import { useReducedMotion } from "@libs/react-motion"
-import { motion } from "motion/react"
-import { useCallback, useEffect, useId, useRef, useState } from "react"
+import { useCallback, useState } from "react"
import { AuthManagerContext } from "@client/view/contexts"
-import ShellSurface, { shellSurfaceClassName } from "../shell-surface"
-import { Button, useTiming } from "@phreshos/react-ui"
+import { AlertDialog, Button } from "@phreshos/react-ui"
+import { useDesktopScaleContainer } from "../../../desktop-scale"
+import useShown from "./shown"
/** Shell-owned real-time presentation of new System errors. */
export default function SystemErrors() {
@@ -24,86 +22,40 @@ export default function SystemErrors() {
if (received.level === "error") setRecord(received)
}, []))
- const surface = useRef<HTMLDialogElement>(null)
+ const container = useDesktopScaleContainer()
- const title = useId()
+ const shown = useShown(record ?? undefined)
- const description = useId()
+ // The latest error replaces what the open dialog shows; it does not close and reopen it.
+ return <AlertDialog open={record !== null}>
- const reducedMotion = useReducedMotion()
+ <AlertDialog.Backdrop portalContainer={container ?? undefined}>
- const transaction = useTiming()("change")
+ <AlertDialog.Content style={{ width: "28rem" }}>
- const visible = record !== null
+ {shown && <>
- useEffect(function () {
+ <AlertDialog.Header>
- const element = surface.current
+ <AlertDialog.Title>{errorTitle(shown)}</AlertDialog.Title>
- if (!visible || !element || element.open) return
+ <AlertDialog.Description>{shown.content}</AlertDialog.Description>
- element.showModal()
+ </AlertDialog.Header>
- return function () {
+ <AlertDialog.Footer>
- if (element.open) element.close()
- }
+ <Button autoFocus onPress={() => setRecord(null)}>I understand</Button>
- // The latest error may replace the visible content, but it must not close
- // and reopen the same Shell-owned dialog merely because its record changed.
- }, [visible])
+ </AlertDialog.Footer>
- if (!record) return null
+ </>}
- return <motion.dialog
+ </AlertDialog.Content>
- ref={surface}
+ </AlertDialog.Backdrop>
- role="alertdialog"
-
- aria-modal="true"
-
- aria-labelledby={title}
-
- aria-describedby={description}
-
- initial={reducedMotion ? surfaceLifecyclePose.visible : surfaceLifecyclePose.hidden}
-
- animate={surfaceLifecyclePose.visible}
-
- transition={surfacePresenceTransition(reducedMotion, transaction)}
-
- onCancel={event => event.preventDefault()}
-
- className={`${shellSurfaceClassName} pointer-events-auto fixed inset-0 m-auto h-fit w-[min(28rem,calc(100dvw/var(--desktop-scale)-var(--desktop-gutter)*2))] backdrop:bg-transparent`}
-
- >
-
- <ShellSurface material="full" label="System error" labelId={title}>
-
- <div className="grid grid-cols-[auto_minmax(0,1fr)] items-start gap-x-3 gap-y-5">
-
- <span aria-hidden="true" className="grid size-8 place-items-center rounded-full border border-rose-600/25 bg-rose-500/15 text-lg font-medium">!</span>
-
- <div className="grid gap-1">
-
- <h3 className="text-base font-medium">{errorTitle(record)}</h3>
-
- <p id={description} className="text-sm leading-6 opacity-60">{record.content}</p>
-
- </div>
-
- <Button size="xsmall" autoFocus onPress={() => setRecord(null)} className="col-span-full justify-self-end font-medium">
-
- I understand
-
- </Button>
-
- </div>
-
- </ShellSurface>
-
- </motion.dialog>
+ </AlertDialog>
}
function errorTitle(record: SystemLogRecord) {