5 Commits
Author SHA1 Message Date
robin 966554e615 feat: sort table by time 2026-08-25 13:38:22 +02:00
robin c5e351cec3 style: switch to Pie diagramm 2026-08-04 12:16:06 +02:00
robin b3e8b1209a chore: remove unnecessary comments 2026-08-04 12:09:39 +02:00
robin e5e66b2953 feat: create index page 2026-08-04 12:06:21 +02:00
robin 19d2d191d0 refactor: switch arguments to query parameters 2026-08-04 11:50:37 +02:00
3 changed files with 131 additions and 28 deletions

No files matched your search

@@ -2,9 +2,9 @@ import ical, { VEvent } from 'node-ical';
import CategoryChart from '@/components/CategoryChart'; import CategoryChart from '@/components/CategoryChart';
interface PageProps { interface PageProps {
params: Promise<{ searchParams: Promise<{
'days': string; 'days'?: string;
'ical-link': string[]; 'ical-link'?: string | string[];
}>; }>;
} }
@@ -31,17 +31,25 @@ 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({ searchParams }: PageProps) {
const times: TimeMap = {}; const times: TimeMap = {};
let total = 0; let total = 0;
const resolvedParams = await params; const resolvedSearchParams = await searchParams;
const daysToFetch = Number(resolvedParams['days']) || 7; const daysToFetch = Number(resolvedSearchParams['days']) || 7;
const pathSegments = resolvedParams['ical-link']; const rawUrl = resolvedSearchParams['ical-link'];
let rawUrl = pathSegments.join('/');
rawUrl = decodeURIComponent(rawUrl); if (!rawUrl) {
const icalUrl = rawUrl.replace(/^(https?):\/+/, '$1://'); return (
<div style={{ padding: '1rem', color: '#dc2626', fontFamily: 'system-ui, sans-serif' }}>
Fehler: Kein iCal-Link übergeben. Bitte verwende den Query-Parameter ?ical-link=...
</div>
);
}
const singleUrl = Array.isArray(rawUrl) ? rawUrl[0] : rawUrl;
const icalUrl = decodeURIComponent(singleUrl);
const response = await fetch(icalUrl, { next: { revalidate: 3600 } }); const response = await fetch(icalUrl, { next: { revalidate: 3600 } });
if (!response.ok) { if (!response.ok) {
@@ -112,20 +120,23 @@ export default async function EvaluationPage({ params }: PageProps) {
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{Object.entries(times).map(([category, minutes]) => ( {Object.entries(times)
<tr key={category} style={{ borderBottom: '1px solid #e5e7eb' }}> .sort(([, minutesA], [, minutesB]) => minutesB - minutesA)
<td style={{ padding: '0.5rem' }}>{category}</td> .map(([category, minutes]) => (
<td style={{ padding: '0.5rem', whiteSpace: 'nowrap' }}> <tr key={category} style={{ borderBottom: '1px solid #e5e7eb' }}>
{Math.floor(minutes / 60)}:{Math.round(minutes % 60)}h (={Math.round(minutes)} min) <td style={{ padding: '0.5rem' }}>{category}</td>
</td> <td style={{ padding: '0.5rem', whiteSpace: 'nowrap' }}>
<td style={{ padding: '0.5rem' }}> {Math.floor(minutes / 60)}:{Math.round(minutes % 60).toString().padStart(2, '0')}h (={Math.round(minutes)} min)
{total > 0 ? Math.round((minutes / total) * 1000) / 10 : 0}% </td>
</td> <td style={{ padding: '0.5rem' }}>
<td style={{ padding: '0.5rem' }}> {total > 0 ? Math.round((minutes / total) * 1000) / 10 : 0}%
{total > 0 ? Math.round((minutes / (daysToFetch * 24 * 60)) * 1000) / 10 : 0}% </td>
</td> <td style={{ padding: '0.5rem' }}>
</tr> {total > 0 ? Math.round((minutes / (daysToFetch * 24 * 60)) * 1000) / 10 : 0}%
))} </td>
</tr>
))
}
</tbody> </tbody>
<tfoot> <tfoot>
<tr style={{ fontWeight: 'bold' }}> <tr style={{ fontWeight: 'bold' }}>
+94 -2
View File
@@ -1,7 +1,99 @@
import Image from "next/image"; "use client"
import { useState } from 'react';
import { useRouter } from 'next/navigation';
export default function Home() { export default function Home() {
const [icalLink, setIcalLink] = useState('');
const [days, setDays] = useState<number | string>(7) // standart: 7 days
const router = useRouter();
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault(); // website won't reload
if (!icalLink) {
return;
}
router.push(`/evaluation?days=${days}&ical-link=${icalLink}`);
};
return ( return (
<p>hi</p> <main
style={{
width: '100%',
maxWidth: '800px',
margin: '0 auto',
padding: '1rem',
boxSizing: 'border-box',
fontFamily: 'system-ui, sans-serif',
}}
>
<section style={{ marginBottom: '2.5rem' }}>
<form
onSubmit={handleSubmit}
style={{ display: 'flex', flexDirection: 'column', gap: '1rem', maxWidth: '400px' }}
>
<div style={{ display: 'flex', flexDirection: 'column', gap: '0.3rem' }}>
<label htmlFor="ical-link-input" style={{ fontWeight: 600 }}>
iCal-Link
</label>
<input
type="url"
id="ical-link-input"
value={icalLink}
onChange={(e) => setIcalLink(e.target.value)}
placeholder="https://example.com/calendar.ics"
required
style={{
padding: '0.5rem',
borderRadius: '4px',
border: '1px solid #ccc',
fontSize: '1rem',
}}
/>
</div>
<div style={{ display: 'flex', flexDirection: 'column', gap: '0.3rem' }}>
<label htmlFor="days-input" style={{ fontWeight: 600 }}>
Anzahl der betrachteten Tage
</label>
<input
type="number"
id="days-input"
min={1}
value={days}
onChange={(e) => setDays(Number(e.target.value) || '')}
placeholder="7"
required
style={{
padding: '0.5rem',
borderRadius: '4px',
border: '1px solid #ccc',
fontSize: '1rem',
}}
/>
</div>
<button
type="submit"
style={{
marginTop: '0.5rem',
padding: '0.75rem',
backgroundColor: '#3b82f6',
color: 'white',
border: 'none',
borderRadius: '4px',
fontSize: '1rem',
fontWeight: 600,
cursor: 'pointer',
}}
>
Zu den Diagrammen
</button>
</form>
</section>
</main>
); );
} }
+2 -2
View File
@@ -1,7 +1,7 @@
'use client'; 'use client';
import { Chart as ChartJS, ArcElement, Tooltip, Legend } from 'chart.js'; import { Chart as ChartJS, ArcElement, Tooltip, Legend } from 'chart.js';
import { Doughnut } from 'react-chartjs-2'; import { Pie } from 'react-chartjs-2';
// Chart.js Module registrieren (wichtig in v3/v4) // Chart.js Module registrieren (wichtig in v3/v4)
ChartJS.register(ArcElement, Tooltip, Legend); ChartJS.register(ArcElement, Tooltip, Legend);
@@ -56,7 +56,7 @@ export default function CategoryChart({ times }: CategoryChartProps) {
return ( return (
<div style={{ maxWidth: '360px', margin: '1.5rem auto' }}> <div style={{ maxWidth: '360px', margin: '1.5rem auto' }}>
<Doughnut data={data} options={options} /> <Pie data={data} options={options} />
</div> </div>
); );
} }