Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
966554e615 | ||
|
|
c5e351cec3 | ||
|
|
b3e8b1209a | ||
|
|
e5e66b2953 | ||
|
|
19d2d191d0 | ||
|
|
9935be7a25 | ||
|
|
e143b407c6 |
No files matched your search
@@ -2,9 +2,9 @@ import ical, { VEvent } from 'node-ical';
|
||||
import CategoryChart from '@/components/CategoryChart';
|
||||
|
||||
interface PageProps {
|
||||
params: Promise<{
|
||||
'days': string;
|
||||
'ical-link': string[];
|
||||
searchParams: Promise<{
|
||||
'days'?: string;
|
||||
'ical-link'?: string | string[];
|
||||
}>;
|
||||
}
|
||||
|
||||
@@ -31,17 +31,25 @@ function getCategories(categoriesField: any): string[] {
|
||||
|
||||
type TimeMap = Record<string, number>;
|
||||
|
||||
export default async function EvaluationPage({ params }: PageProps) {
|
||||
export default async function EvaluationPage({ searchParams }: PageProps) {
|
||||
const times: TimeMap = {};
|
||||
let total = 0;
|
||||
|
||||
const resolvedParams = await params;
|
||||
const daysToFetch = Number(resolvedParams['days']) || 7;
|
||||
const resolvedSearchParams = await searchParams;
|
||||
const daysToFetch = Number(resolvedSearchParams['days']) || 7;
|
||||
|
||||
const pathSegments = resolvedParams['ical-link'];
|
||||
let rawUrl = pathSegments.join('/');
|
||||
rawUrl = decodeURIComponent(rawUrl);
|
||||
const icalUrl = rawUrl.replace(/^(https?):\/+/, '$1://');
|
||||
const rawUrl = resolvedSearchParams['ical-link'];
|
||||
|
||||
if (!rawUrl) {
|
||||
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 } });
|
||||
if (!response.ok) {
|
||||
@@ -112,20 +120,23 @@ export default async function EvaluationPage({ params }: PageProps) {
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{Object.entries(times).map(([category, minutes]) => (
|
||||
<tr key={category} style={{ borderBottom: '1px solid #e5e7eb' }}>
|
||||
<td style={{ padding: '0.5rem' }}>{category}</td>
|
||||
<td style={{ padding: '0.5rem', whiteSpace: 'nowrap' }}>
|
||||
{Math.floor(minutes / 60)}:{Math.round(minutes % 60)}h (={Math.round(minutes)} min)
|
||||
</td>
|
||||
<td style={{ padding: '0.5rem' }}>
|
||||
{total > 0 ? Math.round((minutes / total) * 1000) / 10 : 0}%
|
||||
</td>
|
||||
<td style={{ padding: '0.5rem' }}>
|
||||
{total > 0 ? Math.round((minutes / (daysToFetch * 24 * 60)) * 1000) / 10 : 0}%
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
{Object.entries(times)
|
||||
.sort(([, minutesA], [, minutesB]) => minutesB - minutesA)
|
||||
.map(([category, minutes]) => (
|
||||
<tr key={category} style={{ borderBottom: '1px solid #e5e7eb' }}>
|
||||
<td style={{ padding: '0.5rem' }}>{category}</td>
|
||||
<td style={{ padding: '0.5rem', whiteSpace: 'nowrap' }}>
|
||||
{Math.floor(minutes / 60)}:{Math.round(minutes % 60).toString().padStart(2, '0')}h (={Math.round(minutes)} min)
|
||||
</td>
|
||||
<td style={{ padding: '0.5rem' }}>
|
||||
{total > 0 ? Math.round((minutes / total) * 1000) / 10 : 0}%
|
||||
</td>
|
||||
<td style={{ padding: '0.5rem' }}>
|
||||
{total > 0 ? Math.round((minutes / (daysToFetch * 24 * 60)) * 1000) / 10 : 0}%
|
||||
</td>
|
||||
</tr>
|
||||
))
|
||||
}
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr style={{ fontWeight: 'bold' }}>
|
||||
+94
-2
@@ -1,7 +1,99 @@
|
||||
import Image from "next/image";
|
||||
"use client"
|
||||
|
||||
import { useState } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
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 (
|
||||
<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>
|
||||
);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
'use client';
|
||||
|
||||
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)
|
||||
ChartJS.register(ArcElement, Tooltip, Legend);
|
||||
@@ -56,7 +56,7 @@ export default function CategoryChart({ times }: CategoryChartProps) {
|
||||
|
||||
return (
|
||||
<div style={{ maxWidth: '360px', margin: '1.5rem auto' }}>
|
||||
<Doughnut data={data} options={options} />
|
||||
<Pie data={data} options={options} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user