feat(web): rework layout and quality of life (#12)
- App shell: top bar with connection state and Chat/Terminal toggles, per-column scrolling, sidebar only on the Notebooks page. - Hash routes (#/notebooks/<path>, #/hosts, #/settings) so reloads and links keep the open notebook and page. - Parameters sit beside the notebook on wide screens, collapsible, with missing-count summary and Reset; non-secret values are remembered per notebook in localStorage (secrets and undeclared names never stored). - Sticky notebook header with breadcrumbs, check summary and run-all; Ctrl/Cmd+S saves the Markdown draft. - Step cards show target, one deduplicated hint for missing values and copy feedback. - Shared Dialog, Menu and CopyButton components; notebook and host actions move into menus and modal dialogs. - Hosts page as a compact list; Settings split into cards with sign out for this browser.
This commit is contained in:
+109
-63
@@ -3,6 +3,7 @@ import { useState } from "react";
|
||||
import type { NotebookSummary } from "@shellbook/core";
|
||||
import type { Api } from "./api";
|
||||
import { newNotebook } from "./authoring";
|
||||
import { Dialog, Menu } from "./ui";
|
||||
type Node = { folders: Map<string, Node>; files: NotebookSummary[] };
|
||||
function tree(list: NotebookSummary[]): Node {
|
||||
const root: Node = { folders: new Map(), files: [] };
|
||||
@@ -40,6 +41,10 @@ export function NotebookList({
|
||||
>();
|
||||
const [error, setError] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const choose = (op: "rename" | "duplicate" | "delete") => {
|
||||
setAction(op);
|
||||
setError("");
|
||||
};
|
||||
const render = (node: Node) => (
|
||||
<>
|
||||
{[...node.folders]
|
||||
@@ -51,67 +56,94 @@ export function NotebookList({
|
||||
</details>
|
||||
))}
|
||||
{node.files.map((item) => (
|
||||
<button
|
||||
className={item.path === path ? "selected" : ""}
|
||||
<div
|
||||
className={`notebook-item ${item.path === path ? "selected" : ""}`}
|
||||
key={item.path}
|
||||
onClick={() => onSelect(item.path)}
|
||||
>
|
||||
{item.title}
|
||||
<small>{item.path}</small>
|
||||
</button>
|
||||
<button
|
||||
aria-current={item.path === path ? "page" : undefined}
|
||||
title={item.path}
|
||||
onClick={() => onSelect(item.path)}
|
||||
>
|
||||
{item.title}
|
||||
</button>
|
||||
{item.path === path && (
|
||||
<Menu label={`Actions for ${item.title}`}>
|
||||
{(close) =>
|
||||
(["rename", "duplicate", "delete"] as const).map((op) => (
|
||||
<button
|
||||
key={op}
|
||||
role="menuitem"
|
||||
className={op === "delete" ? "danger" : ""}
|
||||
onClick={() => {
|
||||
close();
|
||||
choose(op);
|
||||
}}
|
||||
>
|
||||
{op === "rename"
|
||||
? "Rename / move"
|
||||
: op === "duplicate"
|
||||
? "Duplicate"
|
||||
: "Delete"}
|
||||
</button>
|
||||
))
|
||||
}
|
||||
</Menu>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</>
|
||||
);
|
||||
const shown = list.filter((n) =>
|
||||
`${n.path} ${n.title}`.toLowerCase().includes(search.toLowerCase()),
|
||||
);
|
||||
return (
|
||||
<>
|
||||
<label>
|
||||
Search notebooks
|
||||
<div className="sidebar-tools">
|
||||
<input
|
||||
type="search"
|
||||
aria-label="Search notebooks"
|
||||
placeholder="Search notebooks"
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<button
|
||||
onClick={() => {
|
||||
setAction("new");
|
||||
setError("");
|
||||
}}
|
||||
>
|
||||
New notebook
|
||||
</button>
|
||||
<button
|
||||
className="icon"
|
||||
aria-label="New notebook"
|
||||
title="New notebook"
|
||||
onClick={() => {
|
||||
setAction("new");
|
||||
setError("");
|
||||
}}
|
||||
>
|
||||
+
|
||||
</button>
|
||||
</div>
|
||||
<nav aria-label="Notebooks">
|
||||
{render(
|
||||
tree(
|
||||
list.filter((n) =>
|
||||
`${n.path} ${n.title}`
|
||||
.toLowerCase()
|
||||
.includes(search.toLowerCase()),
|
||||
),
|
||||
),
|
||||
{render(tree(shown))}
|
||||
{!shown.length && (
|
||||
<p className="muted">
|
||||
{list.length ? "No notebook matches." : "No notebooks yet."}
|
||||
</p>
|
||||
)}
|
||||
</nav>
|
||||
{path && (
|
||||
<div className="actions">
|
||||
{(["rename", "duplicate", "delete"] as const).map((op) => (
|
||||
<button
|
||||
key={op}
|
||||
onClick={() => {
|
||||
setAction(op);
|
||||
setError("");
|
||||
}}
|
||||
>
|
||||
{op === "rename"
|
||||
? "Rename / move"
|
||||
: op === "duplicate"
|
||||
? "Duplicate"
|
||||
: "Delete"}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{action && (
|
||||
<Dialog
|
||||
title={
|
||||
action === "new"
|
||||
? "New notebook"
|
||||
: action === "rename"
|
||||
? "Rename or move notebook"
|
||||
: action === "duplicate"
|
||||
? "Duplicate notebook"
|
||||
: "Delete notebook"
|
||||
}
|
||||
onClose={() => {
|
||||
if (!busy) setAction(undefined);
|
||||
}}
|
||||
>
|
||||
<form
|
||||
className="stack"
|
||||
key={`${action}:${path}`}
|
||||
aria-label="Manage notebook"
|
||||
onSubmit={async (e) => {
|
||||
@@ -158,18 +190,22 @@ export function NotebookList({
|
||||
}
|
||||
}}
|
||||
>
|
||||
<strong>
|
||||
{action === "delete"
|
||||
? `Delete ${path}? This cannot be undone.`
|
||||
: action === "new"
|
||||
? "New notebook"
|
||||
: `${action} ${path}`}
|
||||
</strong>
|
||||
{action === "delete" ? (
|
||||
<p>
|
||||
Delete <code>{path}</code>? This cannot be undone.
|
||||
</p>
|
||||
) : (
|
||||
action !== "new" && (
|
||||
<p className="muted">
|
||||
From <code>{path}</code>
|
||||
</p>
|
||||
)
|
||||
)}
|
||||
{action === "new" ? (
|
||||
<>
|
||||
<label>
|
||||
Name
|
||||
<input name="name" required />
|
||||
<input name="name" required placeholder="debian-upgrade" />
|
||||
</label>
|
||||
<label>
|
||||
Folder (optional)
|
||||
@@ -196,18 +232,28 @@ export function NotebookList({
|
||||
</label>
|
||||
)
|
||||
)}
|
||||
<button disabled={busy}>
|
||||
{action === "delete" ? "Confirm delete" : "Apply"}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
disabled={busy}
|
||||
onClick={() => setAction(undefined)}
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
{error && <p role="alert">{error}</p>}
|
||||
{error && (
|
||||
<p role="alert" className="error">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
<div className="dialog-actions">
|
||||
<button
|
||||
type="button"
|
||||
disabled={busy}
|
||||
onClick={() => setAction(undefined)}
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
className={action === "delete" ? "danger" : "primary"}
|
||||
disabled={busy}
|
||||
>
|
||||
{action === "delete" ? "Confirm delete" : "Apply"}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</Dialog>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user