feat(collections): display no children warning for empty presentations

This commit is contained in:
Elian Doran 2025-11-18 08:51:47 +02:00
parent ec76e9cf2a
commit 328bcd0532
No known key found for this signature in database
2 changed files with 4 additions and 3 deletions

View File

@ -41,7 +41,7 @@ export default function PresentationView({ note, noteIds, media, onReady }: View
} }
}, [ api, presentation ]); }, [ api, presentation ]);
if (!presentation || !stylesheets) return; if (!presentation || !stylesheets || !note.hasChildren()) return;
const content = ( const content = (
<> <>
{stylesheets.map(stylesheet => <style>{stylesheet}</style>)} {stylesheets.map(stylesheet => <style>{stylesheet}</style>)}

View File

@ -5,15 +5,16 @@ import RawHtml from "../react/RawHtml";
import { TypeWidgetProps } from "./type_widget"; import { TypeWidgetProps } from "./type_widget";
import "./Book.css"; import "./Book.css";
import { useEffect, useState } from "preact/hooks"; import { useEffect, useState } from "preact/hooks";
import { ViewTypeOptions } from "../collections/interface";
const VIEW_TYPES = [ "list", "grid" ]; const VIEW_TYPES: ViewTypeOptions[] = [ "list", "grid", "presentation" ];
export default function Book({ note }: TypeWidgetProps) { export default function Book({ note }: TypeWidgetProps) {
const [ viewType ] = useNoteLabelWithDefault(note, "viewType", "grid"); const [ viewType ] = useNoteLabelWithDefault(note, "viewType", "grid");
const [ shouldDisplayNoChildrenWarning, setShouldDisplayNoChildrenWarning ] = useState(false); const [ shouldDisplayNoChildrenWarning, setShouldDisplayNoChildrenWarning ] = useState(false);
function refresh() { function refresh() {
setShouldDisplayNoChildrenWarning(!note.hasChildren() && VIEW_TYPES.includes(viewType ?? "")); setShouldDisplayNoChildrenWarning(!note.hasChildren() && VIEW_TYPES.includes(viewType as ViewTypeOptions));
} }
useEffect(refresh, [ note, viewType ]); useEffect(refresh, [ note, viewType ]);