Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
chore(client/print): wire printing for collections
Elian Dorane416caffe364
diff --git a/apps/client/src/print.tsx b/apps/client/src/print.tsxindex 73d44d3675..267e2fdc4c 100644--- a/apps/client/src/print.tsx+++ b/apps/client/src/print.tsx@@ -1,6 +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";async function main() {const noteId = window.location.pathname.split("/")[2];@@ -11,15 +13,33 @@ async function main() {let el: JSX.Element | null = null;if (note.type === "book") {- el = handleCollection(note);+ el = <Collection note={note} />;}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 (- <h1>{note.title}</h1>+ <>+ <h1>{note.title}</h1>++ {component}+ </>);}diff --git a/apps/client/src/widgets/collections/NoteList.tsx b/apps/client/src/widgets/collections/NoteList.tsxindex cb43ab1be2..d0ee5ed07b 100644--- a/apps/client/src/widgets/collections/NoteList.tsx+++ b/apps/client/src/widgets/collections/NoteList.tsx@@ -13,6 +13,7 @@ import { subscribeToMessages, unsubscribeToMessage as unsubscribeFromMessage } fimport { WebSocketMessage } from "@triliumnext/commons";import froca from "../../services/froca";import PresentationView from "./presentation";+import PresentationPrintView from "./presentation/print";interface NoteListProps {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 {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 [ includeArchived ] = useNoteLabelBoolean(note, "includeArchived");@@ -187,7 +202,7 @@ function useNoteIds(note: FNote | null | undefined, viewType: ViewTypeOptions |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]>();useEffect(() => {diff --git a/apps/client/src/widgets/collections/presentation/print.tsx b/apps/client/src/widgets/collections/presentation/print.tsxnew file mode 100644index 0000000000..c2dadeb6f6--- /dev/null+++ b/apps/client/src/widgets/collections/presentation/print.tsx@@ -0,0 +1,5 @@+import { ViewModeProps } from "../interface";++export default function PresentationPrintView(props: ViewModeProps<any>) {+ return <p>Hello world.</p>+}