feat: add Book type to schema and sidebar
- Add BookContentSchema with headline, subtitle, bookBody, reviewBody fields - Add BookResource type and update GenericResourceSchema - Add books to sidebar navigation with Bookmark Tabs icon
This commit is contained in:
41
islands/KMenu/commands/enhance_book_infos.ts
Normal file
41
islands/KMenu/commands/enhance_book_infos.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { getCookie } from "@lib/string.ts";
|
||||
import { MenuEntry } from "../types.ts";
|
||||
import { BookResource } from "@lib/marka/schema.ts";
|
||||
import { fetchStream } from "@lib/helpers.ts";
|
||||
|
||||
export const enhanceBookInfo: MenuEntry = {
|
||||
title: "Enhance Book Info",
|
||||
meta: "Update metadata and content from Hardcover",
|
||||
icon: "IconWand",
|
||||
cb: (state, context) => {
|
||||
state.activeState.value = "loading";
|
||||
const book = context as BookResource;
|
||||
|
||||
fetchStream(
|
||||
`/api/books/enhance/${book.name}/`,
|
||||
(chunk) => {
|
||||
if (chunk.type === "error") {
|
||||
state.activeState.value = "error";
|
||||
state.loadingText.value = chunk.message;
|
||||
} else if (chunk.type == "finished") {
|
||||
state.loadingText.value = "Finished";
|
||||
setTimeout(() => {
|
||||
state.visible.value = false;
|
||||
state.activeState.value = "normal";
|
||||
globalThis.location.reload();
|
||||
}, 500);
|
||||
} else {
|
||||
state.loadingText.value = chunk.message;
|
||||
}
|
||||
},
|
||||
{ method: "POST" },
|
||||
);
|
||||
},
|
||||
visible: () => {
|
||||
const loc = globalThis["location"];
|
||||
if (!getCookie("session_cookie")) return false;
|
||||
|
||||
return (loc?.pathname?.includes("book") &&
|
||||
!loc.pathname.endsWith("books"));
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user