feat(io): save and open .margin projects with cmd-s and cmd-o

This commit is contained in:
pj committed 2026-06-20 12:54:01 -04:00
1 parent 13f2a70af2
commit aedf8b8a63
4 files changed
+78 -1

No files matched your search

+7
View File
@@ -5,11 +5,14 @@ import { type Book, createChapter, starterBook } from "../model/book";
interface BookState {
book: Book;
activeChapterId: string;
path: string | null;
dirty: boolean;
setActiveChapter: (id: string) => void;
setChapterContent: (id: string, content: JSONContent) => void;
setChapterTitle: (id: string, title: string) => void;
addChapter: () => void;
replaceBook: (book: Book, path: string) => void;
markSaved: (path: string) => void;
}
export const useBook = create<BookState>((set) => {
@@ -17,6 +20,7 @@ export const useBook = create<BookState>((set) => {
return {
book,
activeChapterId: book.chapters[0].id,
path: null,
dirty: false,
setActiveChapter: (id) => set({ activeChapterId: id }),
setChapterContent: (id, content) =>
@@ -44,5 +48,8 @@ export const useBook = create<BookState>((set) => {
book: { ...s.book, chapters: [...s.book.chapters, chapter] },
};
}),
replaceBook: (book, path) =>
set({ book, activeChapterId: book.chapters[0]?.id ?? "", path, dirty: false }),
markSaved: (path) => set({ path, dirty: false }),
};
});