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
No known key found for this signature in database
4 changed files with 23 additions and 45 deletions

View File

@ -0,0 +1,5 @@
html,
body {
width: 100%;
height: 100%;
}

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}
/>
);
}

View File

@ -13,7 +13,6 @@ import { subscribeToMessages, unsubscribeToMessage as unsubscribeFromMessage } f
import { WebSocketMessage } from "@triliumnext/commons";
import froca from "../../services/froca";
import PresentationView from "./presentation";
import PresentationPrintView from "./presentation/print";
interface NoteListProps {
note: FNote | null | undefined;
@ -35,7 +34,7 @@ export function SearchNoteList<T extends object>(props: Omit<NoteListProps, "isE
return <CustomNoteList {...props} isEnabled={true} />
}
function CustomNoteList<T extends object>({ note, isEnabled: shouldEnable, notePath, highlightedTokens, displayOnlyCollections, ntxId }: NoteListProps) {
export function CustomNoteList<T extends object>({ note, isEnabled: shouldEnable, notePath, highlightedTokens, displayOnlyCollections, ntxId }: NoteListProps) {
const widgetRef = useRef<HTMLDivElement>(null);
const viewType = useNoteViewType(note);
const noteIds = useNoteIds(note, viewType, ntxId);
@ -111,20 +110,6 @@ function getComponentByViewType(viewType: ViewTypeOptions, props: ViewModeProps<
}
}
export function getComponentByViewTypeForPrint(viewType: ViewTypeOptions, props: ViewModeProps<any>) {
switch (viewType) {
case "list":
case "grid":
case "geoMap":
case "calendar":
case "table":
case "board":
return null;
case "presentation":
return <PresentationPrintView {...props} />
}
}
function useNoteViewType(note?: FNote | null): ViewTypeOptions | undefined {
const [ viewType ] = useNoteLabel(note, "viewType");

View File

@ -1,5 +0,0 @@
import { ViewModeProps } from "../interface";
export default function PresentationPrintView(props: ViewModeProps<any>) {
return <p>Hello world.</p>
}