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

This commit is contained in:
Elian Doran 2025-10-15 19:40:46 +03:00
parent 499c190632
commit ecf29fa0e8
No known key found for this signature in database
2 changed files with 42 additions and 13 deletions

View File

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

View File

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