mirror of
https://github.com/zadam/trilium.git
synced 2025-12-29 10:44:25 +01:00
fix(print): skip printing protected notes if session not available
This commit is contained in:
parent
502c896616
commit
66cdee82a4
@ -1,10 +1,11 @@
|
||||
import FNote from "./entities/fnote";
|
||||
import { render } from "preact";
|
||||
import { CustomNoteList, useNoteViewType } from "./widgets/collections/NoteList";
|
||||
import { useCallback, useLayoutEffect, useRef } from "preact/hooks";
|
||||
|
||||
import FNote from "./entities/fnote";
|
||||
import content_renderer from "./services/content_renderer";
|
||||
import { dynamicRequire, isElectron } from "./services/utils";
|
||||
import { applyInlineMermaid } from "./services/content_renderer_text";
|
||||
import { dynamicRequire, isElectron } from "./services/utils";
|
||||
import { CustomNoteList, useNoteViewType } from "./widgets/collections/NoteList";
|
||||
|
||||
interface RendererProps {
|
||||
note: FNote;
|
||||
@ -42,7 +43,7 @@ function App({ note, noteId }: { note: FNote | null | undefined, noteId: string
|
||||
}, []);
|
||||
const props: RendererProps | undefined | null = note && { note, onReady, onProgressChanged };
|
||||
|
||||
if (!note || !props) return <Error404 noteId={noteId} />
|
||||
if (!note || !props) return <Error404 noteId={noteId} />;
|
||||
|
||||
useLayoutEffect(() => {
|
||||
document.body.dataset.noteType = note.type;
|
||||
@ -51,8 +52,8 @@ function App({ note, noteId }: { note: FNote | null | undefined, noteId: string
|
||||
return (
|
||||
<>
|
||||
{note.type === "book"
|
||||
? <CollectionRenderer {...props} />
|
||||
: <SingleNoteRenderer {...props} />
|
||||
? <CollectionRenderer {...props} />
|
||||
: <SingleNoteRenderer {...props} />
|
||||
}
|
||||
</>
|
||||
);
|
||||
@ -91,7 +92,7 @@ function SingleNoteRenderer({ note, onReady }: RendererProps) {
|
||||
await loadCustomCss(note);
|
||||
}
|
||||
|
||||
load().then(() => requestAnimationFrame(onReady))
|
||||
load().then(() => requestAnimationFrame(onReady));
|
||||
}, [ note ]);
|
||||
|
||||
return <>
|
||||
@ -124,12 +125,12 @@ function Error404({ noteId }: { noteId: string }) {
|
||||
<p>The note you are trying to print could not be found.</p>
|
||||
<small>{noteId}</small>
|
||||
</main>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
async function loadCustomCss(note: FNote) {
|
||||
const printCssNotes = await note.getRelationTargets("printCss");
|
||||
let loadPromises: JQueryPromise<void>[] = [];
|
||||
const loadPromises: JQueryPromise<void>[] = [];
|
||||
|
||||
for (const printCssNote of printCssNotes) {
|
||||
if (!printCssNote || (printCssNote.type !== "code" && printCssNote.mime !== "text/css")) continue;
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
import { useEffect, useLayoutEffect, useState } from "preact/hooks";
|
||||
import froca from "../../../services/froca";
|
||||
|
||||
import type FNote from "../../../entities/fnote";
|
||||
import content_renderer from "../../../services/content_renderer";
|
||||
import froca from "../../../services/froca";
|
||||
import type { ViewModeProps } from "../interface";
|
||||
import { filterChildNotes, useFilteredNoteIds } from "./utils";
|
||||
|
||||
@ -22,6 +23,8 @@ export function ListPrintView({ note, noteIds: unfilteredNoteIds, onReady, onPro
|
||||
const notesWithContent: NotesWithContent[] = [];
|
||||
|
||||
async function processNote(note: FNote, depth: number) {
|
||||
if (!isNotePrintable(note)) return;
|
||||
|
||||
const content = await content_renderer.getRenderedContent(note, {
|
||||
trim: false,
|
||||
noChildrenList: true
|
||||
@ -78,6 +81,14 @@ export function ListPrintView({ note, noteIds: unfilteredNoteIds, onReady, onPro
|
||||
);
|
||||
}
|
||||
|
||||
function isNotePrintable(note: FNote) {
|
||||
if (!note.isContentAvailable()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function insertPageTitle(contentEl: HTMLElement, title: string) {
|
||||
const pageTitleEl = document.createElement("h1");
|
||||
pageTitleEl.textContent = title;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user