fix(print): fails if included note could not be found

This commit is contained in:
Elian Doran 2025-12-03 19:16:58 +02:00
parent 9d0499a306
commit e0dc25ad23
No known key found for this signature in database
7 changed files with 18 additions and 11 deletions

View File

@ -240,7 +240,7 @@ export default class FNote {
const aNote = this.froca.getNoteFromCache(aNoteId);
if (aNote.isArchived || aNote.isHiddenCompletely()) {
if (!aNote || aNote.isArchived || aNote.isHiddenCompletely()) {
return 1;
}

View File

@ -56,9 +56,14 @@ async function renderIncludedNotes(contentEl: HTMLElement) {
// Render and integrate the notes.
for (const includeNoteEl of includeNoteEls) {
const noteId = includeNoteEl.getAttribute("data-note-id");
if (!noteId) return;
if (!noteId) continue;
const note = froca.getNoteFromCache(noteId);
if (!note) {
console.warn(`Unable to include ${noteId} because it could not be found.`);
continue;
}
const renderedContent = (await content_renderer.getRenderedContent(note)).$renderedContent;
includeNoteEl.replaceChildren(...renderedContent);
}

View File

@ -13,7 +13,7 @@ export interface Froca {
getBlob(entityType: string, entityId: string): Promise<FBlob | null>;
getNote(noteId: string, silentNotFoundError?: boolean): Promise<FNote | null>;
getNoteFromCache(noteId: string): FNote;
getNoteFromCache(noteId: string): FNote | undefined;
getNotesFromCache(noteIds: string[], silentNotFoundError?: boolean): FNote[];
getNotes(noteIds: string[], silentNotFoundError?: boolean): Promise<FNote[]>;

View File

@ -288,7 +288,7 @@ class FrocaImpl implements Froca {
return (await this.getNotes([noteId], silentNotFoundError))[0];
}
getNoteFromCache(noteId: string) {
getNoteFromCache(noteId: string): FNote | undefined {
if (!noteId) {
throw new Error("Empty noteId");
}

View File

@ -103,7 +103,7 @@ export default function BranchPrefixDialog() {
<input class="branch-prefix-input form-control" value={prefix} ref={branchInput}
onChange={(e) => setPrefix((e.target as HTMLInputElement).value)} />
{isSingleBranch && branches[0] && (
<div class="branch-prefix-note-title input-group-text"> - {branches[0].getNoteFromCache().title}</div>
<div class="branch-prefix-note-title input-group-text"> - {branches[0].getNoteFromCache()?.title}</div>
)}
</div>
</FormGroup>
@ -113,7 +113,7 @@ export default function BranchPrefixDialog() {
<ul>
{branches.map((branch) => {
const note = branch.getNoteFromCache();
return (
return note && (
<li key={branch.branchId}>
{branch.prefix && <span className="branch-prefix-current">{branch.prefix} - </span>}
{note.title}

View File

@ -91,7 +91,7 @@ function RecentChangesTimeline({ groupedByDate, setShown }: { groupedByDate: Map
return (
<li className={isDeleted ? "deleted-note" : ""}>
<span title={change.date}>{formattedTime}</span>
{ !isDeleted
{ notePath && !isDeleted
? <NoteLink notePath={notePath} title={change.current_title} />
: <DeletedNoteLink change={change} setShown={setShown} /> }
</li>

View File

@ -574,6 +574,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
.loadSearchNote(noteId)
.then(() => {
const note = froca.getNoteFromCache(noteId);
if (!note) return [];
let childNoteIds = note.getChildNoteIds();
@ -585,6 +586,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
})
.then(() => {
const note = froca.getNoteFromCache(noteId);
if (!note) return [];
return this.prepareChildren(note);
});
@ -740,7 +742,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
const node = $.ui.fancytree.getNode(e as unknown as Event);
const note = froca.getNoteFromCache(node.data.noteId);
if (note.isLaunchBarConfig()) {
if (note?.isLaunchBarConfig()) {
import("../menus/launcher_context_menu.js").then(({ default: LauncherContextMenu }) => {
const launcherContextMenu = new LauncherContextMenu(this, node);
launcherContextMenu.show(e);
@ -775,7 +777,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
if (hideArchivedNotes) {
const note = branch.getNoteFromCache();
if (note.hasLabel("archived")) {
if (!note || note.hasLabel("archived")) {
continue;
}
}
@ -1754,7 +1756,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
for (const nodeToDuplicate of nodesToDuplicate) {
const note = froca.getNoteFromCache(nodeToDuplicate.data.noteId);
if (note.isProtected && !protectedSessionHolder.isProtectedSessionAvailable()) {
if (note?.isProtected && !protectedSessionHolder.isProtectedSessionAvailable()) {
continue;
}