mirror of
https://github.com/zadam/trilium.git
synced 2025-10-19 14:49:01 +02:00
chore(collection/presentation): use model based mechanism for note content
This commit is contained in:
parent
499c190632
commit
ecf29fa0e8
@ -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>
|
||||
);
|
||||
}
|
||||
|
25
apps/client/src/widgets/collections/presentation/model.ts
Normal file
25
apps/client/src/widgets/collections/presentation/model.ts
Normal 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
|
||||
};
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user