This commit is contained in:
@@ -5,10 +5,12 @@ import { format, startOfWeek, addDays, parseISO } from 'date-fns';
|
||||
import { cs } from 'date-fns/locale';
|
||||
import { LocalData, SubstitutionData, ChangeEntry, Hour } from '@/lib/types';
|
||||
import { Card } from '@/components/ui/card';
|
||||
import { capitalizeFirstLetter } from '@/lib/utils';
|
||||
|
||||
interface ScheduleViewerProps {
|
||||
localData: LocalData;
|
||||
substitutionData: SubstitutionData | null;
|
||||
hideSubstitutions?: boolean;
|
||||
}
|
||||
|
||||
function getChangesForClass(changes: Record<string, (ChangeEntry | null)[]> | undefined, className: string): (ChangeEntry | null)[] {
|
||||
@@ -22,7 +24,7 @@ function getChangesForClass(changes: Record<string, (ChangeEntry | null)[]> | un
|
||||
return [];
|
||||
}
|
||||
|
||||
export default function ScheduleViewer({ localData, substitutionData }: ScheduleViewerProps) {
|
||||
export default function ScheduleViewer({ localData, substitutionData, hideSubstitutions = false }: ScheduleViewerProps) {
|
||||
const referenceDate = useMemo(() => {
|
||||
if (substitutionData?.schedule) {
|
||||
const dates = Object.keys(substitutionData.schedule).sort();
|
||||
@@ -51,7 +53,7 @@ export default function ScheduleViewer({ localData, substitutionData }: Schedule
|
||||
|
||||
const currentWeekMaxHours = useMemo(() => {
|
||||
let max = maxHours;
|
||||
if (substitutionData?.schedule) {
|
||||
if (!hideSubstitutions && substitutionData?.schedule) {
|
||||
weekDays.forEach(date => {
|
||||
const dateStr = format(date, 'yyyy-MM-dd');
|
||||
const dayData = substitutionData.schedule[dateStr];
|
||||
@@ -62,7 +64,7 @@ export default function ScheduleViewer({ localData, substitutionData }: Schedule
|
||||
});
|
||||
}
|
||||
return max;
|
||||
}, [maxHours, substitutionData, weekDays, localData.class]);
|
||||
}, [maxHours, substitutionData, weekDays, localData.class, hideSubstitutions]);
|
||||
|
||||
const hours = Array.from({ length: currentWeekMaxHours }, (_, i) => i + 1);
|
||||
|
||||
@@ -115,7 +117,7 @@ export default function ScheduleViewer({ localData, substitutionData }: Schedule
|
||||
<td key={hourIndex} className="border-r min-w-[120px] h-full align-top relative p-0">
|
||||
<CellContent
|
||||
staticLessons={staticLessons}
|
||||
change={change}
|
||||
change={hideSubstitutions ? null : change}
|
||||
/>
|
||||
</td>
|
||||
);
|
||||
@@ -157,7 +159,7 @@ function CellContent({ staticLessons, change }: { staticLessons: Hour[], change:
|
||||
<div key={idx} className="flex-1 flex flex-col justify-between p-1 text-[10px] border-b min-h-[40px]">
|
||||
<div className='flex justify-between'>
|
||||
<div className="font-bold truncate">{lesson.subject}</div>
|
||||
<span className="truncate opacity-70">{lesson.teacher.code}</span>
|
||||
<span className="truncate opacity-70">{capitalizeFirstLetter(lesson.teacher.code)}</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="truncate max-w-[40px]">{lesson.room}</span>
|
||||
@@ -175,7 +177,7 @@ function CellContent({ staticLessons, change }: { staticLessons: Hour[], change:
|
||||
<div className="font-bold text-lg text-primary">{lesson.subject}</div>
|
||||
<div className="flex justify-between items-end mt-1">
|
||||
<div className="font-mono font-medium">{lesson.room}</div>
|
||||
<div className="text-[10px] opacity-80" title={lesson.teacher.name}>{lesson.teacher.code}</div>
|
||||
<div className="text-[10px] opacity-80" title={lesson.teacher.name}>{capitalizeFirstLetter(lesson.teacher.code)}</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
52
viewer/components/own/update-status.tsx
Normal file
52
viewer/components/own/update-status.tsx
Normal file
@@ -0,0 +1,52 @@
|
||||
"use client";
|
||||
|
||||
import { useTransition } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { RefreshCw } from "lucide-react";
|
||||
import { SubstitutionData } from "@/lib/types";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
interface UpdateStatusProps {
|
||||
data: SubstitutionData | null;
|
||||
}
|
||||
|
||||
export default function UpdateStatus({ data }: UpdateStatusProps) {
|
||||
const router = useRouter();
|
||||
const [isPending, startTransition] = useTransition();
|
||||
|
||||
if (!data) return null;
|
||||
|
||||
const handleRefresh = () => {
|
||||
startTransition(() => {
|
||||
router.refresh();
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4 text-sm text-muted-foreground p-4 rounded-lg border">
|
||||
<div>
|
||||
<span className="font-medium">Poslední aktualizace:</span> {data.status.lastUpdated}
|
||||
<span className="mx-2 hidden sm:inline">•</span>
|
||||
<br className="sm:hidden" />
|
||||
<span>
|
||||
Aktualizace každých{" "}
|
||||
{data.status.currentUpdateSchedule < 60
|
||||
? `${data.status.currentUpdateSchedule} min`
|
||||
: `${data.status.currentUpdateSchedule / 60} hod`}
|
||||
</span>
|
||||
</div>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={handleRefresh}
|
||||
disabled={isPending}
|
||||
className="w-full sm:w-auto"
|
||||
>
|
||||
<RefreshCw
|
||||
className={`h-4 w-4 mr-2 ${isPending ? "animate-spin" : ""}`}
|
||||
/>
|
||||
Aktualizovat
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user