feat(client/print): report progress for presentation printing

This commit is contained in:
Elian Doran 2025-11-21 20:15:27 +02:00
parent 39be268969
commit 097808752d
No known key found for this signature in database
3 changed files with 23 additions and 8 deletions

View File

@ -5,6 +5,8 @@ export type ViewTypeOptions = typeof allViewTypes[number];
export type ViewModeMedia = "screen" | "print"; export type ViewModeMedia = "screen" | "print";
export type ProgressChangedFn = (progress: number) => void;
export interface ViewModeProps<T extends object> { export interface ViewModeProps<T extends object> {
note: FNote; note: FNote;
notePath: string; notePath: string;
@ -17,5 +19,5 @@ export interface ViewModeProps<T extends object> {
saveConfig(newConfig: T): void; saveConfig(newConfig: T): void;
media: ViewModeMedia; media: ViewModeMedia;
onReady(): void; onReady(): void;
onProgressChanged?(progress: number): void; onProgressChanged?: ProgressChangedFn;
} }

View File

@ -14,14 +14,14 @@ import { t } from "../../../services/i18n";
import { DEFAULT_THEME, loadPresentationTheme } from "./themes"; import { DEFAULT_THEME, loadPresentationTheme } from "./themes";
import FNote from "../../../entities/fnote"; import FNote from "../../../entities/fnote";
export default function PresentationView({ note, noteIds, media, onReady }: ViewModeProps<{}>) { export default function PresentationView({ note, noteIds, media, onReady, onProgressChanged }: ViewModeProps<{}>) {
const [ presentation, setPresentation ] = useState<PresentationModel>(); const [ presentation, setPresentation ] = useState<PresentationModel>();
const containerRef = useRef<HTMLDivElement>(null); const containerRef = useRef<HTMLDivElement>(null);
const [ api, setApi ] = useState<Reveal.Api>(); const [ api, setApi ] = useState<Reveal.Api>();
const stylesheets = usePresentationStylesheets(note, media); const stylesheets = usePresentationStylesheets(note, media);
function refresh() { function refresh() {
buildPresentationModel(note).then(setPresentation); buildPresentationModel(note, onProgressChanged).then(setPresentation);
} }
useTriliumEvent("entitiesReloaded", ({ loadResults }) => { useTriliumEvent("entitiesReloaded", ({ loadResults }) => {

View File

@ -1,6 +1,7 @@
import { NoteType } from "@triliumnext/commons"; import { NoteType } from "@triliumnext/commons";
import FNote from "../../../entities/fnote"; import FNote from "../../../entities/fnote";
import contentRenderer from "../../../services/content_renderer"; import contentRenderer from "../../../services/content_renderer";
import { ProgressChangedFn } from "../interface";
type DangerouslySetInnerHTML = { __html: string; }; type DangerouslySetInnerHTML = { __html: string; };
@ -22,14 +23,26 @@ export interface PresentationModel {
slides: PresentationSlideModel[]; slides: PresentationSlideModel[];
} }
export async function buildPresentationModel(note: FNote): Promise<PresentationModel> { export async function buildPresentationModel(note: FNote, onProgressChanged?: ProgressChangedFn): Promise<PresentationModel> {
const slideNotes = await note.getChildNotes(); const slideNotes = await note.getChildNotes();
const slides: PresentationSlideModel[] = await Promise.all(slideNotes.map(async slideNote => ({ onProgressChanged?.(0.3);
...(await buildSlideModel(slideNote)), const total = slideNotes.length;
verticalSlides: note.type !== "search" ? await buildVerticalSlides(slideNote) : undefined let completed = 0;
})));
const slidePromises = slideNotes.map(slideNote => (async () => {
const base = await buildSlideModel(slideNote);
const verticalSlides = note.type !== "search" ? await buildVerticalSlides(slideNote) : undefined;
const slide: PresentationSlideModel = { ...base, verticalSlides };
completed++;
onProgressChanged?.(Math.min(0.3 + (completed / total) * 0.4, 0.7));
return slide;
})());
const slides: PresentationSlideModel[] = await Promise.all(slidePromises);
onProgressChanged?.(0.7);
postProcessSlides(slides); postProcessSlides(slides);
onProgressChanged?.(1);
return { slides }; return { slides };
} }