Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
122c984341 |
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 {
|
||||||
searchParams: Promise<{
|
params: Promise<{
|
||||||
'days'?: string;
|
'days': string;
|
||||||
'ical-link'?: string | string[];
|
'ical-link': string[];
|
||||||
}>;
|
}>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,25 +31,17 @@ function getCategories(categoriesField: any): string[] {
|
|||||||
|
|
||||||
type TimeMap = Record<string, number>;
|
type TimeMap = Record<string, number>;
|
||||||
|
|
||||||
export default async function EvaluationPage({ searchParams }: PageProps) {
|
export default async function EvaluationPage({ params }: PageProps) {
|
||||||
const times: TimeMap = {};
|
const times: TimeMap = {};
|
||||||
let total = 0;
|
let total = 0;
|
||||||
|
|
||||||
const resolvedSearchParams = await searchParams;
|
const resolvedParams = await params;
|
||||||
const daysToFetch = Number(resolvedSearchParams['days']) || 7;
|
const daysToFetch = Number(resolvedParams['days']) || 7;
|
||||||
|
|
||||||
const rawUrl = resolvedSearchParams['ical-link'];
|
const pathSegments = resolvedParams['ical-link'];
|
||||||
|
let rawUrl = pathSegments.join('/');
|
||||||
if (!rawUrl) {
|
rawUrl = decodeURIComponent(rawUrl);
|
||||||
return (
|
const icalUrl = rawUrl.replace(/^(https?):\/+/, '$1://');
|
||||||
<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) {
|
||||||
@@ -120,13 +112,11 @@ export default async function EvaluationPage({ searchParams }: PageProps) {
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{Object.entries(times)
|
{Object.entries(times).map(([category, minutes]) => (
|
||||||
.sort(([, minutesA], [, minutesB]) => minutesB - minutesA)
|
|
||||||
.map(([category, minutes]) => (
|
|
||||||
<tr key={category} style={{ borderBottom: '1px solid #e5e7eb' }}>
|
<tr key={category} style={{ borderBottom: '1px solid #e5e7eb' }}>
|
||||||
<td style={{ padding: '0.5rem' }}>{category}</td>
|
<td style={{ padding: '0.5rem' }}>{category}</td>
|
||||||
<td style={{ padding: '0.5rem', whiteSpace: 'nowrap' }}>
|
<td style={{ padding: '0.5rem', whiteSpace: 'nowrap' }}>
|
||||||
{Math.floor(minutes / 60)}:{Math.round(minutes % 60).toString().padStart(2, '0')}h (={Math.round(minutes)} min)
|
{Math.floor(minutes / 60)}:{Math.round(minutes % 60)}h (={Math.round(minutes)} min)
|
||||||
</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 / total) * 1000) / 10 : 0}%
|
||||||
@@ -135,8 +125,7 @@ export default async function EvaluationPage({ searchParams }: PageProps) {
|
|||||||
{total > 0 ? Math.round((minutes / (daysToFetch * 24 * 60)) * 1000) / 10 : 0}%
|
{total > 0 ? Math.round((minutes / (daysToFetch * 24 * 60)) * 1000) / 10 : 0}%
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
))
|
))}
|
||||||
}
|
|
||||||
</tbody>
|
</tbody>
|
||||||
<tfoot>
|
<tfoot>
|
||||||
<tr style={{ fontWeight: 'bold' }}>
|
<tr style={{ fontWeight: 'bold' }}>
|
||||||
+2
-94
@@ -1,99 +1,7 @@
|
|||||||
"use client"
|
import Image from "next/image";
|
||||||
|
|
||||||
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 (
|
||||||
<main
|
<p>hi</p>
|
||||||
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';
|
'use client';
|
||||||
|
|
||||||
import { Chart as ChartJS, ArcElement, Tooltip, Legend } from 'chart.js';
|
import { Chart as ChartJS, ArcElement, Tooltip, Legend } from 'chart.js';
|
||||||
import { Pie } from 'react-chartjs-2';
|
import { Doughnut } 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' }}>
|
||||||
<Pie data={data} options={options} />
|
<Doughnut data={data} options={options} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user