Your favorite shift management application!
feat: Adds skeleton loading states (#64)
panteL52725219edc4
diff --git a/app/page.tsx b/app/page.tsxindex 8ed912b..a4f1573 100644--- a/app/page.tsx+++ b/app/page.tsx@@ -23,13 +23,16 @@ import { useDialogStates } from "@/hooks/useDialogStates";import { useVersionInfo } from "@/hooks/useVersionInfo";import { EmptyCalendarState } from "@/components/empty-calendar-state";import { LockedCalendarView } from "@/components/locked-calendar-view";-import { LoadingState } from "@/components/loading-state";+import { CalendarSkeleton } from "@/components/calendar-skeleton";+import { CalendarContentSkeleton } from "@/components/calendar-content-skeleton";+import { LockedCalendarSkeleton } from "@/components/locked-calendar-skeleton";import { CalendarContent } from "@/components/calendar-content";import { AppFooter } from "@/components/app-footer";import { AppHeader } from "@/components/app-header";import { DialogManager } from "@/components/dialog-manager";import { CalendarDialog } from "@/components/calendar-dialog";import { getCalendarDays } from "@/lib/calendar-utils";+import { getCachedPassword } from "@/lib/password-cache";function HomeContent() {const router = useRouter();@@ -51,6 +54,7 @@ function HomeContent() {const {shifts,setShifts,+ loading: shiftsLoading,createShift: createShiftHook,updateShift: updateShiftHook,deleteShift: deleteShiftHook,@@ -287,9 +291,15 @@ function HomeContent() {// Calendar grid calculationsconst calendarDays = getCalendarDays(currentDate);+ // Check if selected calendar is locked and has no cached password+ const isSelectedCalendarLocked =+ selectedCalendar &&+ calendars.find((c) => c.id === selectedCalendar)?.isLocked &&+ !getCachedPassword(selectedCalendar);+// Loading stateif (loading) {- return <LoadingState />;+ return <CalendarSkeleton />;}// Empty state@@ -335,12 +345,16 @@ function HomeContent() {onManualShiftCreation={handleManualShiftCreation}onMobileCalendarDialogChange={dialogStates.setShowMobileCalendarDialog}onViewSettingsClick={() => dialogStates.setShowViewSettingsDialog(true)}- presetsLoading={presetsLoading}+ presetsLoading={presetsLoading && !isSelectedCalendarLocked}/><div className="container max-w-4xl mx-auto px-1 py-3 sm:p-4 flex-1">- {isVerifyingCalendarPassword ? (- <LoadingState />+ {isVerifyingCalendarPassword || shiftsLoading ? (+ isSelectedCalendarLocked ? (+ <LockedCalendarSkeleton />+ ) : (+ <CalendarContentSkeleton daysCount={calendarDays.length} />+ )) : selectedCalendar && !isCalendarUnlocked ? (<LockedCalendarViewcalendarId={selectedCalendar}diff --git a/components/calendar-content-skeleton.tsx b/components/calendar-content-skeleton.tsxnew file mode 100644index 0000000..112a21e--- /dev/null+++ b/components/calendar-content-skeleton.tsx@@ -0,0 +1,44 @@+import { Skeleton } from "@/components/ui/skeleton";++export function CalendarContentSkeleton({+ daysCount = 42,+}: {+ daysCount?: number;+}) {+ return (+ <div className="space-y-4">+ {/* Month Navigation Skeleton */}+ <div className="flex items-center justify-between mb-4">+ <Skeleton className="h-10 w-10 rounded-lg" />+ <Skeleton className="h-8 w-40" />+ <Skeleton className="h-10 w-10 rounded-lg" />+ </div>++ {/* Calendar Grid Skeleton */}+ <div className="grid grid-cols-7 gap-0 sm:gap-1.5 mb-6">+ {/* Weekday headers */}+ {Array.from({ length: 7 }).map((_, i) => (+ <Skeleton key={`header-${i}`} className="h-6 mx-1" />+ ))}++ {/* Calendar days */}+ {Array.from({ length: daysCount }).map((_, i) => (+ <div+ key={`day-${i}`}+ className="min-h-24 sm:min-h-28 border border-border/30 rounded-lg p-1.5 sm:p-2 space-y-1"+ >+ <Skeleton className="h-5 w-6" />+ <Skeleton className="h-4 w-full" />+ <Skeleton className="h-4 w-3/4" />+ </div>+ ))}+ </div>++ {/* Stats and Shifts Skeleton */}+ <div className="space-y-4">+ <Skeleton className="h-32 w-full rounded-xl" />+ <Skeleton className="h-32 w-full rounded-xl" />+ </div>+ </div>+ );+}diff --git a/components/calendar-skeleton.tsx b/components/calendar-skeleton.tsxnew file mode 100644index 0000000..c52de07--- /dev/null+++ b/components/calendar-skeleton.tsx@@ -0,0 +1,79 @@+import { Skeleton } from "@/components/ui/skeleton";++export function CalendarSkeleton() {+ return (+ <div className="min-h-screen flex flex-col">+ {/* Header Skeleton */}+ <div className="border-b border-border/50 bg-background/80 backdrop-blur-xl sticky top-0 z-50">+ <div className="container max-w-4xl mx-auto px-2 sm:px-4 py-3 sm:py-4">+ <div className="flex flex-col gap-3 sm:gap-4">+ {/* Top row with calendar and theme switchers */}+ <div className="flex items-center justify-between gap-2">+ <Skeleton className="h-10 w-48" />+ <div className="flex items-center gap-2">+ <Skeleton className="h-9 w-9 rounded-lg" />+ <Skeleton className="h-9 w-9 rounded-lg" />+ </div>+ </div>++ {/* Preset selector row */}+ <div className="flex flex-wrap gap-2">+ <Skeleton className="h-9 w-24" />+ <Skeleton className="h-9 w-32" />+ <Skeleton className="h-9 w-28" />+ <Skeleton className="h-9 w-9" />+ </div>+ </div>+ </div>+ </div>++ {/* Main Content */}+ <div className="container max-w-4xl mx-auto px-1 py-3 sm:p-4 flex-1">+ <div className="space-y-4">+ {/* Month Navigation Skeleton */}+ <div className="flex items-center justify-between mb-4">+ <Skeleton className="h-10 w-10 rounded-lg" />+ <Skeleton className="h-8 w-40" />+ <Skeleton className="h-10 w-10 rounded-lg" />+ </div>++ {/* Calendar Grid Skeleton */}+ <div className="grid grid-cols-7 gap-0 sm:gap-1.5 mb-6">+ {/* Weekday headers */}+ {Array.from({ length: 7 }).map((_, i) => (+ <Skeleton key={`header-${i}`} className="h-6 mx-1" />+ ))}++ {/* Calendar days */}+ {Array.from({ length: 35 }).map((_, i) => (+ <div+ key={`day-${i}`}+ className="min-h-24 sm:min-h-28 border border-border/30 rounded-lg p-1.5 sm:p-2 space-y-1"+ >+ <Skeleton className="h-5 w-6" />+ <Skeleton className="h-4 w-full" />+ <Skeleton className="h-4 w-3/4" />+ </div>+ ))}+ </div>++ {/* Stats and Shifts Skeleton */}+ <div className="space-y-4">+ <Skeleton className="h-32 w-full rounded-xl" />+ <Skeleton className="h-32 w-full rounded-xl" />+ </div>+ </div>+ </div>++ {/* Footer Skeleton */}+ <div className="border-t border-border/50 bg-background/80 backdrop-blur-xl">+ <div className="container max-w-4xl mx-auto px-2 sm:px-4 py-3 sm:py-4">+ <div className="flex flex-col sm:flex-row items-center justify-between gap-2">+ <Skeleton className="h-4 w-40" />+ <Skeleton className="h-4 w-32" />+ </div>+ </div>+ </div>+ </div>+ );+}diff --git a/components/external-sync-manage-dialog.tsx b/components/external-sync-manage-dialog.tsxindex 2890220..030dc10 100644--- a/components/external-sync-manage-dialog.tsx+++ b/components/external-sync-manage-dialog.tsx@@ -24,12 +24,12 @@ import { ColorPicker } from "@/components/ui/color-picker";import { Slider } from "@/components/ui/slider";import { useTranslations } from "next-intl";import {- Loader2,Trash2,RefreshCw,Plus,Edit2,ChevronDown,+ Loader2,} from "lucide-react";import { toast } from "sonner";import { PRESET_COLORS } from "@/lib/constants";diff --git a/components/loading-state.tsx b/components/loading-state.tsxdeleted file mode 100644index 2988bc0..0000000--- a/components/loading-state.tsx+++ /dev/null@@ -1,27 +0,0 @@-import { motion } from "motion/react";-import { useTranslations } from "next-intl";-import { Calendar as CalendarIcon } from "lucide-react";--export function LoadingState() {- const t = useTranslations();-- return (- <div className="min-h-screen flex items-center justify-center bg-gradient-to-b from-background to-muted/20">- <motion.div- className="text-center space-y-4"- initial={{ opacity: 0, scale: 0.9 }}- animate={{ opacity: 1, scale: 1 }}- >- <motion.div- animate={{ rotate: 360 }}- transition={{ duration: 2, repeat: Infinity, ease: "linear" }}- >- <CalendarIcon className="h-12 w-12 sm:h-16 sm:w-16 mx-auto text-primary" />- </motion.div>- <p className="text-sm sm:text-base text-muted-foreground font-medium">- {t("common.loading")}- </p>- </motion.div>- </div>- );-}diff --git a/components/locked-calendar-skeleton.tsx b/components/locked-calendar-skeleton.tsxnew file mode 100644index 0000000..c45c833--- /dev/null+++ b/components/locked-calendar-skeleton.tsx@@ -0,0 +1,34 @@+import { Skeleton } from "@/components/ui/skeleton";+import { Calendar as CalendarIcon } from "lucide-react";++export function LockedCalendarSkeleton() {+ return (+ <div className="flex flex-col items-center justify-center py-20">+ <div className="w-full max-w-md">+ <div className="bg-gradient-to-b from-background via-background to-muted/30 backdrop-blur-xl shadow-2xl border border-border/50 rounded-2xl p-8">+ {/* Icon */}+ <div className="w-20 h-20 rounded-full bg-primary/10 flex items-center justify-center mb-6 mx-auto">+ <CalendarIcon className="h-10 w-10 text-primary animate-pulse" />+ </div>++ {/* Title */}+ <Skeleton className="h-8 w-3/4 mx-auto mb-2" />++ {/* Description */}+ <Skeleton className="h-5 w-full mx-auto mb-8" />++ {/* Password Input */}+ <div className="space-y-4">+ <div className="space-y-2">+ <Skeleton className="h-4 w-20" />+ <Skeleton className="h-11 w-full" />+ </div>++ {/* Submit Button */}+ <Skeleton className="h-11 w-full rounded-lg" />+ </div>+ </div>+ </div>+ </div>+ );+}diff --git a/components/preset-list-skeleton.tsx b/components/preset-list-skeleton.tsxnew file mode 100644index 0000000..0bfda8e--- /dev/null+++ b/components/preset-list-skeleton.tsx@@ -0,0 +1,13 @@+import { Skeleton } from "@/components/ui/skeleton";++export function PresetListSkeleton() {+ return (+ <div className="flex flex-wrap gap-2">+ <Skeleton className="h-9 w-24 rounded-lg" />+ <Skeleton className="h-9 w-32 rounded-lg" />+ <Skeleton className="h-9 w-28 rounded-lg" />+ <Skeleton className="h-9 w-36 rounded-lg" />+ <Skeleton className="h-9 w-9 rounded-lg" />+ </div>+ );+}diff --git a/components/preset-list.tsx b/components/preset-list.tsxindex efbd485..0b7d364 100644--- a/components/preset-list.tsx+++ b/components/preset-list.tsx@@ -5,6 +5,7 @@ import { Check, Plus, Settings, ChevronDown, ChevronUp } from "lucide-react";import { ShiftPreset } from "@/lib/db/schema";import { CalendarWithCount } from "@/lib/types";import { getCachedPassword } from "@/lib/password-cache";+import { PresetListSkeleton } from "@/components/preset-list-skeleton";interface PresetListProps {calendars: CalendarWithCount[];@@ -45,16 +46,7 @@ export function PresetList({// Show loading state while fetchingif (loading) {- return (- <div className="border-2 border-dashed rounded-lg p-4 sm:p-6 text-center">- <div className="flex items-center justify-center gap-2 text-muted-foreground">- <div className="h-4 w-4 border-2 border-primary border-t-transparent rounded-full animate-spin" />- <p className="text-xs sm:text-sm font-medium">- {t("common.loading")}- </p>- </div>- </div>- );+ return <PresetListSkeleton />;}// Show unlock hint if calendar requires password and no password is cached (but not locked)diff --git a/components/shift-stats-skeleton.tsx b/components/shift-stats-skeleton.tsxnew file mode 100644index 0000000..b9bfa3e--- /dev/null+++ b/components/shift-stats-skeleton.tsx@@ -0,0 +1,37 @@+"use client";+import { Skeleton } from "@/components/ui/skeleton";+import { useTranslations } from "next-intl";+import { BarChart3 } from "lucide-react";++export function ShiftStatsSkeleton() {+ const t = useTranslations();++ return (+ <div className="border border-border/50 rounded-xl bg-gradient-to-b from-card/80 via-card/60 to-card/40 backdrop-blur-sm overflow-hidden shadow-lg">+ <div className="px-3 sm:px-4 py-3 sm:py-3.5 flex items-center justify-between">+ <div className="flex items-center gap-2.5">+ <div className="w-9 h-9 rounded-xl bg-gradient-to-br from-primary to-primary/70 flex items-center justify-center shadow-lg shadow-primary/20">+ <BarChart3 className="h-4 w-4 sm:h-5 sm:w-5 text-primary-foreground" />+ </div>+ <h3 className="text-sm sm:text-base font-semibold bg-gradient-to-r from-foreground to-foreground/70 bg-clip-text">+ {t("stats.title")}+ </h3>+ </div>+ </div>++ <div className="border-t border-border/30 bg-muted/20 p-3 sm:p-4 space-y-3">+ <div className="flex items-center justify-center gap-2">+ <Skeleton className="h-9 w-20 rounded-lg" />+ <Skeleton className="h-9 w-20 rounded-lg" />+ <Skeleton className="h-9 w-20 rounded-lg" />+ </div>++ <div className="space-y-2">+ <Skeleton className="h-12 w-full rounded-lg" />+ <Skeleton className="h-12 w-full rounded-lg" />+ <Skeleton className="h-12 w-full rounded-lg" />+ </div>+ </div>+ </div>+ );+}diff --git a/components/shift-stats.tsx b/components/shift-stats.tsxindex 9aec4f4..8b5a9ed 100644--- a/components/shift-stats.tsx+++ b/components/shift-stats.tsx@@ -6,6 +6,7 @@ import { Button } from "@/components/ui/button";import { BarChart3, ChevronDown, ChevronUp } from "lucide-react";import { getCachedPassword } from "@/lib/password-cache";import { formatDuration } from "@/lib/date-utils";+import { Skeleton } from "@/components/ui/skeleton";interface ShiftStats {period: string;@@ -202,9 +203,11 @@ export function ShiftStats({{/* Stats Display */}{loading ? (- <p className="text-sm text-muted-foreground py-6 text-center">- {t("common.loading")}- </p>+ <div className="space-y-3">+ <Skeleton className="h-20 w-full rounded-lg" />+ <Skeleton className="h-16 w-full rounded-lg" />+ <Skeleton className="h-16 w-full rounded-lg" />+ </div>) : stats && Object.keys(stats.stats).length > 0 ? (<div className="space-y-3.5">{/* Total Statistics Card */}diff --git a/components/sync-notification-dialog.tsx b/components/sync-notification-dialog.tsxindex f29b1d3..87ec44a 100644--- a/components/sync-notification-dialog.tsx+++ b/components/sync-notification-dialog.tsx@@ -28,6 +28,7 @@ import {CheckCheck,} from "lucide-react";import { toast } from "sonner";+import { Skeleton } from "@/components/ui/skeleton";interface SyncNotificationDialogProps {open: boolean;@@ -262,8 +263,10 @@ export function SyncNotificationDialog({<div className="space-y-4 overflow-y-auto flex-1 px-6 pb-6">{loading ? (- <div className="text-center py-8 text-muted-foreground">- {t("common.loading")}+ <div className="space-y-4">+ <Skeleton className="h-32 w-full rounded-lg" />+ <Skeleton className="h-32 w-full rounded-lg" />+ <Skeleton className="h-32 w-full rounded-lg" /></div>) : filteredLogs.length === 0 ? (<div className="text-center py-8 text-muted-foreground">diff --git a/components/ui/skeleton.tsx b/components/ui/skeleton.tsxnew file mode 100644index 0000000..5c178be--- /dev/null+++ b/components/ui/skeleton.tsx@@ -0,0 +1,13 @@+import type { HTMLAttributes } from "react";+import { cn } from "@/lib/utils";++function Skeleton({ className, ...props }: HTMLAttributes<HTMLDivElement>) {+ return (+ <div+ className={cn("animate-pulse rounded-md bg-muted", className)}+ {...props}+ />+ );+}++export { Skeleton };diff --git a/hooks/useShifts.ts b/hooks/useShifts.tsindex 0f9c3fe..8b61f33 100644--- a/hooks/useShifts.ts+++ b/hooks/useShifts.ts@@ -8,10 +8,12 @@ import { getCachedPassword } from "@/lib/password-cache";export function useShifts(calendarId: string | undefined) {const t = useTranslations();const [shifts, setShifts] = useState<ShiftWithCalendar[]>([]);+ const [loading, setLoading] = useState(false);const fetchShifts = useCallback(async () => {if (!calendarId) return;+ setLoading(true);try {const password = getCachedPassword(calendarId);const params = new URLSearchParams({ calendarId });@@ -30,6 +32,8 @@ export function useShifts(calendarId: string | undefined) {} catch (error) {console.error("Failed to fetch shifts:", error);setShifts([]);+ } finally {+ setLoading(false);}}, [calendarId]);@@ -172,8 +176,6 @@ export function useShifts(calendarId: string | undefined) {useEffect(() => {if (!calendarId) {- // Data fetching on mount/calendar change is a valid effect use case- // eslint-disable-next-line react-hooks/set-state-in-effectsetShifts([]);return;}@@ -183,6 +185,7 @@ export function useShifts(calendarId: string | undefined) {return {shifts,setShifts,+ loading,createShift,updateShift,deleteShift,