feat(client/print): get collections to render

This commit is contained in:
Elian Doran
2025-10-18 21:35:19 +03:00
parent e416caffe3
commit e374b31a1c
4 changed files with 23 additions and 45 deletions

View File

@@ -1,8 +1,8 @@
import { JSX } from "preact/jsx-runtime";
import FNote from "./entities/fnote";
import { render } from "preact";
import { getComponentByViewTypeForPrint, useNoteIds, useViewModeConfig } from "./widgets/collections/NoteList";
import { ViewTypeOptions } from "./widgets/collections/interface";
import { CustomNoteList } from "./widgets/collections/NoteList";
import "./print.css";
async function main() {
const noteId = window.location.pathname.split("/")[2];
@@ -13,33 +13,26 @@ async function main() {
let el: JSX.Element | null = null;
if (note.type === "book") {
el = <Collection note={note} />;
el = handleCollection(note);
}
render(el, document.body);
}
function Collection({ note }: { note: FNote }) {
const viewType = note.getLabelValue("viewType") as ViewTypeOptions ?? "grid";
const viewConfig = useViewModeConfig(note, viewType);
const noteIds = useNoteIds(note, viewType, "print");
const component = getComponentByViewTypeForPrint(viewType, {
saveConfig() {
// While printing we don't allow for interactivity, so saving the config is a no-op.
},
viewConfig: viewConfig?.[0] ?? {},
note,
notePath: note.getBestNotePath().join("/"),
noteIds,
highlightedTokens: null
});
return (
render((
<>
<h1>{note.title}</h1>
{component}
{el}
</>
), document.body);
}
function handleCollection(note: FNote) {
return (
<CustomNoteList
isEnabled
note={note}
notePath={note.getBestNotePath().join("/")}
ntxId="print"
highlightedTokens={null}
/>
);
}