diff --git a/app/EditorPage.jsx b/app/EditorPage.jsx index f9f39f1..6efd533 100644 --- a/app/EditorPage.jsx +++ b/app/EditorPage.jsx @@ -3,14 +3,16 @@ import {useState, useEffect, useRef, useCallback, useSyncExternalStore} from "re import {notFound} from "next/navigation"; import {Pencil} from "lucide-react"; import {Editor} from "./Editor.jsx"; -import {getNotebookById, createNotebook, addNotebook, saveNotebook} from "./api.js"; +import {getNotebookById, createNotebook, addNotebook, saveNotebook, getNotebooks} from "./api.js"; import {isDirtyStore, countStore} from "./store.js"; import {cn} from "./cn.js"; +import {SafeLink} from "./SafeLink.jsx"; const UNSET = Symbol("UNSET"); export function EditorPage({id: initialId}) { const [notebook, setNotebook] = useState(UNSET); + const [notebookList, setNotebookList] = useState([]); const [showInput, setShowInput] = useState(false); const [autoRun, setAutoRun] = useState(false); const [id, setId] = useState(initialId); @@ -59,6 +61,11 @@ export function EditorPage({id: initialId}) { }, 100); }, [notebook, isAdded]); + useEffect(() => { + const notebooks = getNotebooks(); + setNotebookList(notebooks.slice(0, 4)); + }, [isAdded]); + useEffect(() => { const onBeforeUnload = (e) => { if (isDirty) e.preventDefault(); @@ -137,44 +144,97 @@ export function EditorPage({id: initialId}) { } return ( -
- - {!isAdded && ( - +
+ {!isAdded && notebookList.length > 0 && ( +
+ +
+ + View your notebooks +
- } - /> +
+ )} + {!isAdded && notebookList.length === 0 && ( +
+

+ Explore code and art with instant feedback. +

+
+ )} +
+ + {!isAdded && ( + + )} + {!showInput && isAdded && ( + + )} + {showInput || !isAdded ? ( + + ) : ( + {notebook.title} + )} +
+ } + /> +
); }