chore(client/print): wire printing for collections

This commit is contained in:
Elian Doran 2025-10-18 21:19:53 +03:00
parent 62855f4bb1
commit e416caffe3
No known key found for this signature in database
3 changed files with 45 additions and 5 deletions

View File

@ -1,6 +1,8 @@
import { JSX } from "preact/jsx-runtime"; import { JSX } from "preact/jsx-runtime";
import FNote from "./entities/fnote"; import FNote from "./entities/fnote";
import { render } from "preact"; import { render } from "preact";
import { getComponentByViewTypeForPrint, useNoteIds, useViewModeConfig } from "./widgets/collections/NoteList";
import { ViewTypeOptions } from "./widgets/collections/interface";
async function main() { async function main() {
const noteId = window.location.pathname.split("/")[2]; const noteId = window.location.pathname.split("/")[2];
@ -11,15 +13,33 @@ async function main() {
let el: JSX.Element | null = null; let el: JSX.Element | null = null;
if (note.type === "book") { if (note.type === "book") {
el = handleCollection(note); el = <Collection note={note} />;
} }
render(el, document.body); render(el, document.body);
} }
function handleCollection(note: FNote) { 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 ( return (
<h1>{note.title}</h1> <>
<h1>{note.title}</h1>
{component}
</>
); );
} }

View File

@ -13,6 +13,7 @@ import { subscribeToMessages, unsubscribeToMessage as unsubscribeFromMessage } f
import { WebSocketMessage } from "@triliumnext/commons"; import { WebSocketMessage } from "@triliumnext/commons";
import froca from "../../services/froca"; import froca from "../../services/froca";
import PresentationView from "./presentation"; import PresentationView from "./presentation";
import PresentationPrintView from "./presentation/print";
interface NoteListProps { interface NoteListProps {
note: FNote | null | undefined; note: FNote | null | undefined;
@ -110,6 +111,20 @@ 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 { function useNoteViewType(note?: FNote | null): ViewTypeOptions | undefined {
const [ viewType ] = useNoteLabel(note, "viewType"); const [ viewType ] = useNoteLabel(note, "viewType");
@ -123,7 +138,7 @@ function useNoteViewType(note?: FNote | null): ViewTypeOptions | undefined {
} }
} }
function useNoteIds(note: FNote | null | undefined, viewType: ViewTypeOptions | undefined, ntxId: string | null | undefined) { export function useNoteIds(note: FNote | null | undefined, viewType: ViewTypeOptions | undefined, ntxId: string | null | undefined) {
const [ noteIds, setNoteIds ] = useState<string[]>([]); const [ noteIds, setNoteIds ] = useState<string[]>([]);
const [ includeArchived ] = useNoteLabelBoolean(note, "includeArchived"); const [ includeArchived ] = useNoteLabelBoolean(note, "includeArchived");
@ -187,7 +202,7 @@ function useNoteIds(note: FNote | null | undefined, viewType: ViewTypeOptions |
return noteIds; return noteIds;
} }
function useViewModeConfig<T extends object>(note: FNote | null | undefined, viewType: ViewTypeOptions | undefined) { export function useViewModeConfig<T extends object>(note: FNote | null | undefined, viewType: ViewTypeOptions | undefined) {
const [ viewConfig, setViewConfig ] = useState<[T | undefined, (data: T) => void]>(); const [ viewConfig, setViewConfig ] = useState<[T | undefined, (data: T) => void]>();
useEffect(() => { useEffect(() => {

View File

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