diff --git a/apps/client/src/print.tsx b/apps/client/src/print.tsx index 73d44d367..267e2fdc4 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 = ; } 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 ( -

{note.title}

+ <> +

{note.title}

+ + {component} + ); } diff --git a/apps/client/src/widgets/collections/NoteList.tsx b/apps/client/src/widgets/collections/NoteList.tsx index cb43ab1be..d0ee5ed07 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 } 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; @@ -110,6 +111,20 @@ function getComponentByViewType(viewType: ViewTypeOptions, props: ViewModeProps< } } +export function getComponentByViewTypeForPrint(viewType: ViewTypeOptions, props: ViewModeProps) { + switch (viewType) { + case "list": + case "grid": + case "geoMap": + case "calendar": + case "table": + case "board": + return null; + case "presentation": + return + } +} + 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([]); const [ includeArchived ] = useNoteLabelBoolean(note, "includeArchived"); @@ -187,7 +202,7 @@ function useNoteIds(note: FNote | null | undefined, viewType: ViewTypeOptions | return noteIds; } -function useViewModeConfig(note: FNote | null | undefined, viewType: ViewTypeOptions | undefined) { +export function useViewModeConfig(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.tsx new file mode 100644 index 000000000..c2dadeb6f --- /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) { + return

Hello world.

+}