/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/ 'use client' import { AbstractApi } from "@/app/api/abstract-api"; import { TableArrangementStatus } from "@/app/lib/definitions"; import { TableSimulation, TableSimulationSerializer } from "@/app/lib/tableSimulation"; import { getSlug } from "@/app/lib/utils"; import { Toast } from "primereact/toast"; import { useEffect, useRef, useState } from "react"; import { ProgressSpinner } from 'primereact/progressspinner'; import { classNames } from "../components/button"; export default function CalculatingSummary() { const [stats, setStats] = useState<{ [key in TableArrangementStatus]: number }>({ in_progress: 0, completed: 0, not_started: 0, }); const [inProgress, setInProgress] = useState([]); useEffect(() => { const fetchStats = () => { fetch(`/api/${getSlug()}/tables_arrangements/stats`) .then((response) => response.json()) .then((data) => { setStats(data.count); setInProgress(data.in_progress); }); }; fetchStats(); const interval = setInterval(fetchStats, 10000); return () => clearInterval(interval); }, []); const toast = useRef(null); function createSimulation() { const api = new AbstractApi(); const serializer = new TableSimulationSerializer(); api.create(serializer, new TableSimulation(), () => { toast.current?.show({ severity: 'success', summary: 'Simulation created', detail: 'Table distributions will be calculated shortly, please come back in some minutes' }); }); } return ( <>

Processing engine

{stats.in_progress || 0 } processing

{inProgress.map((progress, index) => (
{Math.round(progress * 100)}%
))}

+{stats.not_started || 0 } in queue

); }