Skip to content

Build your personal knowledge base with Trilium Notes

chore(collection/presentation): use model based mechanism for note content

Elian Doranecf29fa0e87f
diff --git a/apps/client/src/widgets/collections/presentation/index.tsx b/apps/client/src/widgets/collections/presentation/index.tsx
index dbb8bbcd4f..7d57ef573d 100644
--- a/apps/client/src/widgets/collections/presentation/index.tsx
+++ b/apps/client/src/widgets/collections/presentation/index.tsx
@@ -4,22 +4,24 @@ import { useEffect, useLayoutEffect, useRef, useState } from "preact/hooks";
import Reveal from "reveal.js";
import "reveal.js/dist/reveal.css";
import "reveal.js/dist/theme/black.css";
+import { buildPresentationModel, PresentationModel, PresentationSlideModel } from "./model";
export default function PresentationView({ note }: ViewModeProps<{}>) {
- return note && (
- <Presentation note={note} />
+ const [ presentation, setPresentation ] = useState<PresentationModel>();
+
+ useLayoutEffect(() => {
+ buildPresentationModel(note).then(setPresentation);
+ }, [ note ]);
+
+ return presentation && (
+ <Presentation presentation={presentation} />
)
}
-function Presentation({ note }: { note: FNote }) {
- const [ slides, setSlides ] = useState<FNote[]>();
+function Presentation({ presentation } : { presentation: PresentationModel }) {
const containerRef = useRef<HTMLDivElement>(null);
const apiRef = useRef<Reveal.Api | null>(null);
- useLayoutEffect(() => {
- note.getChildNotes().then(setSlides);
- }, [ note ]);
-
useEffect(() => {
if (apiRef.current || !containerRef.current) return;
@@ -41,8 +43,8 @@ function Presentation({ note }: { note: FNote }) {
return (
<div ref={containerRef} className="reveal">
<div className="slides">
- {slides && slides?.map(slide => (
- <Slide note={slide} />
+ {presentation.slides?.map(slide => (
+ <Slide slide={slide} />
))}
</div>
</div>
@@ -50,10 +52,12 @@ function Presentation({ note }: { note: FNote }) {
}
-function Slide({ note }: { note: FNote }) {
+function Slide({ slide }: { slide: PresentationSlideModel }) {
+ const containerRef = useRef<HTMLDivElement>(null);
+
return (
- <section>
- <p>{note.title}</p>
+ <section ref={containerRef}>
+ {slide.content}
</section>
);
}
diff --git a/apps/client/src/widgets/collections/presentation/model.ts b/apps/client/src/widgets/collections/presentation/model.ts
new file mode 100644
index 0000000000..a7108a5d69
--- /dev/null
+++ b/apps/client/src/widgets/collections/presentation/model.ts
@@ -0,0 +1,25 @@
+import FNote from "../../../entities/fnote";
+
+export interface PresentationSlideModel {
+ content: string;
+}
+
+export interface PresentationModel {
+ slides: PresentationSlideModel[];
+}
+
+export async function buildPresentationModel(note: FNote): Promise<PresentationModel> {
+
+ const slideNotes = await note.getChildNotes();
+ const slides: PresentationSlideModel[] = [];
+
+ for (const slideNote of slideNotes) {
+ slides.push({
+ content: await slideNote.getContent() ?? ""
+ })
+ }
+
+ return {
+ slides
+ };
+}