mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 15:19:01 +02:00
refactor(collection/presentation): apply review suggestions
This commit is contained in:
parent
90e5193a97
commit
96f5b55d9f
@ -30,7 +30,6 @@ export default function PresentationView({ note, noteIds }: ViewModeProps<{}>) {
|
|||||||
|
|
||||||
useTriliumEvent("entitiesReloaded", ({ loadResults }) => {
|
useTriliumEvent("entitiesReloaded", ({ loadResults }) => {
|
||||||
if (loadResults.getNoteIds().find(noteId => noteIds.includes(noteId))) {
|
if (loadResults.getNoteIds().find(noteId => noteIds.includes(noteId))) {
|
||||||
console.log("Needs reload!");
|
|
||||||
refresh();
|
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 containerRef = useRef<HTMLDivElement>(null);
|
||||||
const apiRef = useRef<Reveal.Api>(null);
|
const apiRef = useRef<Reveal.Api>(null);
|
||||||
const isFirstRenderRef = useRef(true);
|
const isFirstRenderRef = useRef(true);
|
||||||
@ -133,6 +132,7 @@ function Presentation({ presentation, setApi } : { presentation: PresentationMod
|
|||||||
return () => {
|
return () => {
|
||||||
api.destroy();
|
api.destroy();
|
||||||
apiRef.current = null;
|
apiRef.current = null;
|
||||||
|
setApi(undefined);
|
||||||
}
|
}
|
||||||
}, [ ]);
|
}, [ ]);
|
||||||
|
|
||||||
|
@ -19,17 +19,12 @@ export interface PresentationModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function buildPresentationModel(note: FNote): Promise<PresentationModel> {
|
export async function buildPresentationModel(note: FNote): Promise<PresentationModel> {
|
||||||
|
|
||||||
const slideNotes = await note.getChildNotes();
|
const slideNotes = await note.getChildNotes();
|
||||||
const slides: PresentationSlideModel[] = [];
|
const slides: PresentationSlideModel[] = await Promise.all(slideNotes.map(async slideNote => ({
|
||||||
|
|
||||||
for (const slideNote of slideNotes) {
|
|
||||||
slides.push({
|
|
||||||
noteId: slideNote.noteId,
|
noteId: slideNote.noteId,
|
||||||
content: await processContent(slideNote),
|
content: await processContent(slideNote),
|
||||||
verticalSlides: await buildVerticalSlides(slideNote)
|
verticalSlides: await buildVerticalSlides(slideNote)
|
||||||
})
|
})))
|
||||||
}
|
|
||||||
|
|
||||||
return { slides };
|
return { slides };
|
||||||
}
|
}
|
||||||
@ -38,13 +33,11 @@ async function buildVerticalSlides(parentSlideNote: FNote): Promise<undefined |
|
|||||||
const children = await parentSlideNote.getChildNotes();
|
const children = await parentSlideNote.getChildNotes();
|
||||||
if (!children.length) return;
|
if (!children.length) return;
|
||||||
|
|
||||||
const slides: PresentationSlideBaseModel[] = [];
|
const slides: PresentationSlideBaseModel[] = await Promise.all(children.map(async childNote => ({
|
||||||
for (const childNote of children) {
|
|
||||||
slides.push({
|
|
||||||
noteId: childNote.noteId,
|
noteId: childNote.noteId,
|
||||||
content: await processContent(childNote)
|
content: await processContent(childNote)
|
||||||
});
|
})));
|
||||||
}
|
|
||||||
return slides;
|
return slides;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,10 +13,10 @@ export default function ShadowDom({ children, containerRef: externalContainerRef
|
|||||||
|
|
||||||
// Create the shadow root.
|
// Create the shadow root.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!containerRef.current || shadowRoot) return;
|
if (!containerRef.current) return;
|
||||||
const shadow = containerRef.current.attachShadow({ mode: "open" });
|
const shadow = containerRef.current.attachShadow({ mode: "open" });
|
||||||
setShadowRoot(shadow);
|
setShadowRoot(shadow);
|
||||||
}, [ shadowRoot ]);
|
}, []);
|
||||||
|
|
||||||
// Render the child elements.
|
// Render the child elements.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user