mirror of
https://github.com/priyanshujain/margin.git
synced 2026-10-02 19:17:03 +00:00
group of bug fixes
This commit is contained in:
1 parent
cfc93fc97d
commit
bcd5eb9ebc
30 files changed
+973
-238
No files matched your search
+27
-1
@@ -1,6 +1,15 @@
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { isDesktop } from "./ipc";
|
||||
import { type Book, SCHEMA_VERSION, createBook, schemaVersion, starterBook } from "./model/book";
|
||||
import {
|
||||
type Book,
|
||||
type Chapter,
|
||||
SCHEMA_VERSION,
|
||||
createBook,
|
||||
insertByKind,
|
||||
normalizeBook,
|
||||
schemaVersion,
|
||||
starterBook,
|
||||
} from "./model/book";
|
||||
|
||||
export interface BookSummary {
|
||||
id: string;
|
||||
@@ -39,6 +48,23 @@ export async function deleteBook(id: string): Promise<void> {
|
||||
await invoke("delete_book", { id });
|
||||
}
|
||||
|
||||
export async function moveChapterToBook(chapter: Chapter, targetId: string): Promise<void> {
|
||||
const target = normalizeBook(await loadBook(targetId));
|
||||
const moved = { ...chapter, content: structuredClone(chapter.content), updatedAt: Date.now() };
|
||||
await saveBook({ ...target, chapters: insertByKind(target.chapters, moved) });
|
||||
}
|
||||
|
||||
const LAST_BOOK_KEY = "margin-last-book";
|
||||
|
||||
export function lastBookId(): string | null {
|
||||
return localStorage.getItem(LAST_BOOK_KEY);
|
||||
}
|
||||
|
||||
export function rememberLastBook(id: string | null): void {
|
||||
if (id) localStorage.setItem(LAST_BOOK_KEY, id);
|
||||
else localStorage.removeItem(LAST_BOOK_KEY);
|
||||
}
|
||||
|
||||
export function newBook(): Book {
|
||||
return createBook();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user