mirror of
https://github.com/zadam/trilium.git
synced 2025-11-21 08:04:24 +01:00
fix(print/list): note content not shown due to race condition
This commit is contained in:
parent
c95cb79672
commit
a59d407f12
@ -1,4 +1,4 @@
|
|||||||
import { useEffect, useMemo, useRef, useState } from "preact/hooks";
|
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "preact/hooks";
|
||||||
import FNote from "../../../entities/fnote";
|
import FNote from "../../../entities/fnote";
|
||||||
import Icon from "../../react/Icon";
|
import Icon from "../../react/Icon";
|
||||||
import { ViewModeProps } from "../interface";
|
import { ViewModeProps } from "../interface";
|
||||||
@ -12,6 +12,7 @@ import link from "../../../services/link";
|
|||||||
import { t } from "../../../services/i18n";
|
import { t } from "../../../services/i18n";
|
||||||
import attribute_renderer from "../../../services/attribute_renderer";
|
import attribute_renderer from "../../../services/attribute_renderer";
|
||||||
import froca from "../../../services/froca";
|
import froca from "../../../services/froca";
|
||||||
|
import { RawHtmlBlock } from "../../react/RawHtml";
|
||||||
|
|
||||||
export function ListView({ note, noteIds: unfilteredNoteIds, highlightedTokens }: ViewModeProps<{}>) {
|
export function ListView({ note, noteIds: unfilteredNoteIds, highlightedTokens }: ViewModeProps<{}>) {
|
||||||
const [ isExpanded ] = useNoteLabelBoolean(note, "expanded");
|
const [ isExpanded ] = useNoteLabelBoolean(note, "expanded");
|
||||||
@ -35,31 +36,43 @@ export function ListView({ note, noteIds: unfilteredNoteIds, highlightedTokens }
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface NotesWithContent {
|
||||||
|
note: FNote;
|
||||||
|
content: string;
|
||||||
|
}
|
||||||
|
|
||||||
export function ListPrintView({ note, noteIds: unfilteredNoteIds, highlightedTokens, onReady }: ViewModeProps<{}>) {
|
export function ListPrintView({ note, noteIds: unfilteredNoteIds, highlightedTokens, onReady }: ViewModeProps<{}>) {
|
||||||
const noteIds = useFilteredNoteIds(note, unfilteredNoteIds);
|
const noteIds = useFilteredNoteIds(note, unfilteredNoteIds);
|
||||||
const [ notes, setNotes ] = useState<FNote[]>();
|
const [ notesWithContent, setNotesWithContent ] = useState<NotesWithContent[]>();
|
||||||
|
|
||||||
useEffect(() => {
|
useLayoutEffect(() => {
|
||||||
froca.getNotes(noteIds).then(setNotes);
|
froca.getNotes(noteIds).then(async (notes) => {
|
||||||
|
const notesWithContent: NotesWithContent[] = [];
|
||||||
|
for (const note of notes) {
|
||||||
|
const content = await content_renderer.getRenderedContent(note, {
|
||||||
|
trim: false,
|
||||||
|
noChildrenList: true
|
||||||
|
});
|
||||||
|
notesWithContent.push({ note, content: content.$renderedContent[0].innerHTML });
|
||||||
|
}
|
||||||
|
setNotesWithContent(notesWithContent);
|
||||||
|
});
|
||||||
}, [noteIds]);
|
}, [noteIds]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (notes && onReady) {
|
if (notesWithContent && onReady) {
|
||||||
onReady();
|
onReady();
|
||||||
}
|
}
|
||||||
}, [ notes, onReady ]);
|
}, [ notesWithContent, onReady ]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class="note-list list-print-view">
|
<div class="note-list list-print-view">
|
||||||
<div class="note-list-container use-tn-links">
|
<div class="note-list-container use-tn-links">
|
||||||
{notes?.map(childNote => (
|
{notesWithContent?.map(({ note: childNote, content }) => (
|
||||||
<>
|
<section id={`note-${childNote.noteId}`} class="note">
|
||||||
<h1>{childNote.title}</h1>
|
<h1>{childNote.title}</h1>
|
||||||
<NoteContent
|
<RawHtmlBlock html={content} />
|
||||||
note={childNote}
|
</section>
|
||||||
highlightedTokens={highlightedTokens}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user