From ecf29fa0e87f4804bd1805ca6016df50cd45a798 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Wed, 15 Oct 2025 19:40:46 +0300 Subject: [PATCH] chore(collection/presentation): use model based mechanism for note content --- .../collections/presentation/index.tsx | 30 +++++++++++-------- .../widgets/collections/presentation/model.ts | 25 ++++++++++++++++ 2 files changed, 42 insertions(+), 13 deletions(-) create mode 100644 apps/client/src/widgets/collections/presentation/model.ts diff --git a/apps/client/src/widgets/collections/presentation/index.tsx b/apps/client/src/widgets/collections/presentation/index.tsx index dbb8bbcd4..7d57ef573 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 && ( - + const [ presentation, setPresentation ] = useState(); + + useLayoutEffect(() => { + buildPresentationModel(note).then(setPresentation); + }, [ note ]); + + return presentation && ( + ) } -function Presentation({ note }: { note: FNote }) { - const [ slides, setSlides ] = useState(); +function Presentation({ presentation } : { presentation: PresentationModel }) { const containerRef = useRef(null); const apiRef = useRef(null); - useLayoutEffect(() => { - note.getChildNotes().then(setSlides); - }, [ note ]); - useEffect(() => { if (apiRef.current || !containerRef.current) return; @@ -41,8 +43,8 @@ function Presentation({ note }: { note: FNote }) { return (
- {slides && slides?.map(slide => ( - + {presentation.slides?.map(slide => ( + ))}
@@ -50,10 +52,12 @@ function Presentation({ note }: { note: FNote }) { } -function Slide({ note }: { note: FNote }) { +function Slide({ slide }: { slide: PresentationSlideModel }) { + const containerRef = useRef(null); + return ( -
-

{note.title}

+
+ {slide.content}
); } 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 000000000..a7108a5d6 --- /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 { + + const slideNotes = await note.getChildNotes(); + const slides: PresentationSlideModel[] = []; + + for (const slideNote of slideNotes) { + slides.push({ + content: await slideNote.getContent() ?? "" + }) + } + + return { + slides + }; +}