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
feat(client/print): get collections to render
Elian Dorane374b31a1ca7
diff --git a/apps/client/src/print.css b/apps/client/src/print.cssnew file mode 100644index 0000000000..4927e5587c--- /dev/null+++ b/apps/client/src/print.css@@ -0,0 +1,5 @@+html,+body {+ width: 100%;+ height: 100%;+}\ No newline at end of filediff --git a/apps/client/src/print.tsx b/apps/client/src/print.tsxindex 267e2fdc4c..ed3d83c6a0 100644--- a/apps/client/src/print.tsx+++ b/apps/client/src/print.tsx@@ -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}+ />);}diff --git a/apps/client/src/widgets/collections/NoteList.tsx b/apps/client/src/widgets/collections/NoteList.tsxindex d0ee5ed07b..ba7d21d0c9 100644--- a/apps/client/src/widgets/collections/NoteList.tsx+++ b/apps/client/src/widgets/collections/NoteList.tsx@@ -13,7 +13,6 @@ 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;@@ -35,7 +34,7 @@ export function SearchNoteList<T extends object>(props: Omit<NoteListProps, "isEreturn <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");diff --git a/apps/client/src/widgets/collections/presentation/print.tsx b/apps/client/src/widgets/collections/presentation/print.tsxdeleted file mode 100644index c2dadeb6f6..0000000000--- a/apps/client/src/widgets/collections/presentation/print.tsx+++ /dev/null@@ -1,5 +0,0 @@-import { ViewModeProps } from "../interface";--export default function PresentationPrintView(props: ViewModeProps<any>) {- return <p>Hello world.</p>-}