refactor(collection/presentation): apply review suggestions

This commit is contained in:
Elian Doran 2025-10-16 09:02:02 +03:00
parent 90e5193a97
commit 96f5b55d9f
No known key found for this signature in database
3 changed files with 14 additions and 21 deletions

View File

@ -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: PresentationMod
return () => {
api.destroy();
apiRef.current = null;
setApi(undefined);
}
}, [ ]);

View File

@ -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;
}

View File

@ -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(() => {