style: move total to own variable and table footer
This commit is contained in:
1 parent
95e09c6d21
commit
7104dd0771
1 file changed
+35
-11
@@ -31,9 +31,8 @@ function getCategories(categoriesField: any): string[] {
|
||||
type TimeMap = Record<string, number>
|
||||
|
||||
export default async function EvaluationPage({ params }: PageProps) {
|
||||
let times: TimeMap = {
|
||||
total: 0
|
||||
};
|
||||
let times: TimeMap = {};
|
||||
let total: number = 0;
|
||||
|
||||
// get all params
|
||||
const resolvedParams = await params;
|
||||
@@ -79,9 +78,10 @@ export default async function EvaluationPage({ params }: PageProps) {
|
||||
const categories = getCategories(event.categories);
|
||||
|
||||
categories.forEach((cat) => {
|
||||
times["total"] = (times["total"] || 0) + durationInMinutes
|
||||
times[cat] = (times[cat] || 0) + durationInMinutes
|
||||
})
|
||||
|
||||
total = (total || 0) + durationInMinutes
|
||||
})
|
||||
|
||||
return (
|
||||
@@ -91,13 +91,37 @@ export default async function EvaluationPage({ params }: PageProps) {
|
||||
{Object.keys(times).length === 0 ? (
|
||||
<p>Keine Zeiten erfasst.</p>
|
||||
) : (
|
||||
<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>
|
||||
// <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]) => (
|
||||
<tr key={category}>
|
||||
<td>{category}</td>
|
||||
<td>{Math.floor(minutes / 60)} Std. {minutes % 60} Min. ({minutes} Min. gesamt)</td>
|
||||
<td>{Math.round(minutes / total *100 *10)/10}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td>Total</td>
|
||||
<td>{Math.floor(total / 60)} Std. {total % 60} Min. ({total} Min. gesamt)</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
)}
|
||||
</section>
|
||||
|
||||
|
||||
Reference in new issue
Block a user