Web UI on Ant Design, scrollable factory columns, fix empty page after deleting the open chat

Buttons, fields, drop-downs, check boxes, tabs, dialogs and notices are Ant Design components;
their tokens come from the theme variables (web/src/ui). Every factory board column has its own
vertical scrollbar. ChatView rendered fewer hooks once its chat was deleted.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Richard ZinkandClaude Sonnet 5.5 committed 2026-11-27 12:32:57 +01:00
1 parent 90b9ab6670
commit 6b1a1742b2
79 files changed
+2628 -1393

No files matched your search

+48 -59
View File
@@ -1,8 +1,9 @@
import { App, Button, Input, type InputRef } from "antd";
import { UploadPanel } from "./components/UploadPanel";
import { Icon } from "./components/Icon";
// In-app dialogs and toasts instead of the browser's alert/confirm/prompt.
import { useEffect, useRef, useState, useSyncExternalStore } from "react";
import { t } from "./i18n";
import { Modal } from "./ui/Modal";
interface ConfirmOpts {
title?: string;
@@ -39,7 +40,9 @@ interface Toast {
}
let dialogs: Dialog[] = [];
let toasts: Toast[] = [];
/** Shows a notice; set by the DialogHost once it is mounted. */
let show: ((x: Toast) => void) | undefined;
const waiting: Toast[] = [];
let seq = 0;
const listeners = new Set<() => void>();
const emit = () => listeners.forEach((l) => l());
@@ -71,13 +74,9 @@ export function promptDialog(opts: PromptOpts | string): Promise<string | null>
export function toast(message: unknown, kind: Toast["kind"] = "error") {
const text = message instanceof Error ? message.message : typeof message === "string" ? message : String((message as any)?.message ?? message);
const id = ++seq;
toasts = [...toasts, { id, message: text, kind }];
emit();
setTimeout(() => {
toasts = toasts.filter((x) => x.id !== id);
emit();
}, kind === "error" ? 7000 : 3500);
const x = { id: ++seq, message: text, kind };
if (show) show(x);
else waiting.push(x);
}
function close(d: Dialog, value: any) {
@@ -88,86 +87,76 @@ function close(d: Dialog, value: any) {
function DialogView({ d }: { d: Dialog }) {
const [value, setValue] = useState(d.kind === "prompt" ? d.defaultValue ?? "" : "");
const input = useRef<HTMLInputElement>(null);
const input = useRef<InputRef>(null);
const ok = useRef<HTMLButtonElement>(null);
const cancelValue = d.kind === "confirm" ? false : null;
useEffect(() => {
if (d.kind === "prompt") {
input.current?.focus();
input.current?.select();
} else ok.current?.focus();
const h = (e: KeyboardEvent) => e.key === "Escape" && close(d, cancelValue);
window.addEventListener("keydown", h);
return () => window.removeEventListener("keydown", h);
// After the window has opened (it takes the focus itself first).
const timer = setTimeout(() => (d.kind === "prompt" ? input.current?.focus({ cursor: "all" }) : ok.current?.focus()), 60);
return () => clearTimeout(timer);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
const submit = () => close(d, d.kind === "confirm" ? true : value);
const field = {
ref: input,
value,
placeholder: d.kind === "prompt" ? d.placeholder : undefined,
onChange: (e: React.ChangeEvent<HTMLInputElement>) => setValue(e.target.value),
};
return (
<div className="modal-backdrop" onClick={() => close(d, cancelValue)}>
<form
className="modal dialog"
role={d.kind === "confirm" ? "alertdialog" : "dialog"}
aria-label={d.title ?? d.message}
onClick={(e) => e.stopPropagation()}
onSubmit={(e) => (e.preventDefault(), submit())}
>
<Modal onClose={() => close(d, cancelValue)} className="dialog">
<form role={d.kind === "confirm" ? "alertdialog" : "dialog"} aria-label={d.title ?? d.message} onSubmit={(e) => (e.preventDefault(), submit())}>
{d.title && <h3>{d.title}</h3>}
<p className="dialog-message">{d.message}</p>
{d.kind === "prompt" && (
<input
ref={input}
type={d.password ? "password" : "text"}
value={value}
placeholder={d.placeholder}
onChange={(e) => setValue(e.target.value)}
autoComplete={d.password ? "new-password" : "off"}
style={{ width: "100%" }}
/>
)}
{d.kind === "prompt" && (d.password ? <Input.Password {...field} autoComplete="new-password" /> : <Input {...field} autoComplete="off" />)}
{d.kind === "choice" ? (
<div className="row dialog-actions dialog-choices">
<button type="button" onClick={() => close(d, null)}>
{t("common.cancel")}
</button>
{d.choices.map((c, i) => (
<button key={c.value} ref={i === d.choices.length - 1 ? ok : undefined} type="button" className={c.danger ? "danger-solid" : i === d.choices.length - 1 ? "primary" : undefined} onClick={() => close(d, c.value)}>
{c.label}
</button>
))}
<Button onClick={() => close(d, null)}>{t("common.cancel")}</Button>
{d.choices.map((c, i) => {
const last = i === d.choices.length - 1;
return (
<Button key={c.value} ref={last ? ok : undefined} type={c.danger || last ? "primary" : "default"} danger={c.danger} onClick={() => close(d, c.value)}>
{c.label}
</Button>
);
})}
</div>
) : (
<div className="row dialog-actions">
<button type="button" onClick={() => close(d, cancelValue)}>
{t("common.cancel")}
</button>
<button ref={ok} type="submit" className={d.kind === "confirm" && d.danger ? "danger-solid" : "primary"}>
<Button onClick={() => close(d, cancelValue)}>{t("common.cancel")}</Button>
<Button ref={ok} htmlType="submit" type="primary" danger={d.kind === "confirm" && d.danger}>
{d.confirmLabel ?? t("common.ok")}
</button>
</Button>
</div>
)}
</form>
</div>
</Modal>
);
}
/** Renders open dialogs and toasts; mounted once in App. */
export function DialogHost() {
const state = useSyncExternalStore(subscribe, () => dialogs);
const ts = useSyncExternalStore(subscribe, () => toasts);
const { message } = App.useApp();
useEffect(() => {
show = (x) =>
void message.open({
key: x.id,
type: x.kind,
// A click dismisses the notice.
content: <span onClick={() => message.destroy(x.id)}>{x.message}</span>,
duration: x.kind === "error" ? 7 : 3.5,
});
// Notices raised before the host was there.
waiting.splice(0).forEach(show);
return () => void (show = undefined);
}, [message]);
return (
<>
{state.map((d) => (
<DialogView key={d.id} d={d} />
))}
<UploadPanel />
<div className="toasts" role="status" aria-live="polite">
{ts.map((x) => (
<div key={x.id} className={`toast ${x.kind}`} onClick={() => ((toasts = toasts.filter((y) => y.id !== x.id)), emit())}>
{x.kind === "error" ? <Icon name="warning" /> : x.kind === "success" ? <Icon name="check" /> : null}
{x.message}
</div>
))}
</div>
</>
);
}