Skip to content

Your favorite shift management application!

feat(view): add personal filter for only assigned shifts (#206)

panteL76476537a754
diff --git a/app/page.tsx b/app/page.tsx
index 575bd26..2782ce2 100644
--- a/app/page.tsx
+++ b/app/page.tsx
@@ -507,6 +507,7 @@ function HomeContent() {
canEditShift={canEditShift}
canDeleteShift={canDeleteShift}
showStampBar={calendarView.showStampBar}
+ onlyMyShifts={calendarView.onlyMyShifts}
canStampPreset={canStampPreset}
canViewStats={canViewStats}
selectedPresetIds={armedPresetIds}
diff --git a/components/calendar-workspace.tsx b/components/calendar-workspace.tsx
index 74b10a0..b34d2af 100644
--- a/components/calendar-workspace.tsx
+++ b/components/calendar-workspace.tsx
@@ -51,6 +51,8 @@ interface CalendarWorkspaceProps {
/** Per-shift own/any precision (deleteOwnShift/deleteAnyShift) for the delete affordance */
canDeleteShift: (shift: ShiftWithCalendar) => boolean;
showStampBar: boolean;
+ /** Personal-only: hides the grid and day view down to shifts the current user is signed up for */
+ onlyMyShifts: boolean;
/** stampPreset OR createShift — mirrors the server's OR check for stamping a preset */
canStampPreset: boolean;
/** viewStats — hides the stats trigger entirely when absent, instead of failing on click */
@@ -86,6 +88,7 @@ export function CalendarWorkspace({
canEditShift,
canDeleteShift,
showStampBar,
+ onlyMyShifts,
canStampPreset,
canViewStats,
selectedPresetIds,
@@ -99,11 +102,17 @@ export function CalendarWorkspace({
const locale = useLocale();
const queryClient = useQueryClient();
const desktop = useMediaQuery(DESKTOP_QUERY, true);
- const { isGuest } = useAuth();
+ const { isGuest, user } = useAuth();
const { isOnline } = useConnectionStatus({ toasts: false });
const [period, setPeriod] = useState<StatsPeriod>("month");
const [statsOpen, setStatsOpen] = useState(false);
+ // Grid and day view only; stats stay on the full list so totals don't look broken
+ const visibleShifts = useMemo(() => {
+ if (!onlyMyShifts || !user) return shifts;
+ return shifts.filter((shift) => shift.signups?.some((s) => s.id === user.id));
+ }, [shifts, onlyMyShifts, user]);
+
// MobileStatsSheet is skip-mounted below when !canViewStats, so a lingering
// `true` here would pop it open unbidden if the capability comes back later.
// Adjusted during render (not an effect) per React's "adjusting state when a
@@ -114,7 +123,7 @@ export function CalendarWorkspace({
if (!canViewStats) setStatsOpen(false);
}
- const dayData = useDayData({ selectedDay, shifts, notes });
+ const dayData = useDayData({ selectedDay, shifts: visibleShifts, notes });
const monthSummary = usePeriodSummary({
calendarId: canViewStats ? calendarId : undefined,
anchorDate: currentDate,
@@ -180,7 +189,7 @@ export function CalendarWorkspace({
calendarDays={calendarDays}
currentDate={currentDate}
selectedDay={selectedDay}
- shifts={shifts}
+ shifts={visibleShifts}
notes={notes}
externalSyncs={externalSyncs}
togglingDates={togglingDates}
diff --git a/components/view-settings-sheet.tsx b/components/view-settings-sheet.tsx
index 78c3c37..aba9508 100644
--- a/components/view-settings-sheet.tsx
+++ b/components/view-settings-sheet.tsx
@@ -94,12 +94,20 @@ function ViewFields({
onChange,
disabled = false,
stampBar,
+ onlyMyShifts,
}: {
value: CalendarViewSettings;
onChange: (patch: Partial<CalendarViewSettings>) => void;
disabled?: boolean;
/** Only the personal view carries the stamp-bar toggle */
stampBar?: { checked: boolean; onChange: (checked: boolean) => void };
+ /** Only the personal view carries this, and only for signed-in accounts */
+ onlyMyShifts?: {
+ checked: boolean;
+ onChange: (checked: boolean) => void;
+ /** The selected calendar has signups turned off, so the filter would show nothing */
+ signupsDisabled?: boolean;
+ };
}) {
const t = useTranslations();
const id = useId();
@@ -168,6 +176,21 @@ function ViewFields({
disabled={disabled}
/>
)}
+ {onlyMyShifts && (
+ <>
+ <ToggleRow
+ id={`${id}-only-mine`}
+ title={t("view.onlyMyShifts")}
+ description={t("view.onlyMyShiftsHint")}
+ checked={onlyMyShifts.checked}
+ onCheckedChange={onlyMyShifts.onChange}
+ disabled={disabled}
+ />
+ {onlyMyShifts.checked && onlyMyShifts.signupsDisabled && (
+ <InfoNote icon={Info}>{t("view.onlyMyShiftsSignupsDisabledHint")}</InfoNote>
+ )}
+ </>
+ )}
</section>
<section className="flex flex-col gap-3 border-t border-line pt-5">
@@ -410,7 +433,7 @@ export function PersonalViewPanel({
const t = useTranslations();
const { calendars } = useCalendars();
const calendar = calendarId ? calendars.find((c) => c.id === calendarId) : undefined;
- const { personal, updatePersonal } = settings;
+ const { personal, updatePersonal, storedInAccount } = settings;
return (
<PanelBody>
@@ -427,6 +450,15 @@ export function PersonalViewPanel({
checked: personal.showStampBar,
onChange: (showStampBar) => updatePersonal({ showStampBar }),
}}
+ onlyMyShifts={
+ storedInAccount
+ ? {
+ checked: personal.onlyMyShifts,
+ onChange: (onlyMyShifts) => updatePersonal({ onlyMyShifts }),
+ signupsDisabled: calendar ? calendar.signupsEnabled === false : false,
+ }
+ : undefined
+ }
/>
</div>
</PanelBody>
diff --git a/lib/view-settings.ts b/lib/view-settings.ts
index af1e4b9..5844ae8 100644
--- a/lib/view-settings.ts
+++ b/lib/view-settings.ts
@@ -15,9 +15,10 @@ export interface CalendarViewSettings {
highlightColor: string;
}
-/** A user's own view; the stamp bar is never taken over by a calendar. */
+/** A user's own view; the stamp bar and the own-shifts filter are never taken over by a calendar. */
export interface PersonalViewSettings extends CalendarViewSettings {
showStampBar: boolean;
+ onlyMyShifts: boolean;
}
export const SHIFTS_PER_DAY_MAX = 3;
@@ -44,6 +45,7 @@ export const DEFAULT_CALENDAR_VIEW_SETTINGS: CalendarViewSettings = {
export const DEFAULT_PERSONAL_VIEW_SETTINGS: PersonalViewSettings = {
...DEFAULT_CALENDAR_VIEW_SETTINGS,
showStampBar: true,
+ onlyMyShifts: false,
};
function isRecord(value: unknown): value is Record<string, unknown> {
@@ -102,6 +104,7 @@ export function sanitizePersonalViewSettings(input: unknown): PersonalViewSettin
return {
...sanitizeCalendarViewSettings(src),
showStampBar: sanitizeBoolean(src.showStampBar, DEFAULT_PERSONAL_VIEW_SETTINGS.showStampBar),
+ onlyMyShifts: sanitizeBoolean(src.onlyMyShifts, DEFAULT_PERSONAL_VIEW_SETTINGS.onlyMyShifts),
};
}
@@ -121,5 +124,9 @@ export function resolveViewSettings(
calendarView: unknown
): PersonalViewSettings {
if (!isRecord(calendarView)) return personal;
- return { ...sanitizeCalendarViewSettings(calendarView), showStampBar: personal.showStampBar };
+ return {
+ ...sanitizeCalendarViewSettings(calendarView),
+ showStampBar: personal.showStampBar,
+ onlyMyShifts: personal.onlyMyShifts,
+ };
}
diff --git a/messages/cs.json b/messages/cs.json
index ff81e7e..dc259ec 100644
--- a/messages/cs.json
+++ b/messages/cs.json
@@ -246,6 +246,9 @@
"density": "Hustota",
"showPresetBar": "Zobrazit lištu šablon",
"showPresetBarHint": "Lišta šablon pod nebo nad kalendářem",
+ "onlyMyShifts": "Jen moje směny",
+ "onlyMyShiftsHint": "V kalendáři a denním zobrazení ukáže jen směny, na které jste přiřazeni",
+ "onlyMyShiftsSignupsDisabledHint": "Přiřazení jsou pro tento kalendář vypnutá, proto zůstane prázdný.",
"settingsDescriptionLocal": "Vaše osobní zobrazení na tomto zařízení. Platí pro všechny kalendáře bez vlastního zobrazení.",
"overriddenByCalendar": "„{calendar}“ má vlastní zobrazení. Vaše osobní zobrazení tam neplatí.",
"calendarOwn": "Vlastní zobrazení pro tento kalendář",
diff --git a/messages/de.json b/messages/de.json
index 8c2de78..d4c98be 100644
--- a/messages/de.json
+++ b/messages/de.json
@@ -246,6 +246,9 @@
"density": "Dichte",
"showPresetBar": "Vorlagenleiste anzeigen",
"showPresetBarHint": "Vorlagenleiste unter bzw. über dem Kalender",
+ "onlyMyShifts": "Nur meine Schichten",
+ "onlyMyShiftsHint": "Zeigt im Kalender und in der Tagesansicht nur Schichten, denen du zugewiesen bist",
+ "onlyMyShiftsSignupsDisabledHint": "Für diesen Kalender sind Zuweisungen deaktiviert, daher bleibt der Kalender leer.",
"settingsDescriptionLocal": "Deine persönliche Ansicht auf diesem Gerät. Gilt für alle Kalender ohne eigene Ansicht.",
"overriddenByCalendar": "„{calendar}“ hat eine eigene Ansicht. Dort gilt deine persönliche Ansicht nicht.",
"calendarOwn": "Eigene Ansicht für diesen Kalender",
diff --git a/messages/en.json b/messages/en.json
index 598726d..780ca67 100644
--- a/messages/en.json
+++ b/messages/en.json
@@ -246,6 +246,9 @@
"density": "Density",
"showPresetBar": "Show preset bar",
"showPresetBarHint": "Preset bar below or above the calendar",
+ "onlyMyShifts": "Only my shifts",
+ "onlyMyShiftsHint": "Shows only shifts you're assigned to in the calendar and day view",
+ "onlyMyShiftsSignupsDisabledHint": "Assignments are turned off for this calendar, so the calendar stays empty.",
"settingsDescriptionLocal": "Your personal view on this device. Applies to all calendars without their own view.",
"overriddenByCalendar": "“{calendar}” has its own view. Your personal view does not apply there.",
"calendarOwn": "Own view for this calendar",
diff --git a/messages/es.json b/messages/es.json
index 1c08884..ede5baf 100644
--- a/messages/es.json
+++ b/messages/es.json
@@ -246,6 +246,9 @@
"density": "Densidad",
"showPresetBar": "Mostrar barra de plantillas",
"showPresetBarHint": "Barra de plantillas debajo o encima del calendario",
+ "onlyMyShifts": "Solo mis turnos",
+ "onlyMyShiftsHint": "Muestra en el calendario y la vista diaria solo los turnos asignados a ti",
+ "onlyMyShiftsSignupsDisabledHint": "Las asignaciones están desactivadas para este calendario, por lo que quedará vacío.",
"settingsDescriptionLocal": "Tu vista personal en este dispositivo. Se aplica a todos los calendarios sin vista propia.",
"overriddenByCalendar": "«{calendar}» tiene su propia vista. Allí no se aplica tu vista personal.",
"calendarOwn": "Vista propia para este calendario",
diff --git a/messages/fr.json b/messages/fr.json
index 2c626d4..ed8ea0c 100755
--- a/messages/fr.json
+++ b/messages/fr.json
@@ -246,6 +246,9 @@
"density": "Densité",
"showPresetBar": "Afficher la barre de modèles",
"showPresetBarHint": "Barre de modèles sous ou au-dessus du calendrier",
+ "onlyMyShifts": "Seulement mes créneaux",
+ "onlyMyShiftsHint": "N'affiche dans le calendrier et la vue journalière que les créneaux qui vous sont attribués",
+ "onlyMyShiftsSignupsDisabledHint": "Les attributions sont désactivées pour ce calendrier, il restera donc vide.",
"settingsDescriptionLocal": "Votre affichage personnel sur cet appareil. Il s’applique à tous les calendriers sans affichage propre.",
"overriddenByCalendar": "« {calendar} » a son propre affichage. Votre affichage personnel ne s’y applique pas.",
"calendarOwn": "Affichage propre à ce calendrier",
diff --git a/messages/it.json b/messages/it.json
index 2b0087f..5e74edd 100644
--- a/messages/it.json
+++ b/messages/it.json
@@ -246,6 +246,9 @@
"density": "Densità",
"showPresetBar": "Mostra barra dei modelli",
"showPresetBarHint": "Barra dei modelli sotto o sopra il calendario",
+ "onlyMyShifts": "Solo i miei turni",
+ "onlyMyShiftsHint": "Mostra nel calendario e nella vista giornaliera solo i turni a te assegnati",
+ "onlyMyShiftsSignupsDisabledHint": "Le assegnazioni sono disattivate per questo calendario, quindi rimarrà vuoto.",
"settingsDescriptionLocal": "La tua vista personale su questo dispositivo. Vale per tutti i calendari senza una vista propria.",
"overriddenByCalendar": "«{calendar}» ha una vista propria. Lì la tua vista personale non vale.",
"calendarOwn": "Vista propria per questo calendario",