Reading Log
store.js 26 lines
Files · 8
1234567891011121314151617181920212223242526import manifest from "./manifest.json";
import ddl from "./schema.js";
import { createRecordStore } from "../../shared/record-store.js";
export const store = createRecordStore({
manifest,
ddl,
table: "books",
key: "book_id",
added: "book-added",
afterSave: async (before, book, emit) => {
if (
before.exclusive_shelf !== book.exclusive_shelf &&
book.exclusive_shelf === "currently-reading"
)
await emit("reading-started", book);
if (
book.exclusive_shelf === "read" &&
book.date_read &&
(before.exclusive_shelf !== "read" ||
before.date_read !== book.date_read ||
before.read_count < book.read_count)
)
await emit("book-finished", book);
if (before.my_rating !== book.my_rating) await emit("book-rated", book);
},
});