style: move total to own variable and table footer

This commit is contained in:
robin committed 2026-08-03 18:22:20 +02:00
1 parent 95e09c6d21
commit 7104dd0771
1 file changed
+33 -9
+33 -9
View File
@@ -31,9 +31,8 @@ function getCategories(categoriesField: any): string[] {
type TimeMap = Record<string, number> type TimeMap = Record<string, number>
export default async function EvaluationPage({ params }: PageProps) { export default async function EvaluationPage({ params }: PageProps) {
let times: TimeMap = { let times: TimeMap = {};
total: 0 let total: number = 0;
};
// get all params // get all params
const resolvedParams = await params; const resolvedParams = await params;
@@ -79,9 +78,10 @@ export default async function EvaluationPage({ params }: PageProps) {
const categories = getCategories(event.categories); const categories = getCategories(event.categories);
categories.forEach((cat) => { categories.forEach((cat) => {
times["total"] = (times["total"] || 0) + durationInMinutes
times[cat] = (times[cat] || 0) + durationInMinutes times[cat] = (times[cat] || 0) + durationInMinutes
}) })
total = (total || 0) + durationInMinutes
}) })
return ( return (
@@ -91,13 +91,37 @@ export default async function EvaluationPage({ params }: PageProps) {
{Object.keys(times).length === 0 ? ( {Object.keys(times).length === 0 ? (
<p>Keine Zeiten erfasst.</p> <p>Keine Zeiten erfasst.</p>
) : ( ) : (
<ul> // <ul>
// {Object.entries(times).map(([category, minutes]) => (
// <li key={category}>
// <strong>{category}:</strong> {Math.floor(minutes / 60)} Std. {minutes % 60} Min. ({minutes} Min. gesamt)
// </li>
// ))}
// </ul>
<table>
<thead>
<tr>
<td>Categorie</td>
<td>Time</td>
<td>Percentage</td>
</tr>
</thead>
<tbody>
{Object.entries(times).map(([category, minutes]) => ( {Object.entries(times).map(([category, minutes]) => (
<li key={category}> <tr key={category}>
<strong>{category}:</strong> {Math.floor(minutes / 60)} Std. {minutes % 60} Min. ({minutes} Min. gesamt) <td>{category}</td>
</li> <td>{Math.floor(minutes / 60)} Std. {minutes % 60} Min. ({minutes} Min. gesamt)</td>
<td>{Math.round(minutes / total *100 *10)/10}</td>
</tr>
))} ))}
</ul> </tbody>
<tfoot>
<tr>
<td>Total</td>
<td>{Math.floor(total / 60)} Std. {total % 60} Min. ({total} Min. gesamt)</td>
</tr>
</tfoot>
</table>
)} )}
</section> </section>