feat(notebooks): manage and author notebooks in the web UI (#9)
Add atomic, versioned notebook mutations, a searchable folder tree, and editor insertion forms. Validate notebook paths and symlink roots and retain drafts after external changes. Add yaml as a direct web dependency, reusing the existing workspace library for comment-preserving frontmatter edits.
This commit is contained in:
+31
-15
@@ -24,6 +24,7 @@ import type {
|
||||
StartRunRequest,
|
||||
Step,
|
||||
} from "@shellbook/core";
|
||||
import { NotebookList } from "./NotebookList";
|
||||
import { HttpError } from "./api";
|
||||
import type { Api } from "./api";
|
||||
import { emptySession, eventReducer, stepKey } from "./events";
|
||||
@@ -120,6 +121,14 @@ export function App({ api }: { api: Api }) {
|
||||
.catch((e) => setError(String(e)));
|
||||
const close = api.events((event: ServerEvent) => {
|
||||
const open = current.current;
|
||||
if (event.type === "file.changed" || event.type === "file.deleted") {
|
||||
void api
|
||||
.list()
|
||||
.then((result) => {
|
||||
if (active) setList(result.notebooks);
|
||||
})
|
||||
.catch((e) => setError(String(e)));
|
||||
}
|
||||
if (event.type === "file.changed" && event.path === open.doc?.path) {
|
||||
if (open.dirty) setConflict(true);
|
||||
else void load(event.path);
|
||||
@@ -324,21 +333,28 @@ export function App({ api }: { api: Api }) {
|
||||
<h1>
|
||||
ShellBook<span>RUNBOOKS</span>
|
||||
</h1>
|
||||
<nav aria-label="Notebooks">
|
||||
{list.map((item) => (
|
||||
<button
|
||||
className={path === item.path ? "selected" : ""}
|
||||
key={item.path}
|
||||
onClick={() => {
|
||||
if (!dirty || window.confirm("Discard unsaved edits?"))
|
||||
void load(item.path);
|
||||
}}
|
||||
>
|
||||
{item.title}
|
||||
<small>{item.path}</small>
|
||||
</button>
|
||||
))}
|
||||
</nav>
|
||||
<NotebookList
|
||||
api={api}
|
||||
list={list}
|
||||
path={path}
|
||||
version={doc?.version}
|
||||
canLeave={() => !dirty || window.confirm("Discard unsaved edits?")}
|
||||
onSelect={(next) => {
|
||||
if (!dirty || window.confirm("Discard unsaved edits?"))
|
||||
void load(next);
|
||||
}}
|
||||
onChanged={async (next) => {
|
||||
const result = await api.list();
|
||||
setList(result.notebooks);
|
||||
if (next) await load(next);
|
||||
else {
|
||||
++loadSequence.current;
|
||||
setDoc(undefined);
|
||||
setSource("");
|
||||
setConflict(false);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<small className="connection">
|
||||
{import.meta.env.VITE_MOCK === "1" ? "DEMO · " : ""}
|
||||
{connected
|
||||
|
||||
Reference in New Issue
Block a user