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
refactor(collection/presentation): apply review suggestions
Elian Doran96f5b55d9fc5
diff --git a/apps/client/src/widgets/collections/presentation/index.tsx b/apps/client/src/widgets/collections/presentation/index.tsxindex 656940c680..7f40e89230 100644--- a/apps/client/src/widgets/collections/presentation/index.tsx+++ b/apps/client/src/widgets/collections/presentation/index.tsx@@ -30,7 +30,6 @@ export default function PresentationView({ note, noteIds }: ViewModeProps<{}>) {useTriliumEvent("entitiesReloaded", ({ loadResults }) => {if (loadResults.getNoteIds().find(noteId => noteIds.includes(noteId))) {- console.log("Needs reload!");refresh();}});@@ -105,7 +104,7 @@ function ButtonOverlay({ containerRef, api }: { containerRef: RefObject<HTMLDivE)}-function Presentation({ presentation, setApi } : { presentation: PresentationModel, setApi: (api: Reveal.Api) => void }) {+function Presentation({ presentation, setApi } : { presentation: PresentationModel, setApi: (api: Reveal.Api | undefined) => void }) {const containerRef = useRef<HTMLDivElement>(null);const apiRef = useRef<Reveal.Api>(null);const isFirstRenderRef = useRef(true);@@ -133,6 +132,7 @@ function Presentation({ presentation, setApi } : { presentation: PresentationModreturn () => {api.destroy();apiRef.current = null;+ setApi(undefined);}}, [ ]);diff --git a/apps/client/src/widgets/collections/presentation/model.ts b/apps/client/src/widgets/collections/presentation/model.tsindex a94ada59f9..031ff2f36f 100644--- a/apps/client/src/widgets/collections/presentation/model.ts+++ b/apps/client/src/widgets/collections/presentation/model.ts@@ -19,17 +19,12 @@ export interface PresentationModel {}export async function buildPresentationModel(note: FNote): Promise<PresentationModel> {-const slideNotes = await note.getChildNotes();- const slides: PresentationSlideModel[] = [];-- for (const slideNote of slideNotes) {- slides.push({- noteId: slideNote.noteId,- content: await processContent(slideNote),- verticalSlides: await buildVerticalSlides(slideNote)- })- }+ const slides: PresentationSlideModel[] = await Promise.all(slideNotes.map(async slideNote => ({+ noteId: slideNote.noteId,+ content: await processContent(slideNote),+ verticalSlides: await buildVerticalSlides(slideNote)+ })))return { slides };}@@ -38,13 +33,11 @@ async function buildVerticalSlides(parentSlideNote: FNote): Promise<undefined |const children = await parentSlideNote.getChildNotes();if (!children.length) return;- const slides: PresentationSlideBaseModel[] = [];- for (const childNote of children) {- slides.push({- noteId: childNote.noteId,- content: await processContent(childNote)- });- }+ const slides: PresentationSlideBaseModel[] = await Promise.all(children.map(async childNote => ({+ noteId: childNote.noteId,+ content: await processContent(childNote)+ })));+return slides;}diff --git a/apps/client/src/widgets/react/ShadowDom.tsx b/apps/client/src/widgets/react/ShadowDom.tsxindex 3bbd23427a..7b98aba75e 100644--- a/apps/client/src/widgets/react/ShadowDom.tsx+++ b/apps/client/src/widgets/react/ShadowDom.tsx@@ -13,10 +13,10 @@ export default function ShadowDom({ children, containerRef: externalContainerRef// Create the shadow root.useEffect(() => {- if (!containerRef.current || shadowRoot) return;+ if (!containerRef.current) return;const shadow = containerRef.current.attachShadow({ mode: "open" });setShadowRoot(shadow);- }, [ shadowRoot ]);+ }, []);// Render the child elements.useEffect(() => {