mirror of
https://github.com/priyanshujain/margin.git
synced 2026-10-02 19:17:03 +00:00
feat(io): save and open .margin projects with cmd-s and cmd-o
This commit is contained in:
1 parent
13f2a70af2
commit
aedf8b8a63
4 files changed
+78
-1
No files matched your search
@@ -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 }),
|
||||
};
|
||||
});
|
||||
Reference in new issue
Block a user