feat(collection/presentation): get slidejs to render

This commit is contained in:
Elian Doran 2025-10-15 19:29:08 +03:00
parent 343f103126
commit c736fba1b7
No known key found for this signature in database
2 changed files with 26 additions and 2 deletions

View File

@ -72,6 +72,7 @@
"@types/leaflet": "1.9.21",
"@types/leaflet-gpx": "1.3.8",
"@types/mark.js": "8.11.12",
"@types/reveal.js": "5.2.1",
"@types/tabulator-tables": "6.2.11",
"copy-webpack-plugin": "13.0.1",
"happy-dom": "20.0.1",

View File

@ -1,6 +1,9 @@
import { ViewModeProps } from "../interface";
import FNote from "../../../entities/fnote";
import { useLayoutEffect, useState } from "preact/hooks";
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";
export default function PresentationView({ note }: ViewModeProps<{}>) {
return note && (
@ -10,13 +13,33 @@ export default function PresentationView({ note }: ViewModeProps<{}>) {
function Presentation({ note }: { note: FNote }) {
const [ slides, setSlides ] = useState<FNote[]>();
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;
apiRef.current = new Reveal(containerRef.current, {
transition: "slide"
});
apiRef.current.initialize().then(() => {
console.log("Slide.js initialized.");
});
return () => {
if (apiRef.current) {
apiRef.current.destroy();
apiRef.current = null;
}
}
}, []);
return (
<div className="reveal">
<div ref={containerRef} className="reveal">
<div className="slides">
{slides && slides?.map(slide => (
<Slide note={slide} />