Your favorite shift management application!
feat: Add drag-and-drop reordering for shift presets (#79)
panteL9cc8eb1bd1e8
diff --git a/app/api/presets/reorder/route.ts b/app/api/presets/reorder/route.tsnew file mode 100644index 0000000..b49ce30--- /dev/null+++ b/app/api/presets/reorder/route.ts@@ -0,0 +1,108 @@+import { NextRequest, NextResponse } from "next/server";+import { db } from "@/lib/db";+import { shiftPresets, calendars } from "@/lib/db/schema";+import { eq } from "drizzle-orm";+import { verifyPassword } from "@/lib/password-utils";+import { eventEmitter, CalendarChangeEvent } from "@/lib/event-emitter";++// PATCH reorder presets+export async function PATCH(request: NextRequest) {+ try {+ const body = await request.json();+ const { calendarId, presetOrders, password } = body;++ if (!calendarId || !presetOrders || !Array.isArray(presetOrders)) {+ return NextResponse.json(+ { error: "Missing required fields" },+ { status: 400 }+ );+ }++ // Validate presetOrders contents+ const isValidPresetOrders = presetOrders.every(+ (item) =>+ item &&+ typeof item === "object" &&+ typeof item.id === "string" &&+ typeof item.order === "number" &&+ Number.isFinite(item.order)+ );+ if (!isValidPresetOrders) {+ return NextResponse.json(+ { error: "Invalid presetOrders format" },+ { status: 400 }+ );+ }++ // Fetch calendar to check password+ const [calendar] = await db+ .select()+ .from(calendars)+ .where(eq(calendars.id, calendarId));++ if (!calendar) {+ return NextResponse.json(+ { error: "Calendar not found" },+ { status: 404 }+ );+ }++ // Verify password if calendar is protected+ if (calendar.passwordHash) {+ if (!password || !verifyPassword(password, calendar.passwordHash)) {+ return NextResponse.json(+ { error: "Invalid password" },+ { status: 401 }+ );+ }+ }++ // Verify all preset IDs belong to the specified calendarId+ const presetIds = presetOrders.map(+ (p: { id: string; order: number }) => p.id+ );+ const existingPresets = await db+ .select({ id: shiftPresets.id })+ .from(shiftPresets)+ .where(eq(shiftPresets.calendarId, calendarId));++ const existingPresetIds = new Set(existingPresets.map((p) => p.id));+ const invalidIds = presetIds.filter(+ (id: string) => !existingPresetIds.has(id)+ );++ if (invalidIds.length > 0) {+ return NextResponse.json(+ { error: "Invalid preset IDs for this calendar" },+ { status: 403 }+ );+ }++ // Update order for each preset atomically in a transaction+ // presetOrders format: [{ id: string, order: number }]+ const updatePromises = presetOrders.map(+ ({ id, order }: { id: string; order: number }) =>+ db+ .update(shiftPresets)+ .set({ order, updatedAt: new Date() })+ .where(eq(shiftPresets.id, id))+ );+ await Promise.all(updatePromises);++ // Emit event for SSE+ eventEmitter.emit("calendar-change", {+ type: "preset",+ action: "reorder",+ calendarId,+ data: { presetOrders },+ } as CalendarChangeEvent);++ return NextResponse.json({ success: true });+ } catch (error) {+ console.error("Error reordering presets:", error);+ return NextResponse.json(+ { error: "Failed to reorder presets" },+ { status: 500 }+ );+ }+}diff --git a/app/api/presets/route.ts b/app/api/presets/route.tsindex cfab8c1..79a51e2 100644--- a/app/api/presets/route.ts+++ b/app/api/presets/route.ts@@ -1,7 +1,7 @@import { NextRequest, NextResponse } from "next/server";import { db } from "@/lib/db";import { shiftPresets, calendars } from "@/lib/db/schema";-import { eq } from "drizzle-orm";+import { eq, asc } from "drizzle-orm";import { verifyPassword } from "@/lib/password-utils";import { eventEmitter, CalendarChangeEvent } from "@/lib/event-emitter";@@ -46,7 +46,8 @@ export async function GET(request: NextRequest) {const presets = await db.select().from(shiftPresets)- .where(eq(shiftPresets.calendarId, calendarId));+ .where(eq(shiftPresets.calendarId, calendarId))+ .orderBy(asc(shiftPresets.order));return NextResponse.json(presets);} catch (error) {console.error("Error fetching presets:", error);@@ -104,6 +105,17 @@ export async function POST(request: NextRequest) {}}+ // Get the max order value for this calendar to append new preset at the end+ const existingPresets = await db+ .select()+ .from(shiftPresets)+ .where(eq(shiftPresets.calendarId, calendarId));++ const maxOrder =+ existingPresets.length > 0+ ? Math.max(...existingPresets.map((p) => p.order || 0))+ : -1;+const [preset] = await db.insert(shiftPresets).values({@@ -116,6 +128,7 @@ export async function POST(request: NextRequest) {isSecondary: isSecondary || false,isAllDay: isAllDay || false,hideFromStats: hideFromStats || false,+ order: maxOrder + 1,}).returning();diff --git a/components/preset-list.tsx b/components/preset-list.tsxindex b684328..6d9b772 100644--- a/components/preset-list.tsx+++ b/components/preset-list.tsx@@ -1,3 +1,4 @@+import React from "react";import { motion } from "motion/react";import { useTranslations } from "next-intl";import { Button } from "@/components/ui/button";@@ -9,6 +10,7 @@ import {ChevronDown,ChevronUp,} from "lucide-react";+import { ShiftPreset } from "@/lib/db/schema";import { CalendarWithCount } from "@/lib/types";import { getCachedPassword } from "@/lib/password-cache";@@ -45,6 +47,9 @@ export function PresetList({const t = useTranslations();const [showSecondary, setShowSecondary] = React.useState(false);+ const primaryPresets = presets.filter((p) => !p.isSecondary);+ const secondaryPresets = presets.filter((p) => p.isSecondary);+// Hide preset buttons if calendar requires password AND no valid password is cachedconst selectedCalendar = calendars.find((c) => c.id === calendarId);const requiresPassword = !!selectedCalendar?.passwordHash;@@ -53,9 +58,6 @@ export function PresetList({const shouldHidePresetButtons = requiresPassword && !hasPassword;const shouldShowUnlockHint = shouldHidePresetButtons && !isLocked;- const primaryPresets = presets.filter((p) => !p.isSecondary);- const secondaryPresets = presets.filter((p) => p.isSecondary);-// Show loading state while fetchingif (loading) {return <PresetListSkeleton hidePresetHeader={hidePresetHeader} />;@@ -338,5 +340,3 @@ function PresetButton({</motion.div>);}--import React from "react";diff --git a/components/preset-manage-dialog.tsx b/components/preset-manage-dialog.tsxindex 4f897fd..6d6a539 100644--- a/components/preset-manage-dialog.tsx+++ b/components/preset-manage-dialog.tsx@@ -1,8 +1,25 @@"use client";-import { useState, useEffect, useCallback, useRef } from "react";+import { useState, useEffect, useCallback, useRef, memo } from "react";import { useTranslations } from "next-intl";import { motion } from "motion/react";+import {+ DndContext,+ closestCenter,+ KeyboardSensor,+ PointerSensor,+ useSensor,+ useSensors,+ DragEndEvent,+} from "@dnd-kit/core";+import {+ arrayMove,+ SortableContext,+ sortableKeyboardCoordinates,+ useSortable,+ verticalListSortingStrategy,+} from "@dnd-kit/sortable";+import { CSS } from "@dnd-kit/utilities";import {Dialog,DialogContent,@@ -17,7 +34,7 @@ import { Checkbox } from "@/components/ui/checkbox";import { ColorPicker } from "@/components/ui/color-picker";import { ShiftPreset } from "@/lib/db/schema";import { PRESET_COLORS } from "@/lib/constants";-import { Plus, Trash2, Edit2, Loader2 } from "lucide-react";+import { Plus, Trash2, Edit2, Loader2, GripVertical } from "lucide-react";import { toast } from "sonner";import { getCachedPassword } from "@/lib/password-cache";@@ -40,6 +57,116 @@ interface PresetManageDialogProps {onPresetsChange: () => void;}+// Sortable preset item component+interface SortablePresetItemProps {+ preset: ShiftPreset;+ isDeleting: boolean;+ onEdit: (preset: ShiftPreset) => void;+ onDelete: (id: string) => void;+ t: (key: string) => string;+ showDragHandle?: boolean;+}++const SortablePresetItem = memo(function SortablePresetItem({+ preset,+ isDeleting,+ onEdit,+ onDelete,+ t,+ showDragHandle = true,+}: SortablePresetItemProps) {+ const {+ attributes,+ listeners,+ setNodeRef,+ transform,+ transition,+ isDragging,+ } = useSortable({ id: preset.id });++ const style = {+ transform: CSS.Transform.toString(transform),+ transition: isDragging ? undefined : transition, // Disable transition during drag for smoother performance+ opacity: isDragging ? 0.5 : 1,+ zIndex: isDragging ? 1 : 0,+ };++ return (+ <div+ ref={setNodeRef}+ style={style}+ className="flex flex-col gap-3 p-4 rounded-xl border border-border/50 bg-muted/20 transition-colors"+ {...attributes}+ >+ <div className="flex items-start gap-2">+ {showDragHandle && (+ <button+ className="cursor-grab active:cursor-grabbing p-1 hover:bg-muted/50 rounded transition-colors shrink-0"+ {...listeners}+ >+ <GripVertical className="h-4 w-4 text-muted-foreground" />+ </button>+ )}+ <div+ className="w-1 h-4 rounded-full shrink-0 mt-0.5"+ style={{ backgroundColor: preset.color }}+ />+ <span className="font-semibold flex-1 min-w-0 break-words">+ {preset.title}+ </span>+ </div>++ <div className="flex flex-col sm:flex-row sm:items-center gap-3 sm:justify-between pl-7">+ <div className="flex flex-wrap items-center gap-2">+ <span className="text-sm text-muted-foreground">+ {preset.isAllDay ? (+ t("shift.allDay")+ ) : (+ <>+ {preset.startTime} - {preset.endTime}+ </>+ )}+ </span>+ {preset.isSecondary && (+ <span className="text-xs px-2 py-0.5 rounded-full bg-amber-500/10 text-amber-600 dark:text-amber-400 border border-amber-500/20 font-medium">+ {t("preset.secondary")}+ </span>+ )}+ {preset.hideFromStats && (+ <span className="text-xs px-2 py-0.5 rounded-full bg-gray-500/10 text-gray-600 dark:text-gray-400 border border-gray-500/20 font-medium">+ {t("preset.hiddenFromStats")}+ </span>+ )}+ </div>+ <div className="flex gap-1 shrink-0">+ <Button+ size="icon"+ variant="ghost"+ className="h-8 w-8"+ onClick={() => onEdit(preset)}+ disabled={isDeleting}+ >+ <Edit2 className="h-4 w-4" />+ </Button>+ <Button+ size="icon"+ variant="ghost"+ className="h-8 w-8 text-destructive hover:text-destructive hover:bg-destructive/10"+ onClick={() => onDelete(preset.id)}+ disabled={isDeleting}+ >+ {isDeleting ? (+ <Loader2 className="h-4 w-4 animate-spin" />+ ) : (+ <Trash2 className="h-4 w-4" />+ )}+ </Button>+ </div>+ </div>+ </div>+ );+});+export function PresetManageDialog({open,onOpenChange,@@ -52,6 +179,30 @@ export function PresetManageDialog({const [isDeleting, setIsDeleting] = useState<string | null>(null);const [showAddForm, setShowAddForm] = useState(false);const [editingPreset, setEditingPreset] = useState<ShiftPreset | null>(null);+ const [orderedPrimaryPresets, setOrderedPrimaryPresets] = useState<+ ShiftPreset[]+ >([]);+ const [orderedSecondaryPresets, setOrderedSecondaryPresets] = useState<+ ShiftPreset[]+ >([]);++ // Update local ordered presets when presets prop changes+ useEffect(() => {+ setOrderedPrimaryPresets(presets.filter((p) => !p.isSecondary));+ setOrderedSecondaryPresets(presets.filter((p) => p.isSecondary));+ }, [presets]);++ // Drag and drop sensors with activation constraint to prevent accidental drags+ const sensors = useSensors(+ useSensor(PointerSensor, {+ activationConstraint: {+ distance: 8, // Require 8px movement before drag starts+ },+ }),+ useSensor(KeyboardSensor, {+ coordinateGetter: sortableKeyboardCoordinates,+ })+ );// Form stateconst [formData, setFormData] = useState<PresetFormData>({@@ -69,6 +220,90 @@ export function PresetManageDialog({const initialFormDataRef = useRef<PresetFormData | null>(null);const isInitialMount = useRef(true);+ // Handle drag end for primary presets+ const handlePrimaryDragEnd = async (event: DragEndEvent) => {+ const { active, over } = event;++ if (!over || active.id === over.id) {+ return;+ }++ const oldIndex = orderedPrimaryPresets.findIndex((p) => p.id === active.id);+ const newIndex = orderedPrimaryPresets.findIndex((p) => p.id === over.id);++ const newOrderedPrimary = arrayMove(+ orderedPrimaryPresets,+ oldIndex,+ newIndex+ );+ setOrderedPrimaryPresets(newOrderedPrimary);++ // Save new order to backend+ await savePresetOrder([...newOrderedPrimary, ...orderedSecondaryPresets]);+ };++ // Handle drag end for secondary presets+ const handleSecondaryDragEnd = async (event: DragEndEvent) => {+ const { active, over } = event;++ if (!over || active.id === over.id) {+ return;+ }++ const oldIndex = orderedSecondaryPresets.findIndex(+ (p) => p.id === active.id+ );+ const newIndex = orderedSecondaryPresets.findIndex((p) => p.id === over.id);++ const newOrderedSecondary = arrayMove(+ orderedSecondaryPresets,+ oldIndex,+ newIndex+ );+ setOrderedSecondaryPresets(newOrderedSecondary);++ // Save new order to backend+ await savePresetOrder([...orderedPrimaryPresets, ...newOrderedSecondary]);+ };++ const savePresetOrder = async (allPresets: ShiftPreset[]) => {+ try {+ const password = getCachedPassword(calendarId);+ const presetOrders = allPresets.map((preset, index) => ({+ id: preset.id,+ order: index,+ }));++ const response = await fetch("/api/presets/reorder", {+ method: "PATCH",+ headers: { "Content-Type": "application/json" },+ body: JSON.stringify({+ calendarId,+ presetOrders,+ password,+ }),+ });++ if (response.ok) {+ onPresetsChange();+ } else {+ const data = await response.json();+ toast.error(+ data.error || t("common.updateError", { item: t("preset.preset") })+ );+ // Revert order on error+ setOrderedPrimaryPresets(presets.filter((p) => !p.isSecondary));+ setOrderedSecondaryPresets(presets.filter((p) => p.isSecondary));+ }+ } catch (error) {+ console.error("Failed to reorder presets:", error);+ toast.error(t("common.updateError", { item: t("preset.preset") }));+ // Revert order on error+ setOrderedPrimaryPresets(presets.filter((p) => !p.isSecondary));+ setOrderedSecondaryPresets(presets.filter((p) => p.isSecondary));+ }+ };+// Reset state when dialog closesuseEffect(() => {if (!open) {@@ -345,83 +580,87 @@ export function PresetManageDialog({</DialogHeader><div className="space-y-3 overflow-y-auto flex-1 p-6">- {/* Existing Presets List - hide when adding new preset, show only edited preset when editing */}- {presets.length > 0 && !showAddForm && (- <div className="space-y-3">- {presets- .filter(- (preset) => !editingPreset || preset.id === editingPreset.id- )- .map((preset) => (- <div- key={preset.id}- className="flex flex-col gap-3 p-4 rounded-xl border border-border/50 bg-muted/20 hover:bg-muted/30 transition-all"- style={{- borderLeftColor: preset.color,- borderLeftWidth: 4,- }}+ {/* Primary Presets List */}+ {orderedPrimaryPresets.length > 0 &&+ !showAddForm &&+ !editingPreset && (+ <div className="space-y-2">+ <h3 className="text-sm font-medium text-muted-foreground px-1">+ {t("preset.primaryPresets")}+ </h3>+ <DndContext+ sensors={sensors}+ collisionDetection={closestCenter}+ onDragEnd={handlePrimaryDragEnd}+ >+ <SortableContext+ items={orderedPrimaryPresets.map((p) => p.id)}+ strategy={verticalListSortingStrategy}>- {/* Title row */}- <div className="flex items-start gap-2">- <div- className="w-1 h-4 rounded-full shrink-0 mt-0.5"- style={{ backgroundColor: preset.color }}- />- <span className="font-semibold flex-1 min-w-0 break-words">- {preset.title}- </span>+ <div className="space-y-3">+ {orderedPrimaryPresets.map((preset) => (+ <SortablePresetItem+ key={preset.id}+ preset={preset}+ isDeleting={isDeleting === preset.id}+ onEdit={startEdit}+ onDelete={handleDelete}+ t={t}+ showDragHandle={orderedPrimaryPresets.length > 1}+ />+ ))}</div>-- {/* Info and buttons row */}- <div className="flex flex-col sm:flex-row sm:items-center gap-3 sm:justify-between">- <div className="flex flex-wrap items-center gap-2">- <span className="text-sm text-muted-foreground">- {preset.isAllDay ? (- t("shift.allDay")- ) : (- <>- {preset.startTime} - {preset.endTime}- </>- )}- </span>- {preset.isSecondary && (- <span className="text-xs px-2 py-0.5 rounded-full bg-amber-500/10 text-amber-600 dark:text-amber-400 border border-amber-500/20 font-medium">- {t("preset.secondary")}- </span>- )}- {preset.hideFromStats && (- <span className="text-xs px-2 py-0.5 rounded-full bg-gray-500/10 text-gray-600 dark:text-gray-400 border border-gray-500/20 font-medium">- {t("preset.hiddenFromStats")}- </span>- )}- </div>- <div className="flex gap-1 shrink-0">- <Button- size="icon"- variant="ghost"- className="h-8 w-8"- onClick={() => startEdit(preset)}- disabled={!!isDeleting}- >- <Edit2 className="h-4 w-4" />- </Button>- <Button- size="icon"- variant="ghost"- className="h-8 w-8 text-destructive hover:text-destructive hover:bg-destructive/10"- onClick={() => handleDelete(preset.id)}- disabled={!!isDeleting}- >- {isDeleting === preset.id ? (- <Loader2 className="h-4 w-4 animate-spin" />- ) : (- <Trash2 className="h-4 w-4" />- )}- </Button>- </div>+ </SortableContext>+ </DndContext>+ </div>+ )}++ {/* Secondary Presets List */}+ {orderedSecondaryPresets.length > 0 &&+ !showAddForm &&+ !editingPreset && (+ <div className="space-y-2">+ <h3 className="text-sm font-medium text-muted-foreground px-1">+ {t("preset.secondaryPresets")}+ </h3>+ <DndContext+ sensors={sensors}+ collisionDetection={closestCenter}+ onDragEnd={handleSecondaryDragEnd}+ >+ <SortableContext+ items={orderedSecondaryPresets.map((p) => p.id)}+ strategy={verticalListSortingStrategy}+ >+ <div className="space-y-3">+ {orderedSecondaryPresets.map((preset) => (+ <SortablePresetItem+ key={preset.id}+ preset={preset}+ isDeleting={isDeleting === preset.id}+ onEdit={startEdit}+ onDelete={handleDelete}+ t={t}+ showDragHandle={orderedSecondaryPresets.length > 1}+ />+ ))}</div>- </div>- ))}+ </SortableContext>+ </DndContext>+ </div>+ )}++ {/* Show edited preset */}+ {editingPreset && (+ <div className="space-y-3">+ <SortablePresetItem+ preset={editingPreset}+ isDeleting={isDeleting === editingPreset.id}+ onEdit={startEdit}+ onDelete={handleDelete}+ t={t}+ showDragHandle={false}+ /></div>)}diff --git a/drizzle/0011_loose_bloodaxe.sql b/drizzle/0011_loose_bloodaxe.sqlnew file mode 100644index 0000000..a6ef8ea--- /dev/null+++ b/drizzle/0011_loose_bloodaxe.sql@@ -0,0 +1 @@+ALTER TABLE `shift_presets` ADD `order` integer DEFAULT 0 NOT NULL;\ No newline at end of filediff --git a/drizzle/meta/0011_snapshot.json b/drizzle/meta/0011_snapshot.jsonnew file mode 100644index 0000000..c9aff2f--- /dev/null+++ b/drizzle/meta/0011_snapshot.json@@ -0,0 +1,697 @@+{+ "version": "6",+ "dialect": "sqlite",+ "id": "14b7ff8f-884d-4bbf-b0d8-fe65ea2750ae",+ "prevId": "bdcccdcf-d9b5-4906-88d7-3d6012bdbfef",+ "tables": {+ "calendar_notes": {+ "name": "calendar_notes",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "calendar_id": {+ "name": "calendar_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "date": {+ "name": "date",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "note": {+ "name": "note",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "CURRENT_TIMESTAMP"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "CURRENT_TIMESTAMP"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "calendar_notes_calendar_id_calendars_id_fk": {+ "name": "calendar_notes_calendar_id_calendars_id_fk",+ "tableFrom": "calendar_notes",+ "tableTo": "calendars",+ "columnsFrom": [+ "calendar_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "calendars": {+ "name": "calendars",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "color": {+ "name": "color",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'#3b82f6'"+ },+ "password_hash": {+ "name": "password_hash",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "is_locked": {+ "name": "is_locked",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "CURRENT_TIMESTAMP"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "CURRENT_TIMESTAMP"+ }+ },+ "indexes": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "external_syncs": {+ "name": "external_syncs",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "calendar_id": {+ "name": "calendar_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "sync_type": {+ "name": "sync_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'icloud'"+ },+ "calendar_url": {+ "name": "calendar_url",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "color": {+ "name": "color",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'#3b82f6'"+ },+ "display_mode": {+ "name": "display_mode",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'normal'"+ },+ "is_hidden": {+ "name": "is_hidden",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": false+ },+ "hide_from_stats": {+ "name": "hide_from_stats",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": false+ },+ "auto_sync_interval": {+ "name": "auto_sync_interval",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": 0+ },+ "is_one_time_import": {+ "name": "is_one_time_import",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": false+ },+ "last_synced_at": {+ "name": "last_synced_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "CURRENT_TIMESTAMP"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "CURRENT_TIMESTAMP"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "external_syncs_calendar_id_calendars_id_fk": {+ "name": "external_syncs_calendar_id_calendars_id_fk",+ "tableFrom": "external_syncs",+ "tableTo": "calendars",+ "columnsFrom": [+ "calendar_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "shift_presets": {+ "name": "shift_presets",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "calendar_id": {+ "name": "calendar_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "start_time": {+ "name": "start_time",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "end_time": {+ "name": "end_time",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "color": {+ "name": "color",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'#3b82f6'"+ },+ "notes": {+ "name": "notes",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "is_secondary": {+ "name": "is_secondary",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": false+ },+ "is_all_day": {+ "name": "is_all_day",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": false+ },+ "hide_from_stats": {+ "name": "hide_from_stats",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": false+ },+ "order": {+ "name": "order",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": 0+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "CURRENT_TIMESTAMP"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "CURRENT_TIMESTAMP"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "shift_presets_calendar_id_calendars_id_fk": {+ "name": "shift_presets_calendar_id_calendars_id_fk",+ "tableFrom": "shift_presets",+ "tableTo": "calendars",+ "columnsFrom": [+ "calendar_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "shifts": {+ "name": "shifts",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "calendar_id": {+ "name": "calendar_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "preset_id": {+ "name": "preset_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "date": {+ "name": "date",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "start_time": {+ "name": "start_time",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "end_time": {+ "name": "end_time",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "color": {+ "name": "color",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'#3b82f6'"+ },+ "notes": {+ "name": "notes",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "is_all_day": {+ "name": "is_all_day",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": false+ },+ "is_secondary": {+ "name": "is_secondary",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": false+ },+ "external_event_id": {+ "name": "external_event_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "external_sync_id": {+ "name": "external_sync_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "synced_from_external": {+ "name": "synced_from_external",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "CURRENT_TIMESTAMP"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "CURRENT_TIMESTAMP"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "shifts_calendar_id_calendars_id_fk": {+ "name": "shifts_calendar_id_calendars_id_fk",+ "tableFrom": "shifts",+ "tableTo": "calendars",+ "columnsFrom": [+ "calendar_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "shifts_preset_id_shift_presets_id_fk": {+ "name": "shifts_preset_id_shift_presets_id_fk",+ "tableFrom": "shifts",+ "tableTo": "shift_presets",+ "columnsFrom": [+ "preset_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "shifts_external_sync_id_external_syncs_id_fk": {+ "name": "shifts_external_sync_id_external_syncs_id_fk",+ "tableFrom": "shifts",+ "tableTo": "external_syncs",+ "columnsFrom": [+ "external_sync_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "sync_logs": {+ "name": "sync_logs",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "calendar_id": {+ "name": "calendar_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "external_sync_id": {+ "name": "external_sync_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "external_sync_name": {+ "name": "external_sync_name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "error_message": {+ "name": "error_message",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "shifts_created": {+ "name": "shifts_created",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": 0+ },+ "shifts_updated": {+ "name": "shifts_updated",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": 0+ },+ "shifts_deleted": {+ "name": "shifts_deleted",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": 0+ },+ "sync_type": {+ "name": "sync_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'auto'"+ },+ "is_read": {+ "name": "is_read",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": false+ },+ "synced_at": {+ "name": "synced_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "CURRENT_TIMESTAMP"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "sync_logs_calendar_id_calendars_id_fk": {+ "name": "sync_logs_calendar_id_calendars_id_fk",+ "tableFrom": "sync_logs",+ "tableTo": "calendars",+ "columnsFrom": [+ "calendar_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "sync_logs_external_sync_id_external_syncs_id_fk": {+ "name": "sync_logs_external_sync_id_external_syncs_id_fk",+ "tableFrom": "sync_logs",+ "tableTo": "external_syncs",+ "columnsFrom": [+ "external_sync_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ }+ },+ "views": {},+ "enums": {},+ "_meta": {+ "schemas": {},+ "tables": {},+ "columns": {}+ },+ "internal": {+ "indexes": {}+ }+}\ No newline at end of filediff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.jsonindex 82610bc..776afde 100644--- a/drizzle/meta/_journal.json+++ b/drizzle/meta/_journal.json@@ -78,6 +78,13 @@"when": 1765059800909,"tag": "0010_unusual_paibok","breakpoints": true+ },+ {+ "idx": 11,+ "version": "6",+ "when": 1765917907080,+ "tag": "0011_loose_bloodaxe",+ "breakpoints": true}]}\ No newline at end of filediff --git a/lib/db/schema.ts b/lib/db/schema.tsindex eb287c1..7771d84 100644--- a/lib/db/schema.ts+++ b/lib/db/schema.ts@@ -100,6 +100,7 @@ export const shiftPresets = sqliteTable("shift_presets", {hideFromStats: integer("hide_from_stats", { mode: "boolean" }).notNull().default(false),+ order: integer("order").notNull().default(0),createdAt: integer("created_at", { mode: "timestamp" }).notNull().default(sql`CURRENT_TIMESTAMP`),diff --git a/lib/event-emitter.ts b/lib/event-emitter.tsindex ab4d578..59fe11f 100644--- a/lib/event-emitter.ts+++ b/lib/event-emitter.ts@@ -50,7 +50,7 @@ if (process.env.NODE_ENV !== "production") {// Event typesexport type CalendarChangeEvent = {type: "shift" | "preset" | "note" | "calendar" | "sync-log";- action: "create" | "update" | "delete";+ action: "create" | "update" | "delete" | "reorder";calendarId: string;data?: unknown;};diff --git a/messages/de.json b/messages/de.jsonindex 63f5437..6ee8301 100644--- a/messages/de.json+++ b/messages/de.json@@ -133,6 +133,7 @@"noPresets": "Noch keine Schichtvorlagen","createFirstDescription": "Erstelle deine erste Vorlage, um Schichten schnell zu deinem Kalender hinzuzufügen. Vorlagen speichern deine häufig genutzten Schichtzeiten und Details.","deleteConfirm": "Diese Vorlage löschen? Alle aus dieser Vorlage erstellten Schichten werden ebenfalls gelöscht.",+ "primaryPresets": "Primäre Vorlagen","secondaryPresets": "Sekundäre Vorlagen","secondary": "Sekundär","markAsSecondary": "Als sekundär markieren (standardmäßig eingeklappt)",diff --git a/messages/en.json b/messages/en.jsonindex 80a8d2d..99181eb 100644--- a/messages/en.json+++ b/messages/en.json@@ -133,6 +133,7 @@"noPresets": "No shift presets yet","createFirstDescription": "Create your first preset to quickly add shifts to your calendar. Presets save your frequently used shift times and details.","deleteConfirm": "Delete this preset? This will also delete all shifts created from this preset.",+ "primaryPresets": "Primary Presets","secondaryPresets": "Secondary Presets","secondary": "Secondary","markAsSecondary": "Mark as secondary (collapsed by default)",diff --git a/messages/it.json b/messages/it.jsonindex 779e8fb..23b5859 100644--- a/messages/it.json+++ b/messages/it.json@@ -133,6 +133,7 @@"noPresets": "Ancora nessun preset turno","createFirstDescription": "Crea il tuo primo preset per aggiungere rapidamente turni al tuo calendario. I preset salvano gli orari e i dettagli dei turni utilizzati di frequente.","deleteConfirm": "Eliminare questo preset? Verranno eliminati anche tutti i turni creati da questo preset.",+ "primaryPresets": "Preset Primari","secondaryPresets": "Preset Secondari","secondary": "Secondario","markAsSecondary": "Segna come secondario (compresso di default)",diff --git a/package-lock.json b/package-lock.jsonindex 8fb3a71..221dd49 100644--- a/package-lock.json+++ b/package-lock.json@@ -8,6 +8,9 @@"name": "bettershift","version": "1.6.2","dependencies": {+ "@dnd-kit/core": "^6.3.1",+ "@dnd-kit/sortable": "^10.0.0",+ "@dnd-kit/utilities": "^3.2.2","@radix-ui/react-checkbox": "^1.3.3","@radix-ui/react-dialog": "^1.1.15","@radix-ui/react-label": "^2.1.8",@@ -306,6 +309,59 @@"integrity": "sha512-P5LUNhtbj6YfI3iJjw5EL9eUAG6OitD0W3fWQcpQjDRc/QIsL0tRNuO1PcDvPccWL1fSTXXdE1ds+l95DV/OFA==","license": "MIT"},+ "node_modules/@dnd-kit/accessibility": {+ "version": "3.1.1",+ "resolved": "https://registry.npmjs.org/@dnd-kit/accessibility/-/accessibility-3.1.1.tgz",+ "integrity": "sha512-2P+YgaXF+gRsIihwwY1gCsQSYnu9Zyj2py8kY5fFvUM1qm2WA2u639R6YNVfU4GWr+ZM5mqEsfHZZLoRONbemw==",+ "license": "MIT",+ "dependencies": {+ "tslib": "^2.0.0"+ },+ "peerDependencies": {+ "react": ">=16.8.0"+ }+ },+ "node_modules/@dnd-kit/core": {+ "version": "6.3.1",+ "resolved": "https://registry.npmjs.org/@dnd-kit/core/-/core-6.3.1.tgz",+ "integrity": "sha512-xkGBRQQab4RLwgXxoqETICr6S5JlogafbhNsidmrkVv2YRs5MLwpjoF2qpiGjQt8S9AoxtIV603s0GIUpY5eYQ==",+ "license": "MIT",+ "dependencies": {+ "@dnd-kit/accessibility": "^3.1.1",+ "@dnd-kit/utilities": "^3.2.2",+ "tslib": "^2.0.0"+ },+ "peerDependencies": {+ "react": ">=16.8.0",+ "react-dom": ">=16.8.0"+ }+ },+ "node_modules/@dnd-kit/sortable": {+ "version": "10.0.0",+ "resolved": "https://registry.npmjs.org/@dnd-kit/sortable/-/sortable-10.0.0.tgz",+ "integrity": "sha512-+xqhmIIzvAYMGfBYYnbKuNicfSsk4RksY2XdmJhT+HAC01nix6fHCztU68jooFiMUB01Ky3F0FyOvhG/BZrWkg==",+ "license": "MIT",+ "dependencies": {+ "@dnd-kit/utilities": "^3.2.2",+ "tslib": "^2.0.0"+ },+ "peerDependencies": {+ "@dnd-kit/core": "^6.3.0",+ "react": ">=16.8.0"+ }+ },+ "node_modules/@dnd-kit/utilities": {+ "version": "3.2.2",+ "resolved": "https://registry.npmjs.org/@dnd-kit/utilities/-/utilities-3.2.2.tgz",+ "integrity": "sha512-+MKAJEOfaBe5SmV6t34p80MMKhjvUz0vRrvVJbPT0WElzaOJ/1xs+D+KDv+tD/NE5ujfrChEcshd4fLn0wpiqg==",+ "license": "MIT",+ "dependencies": {+ "tslib": "^2.0.0"+ },+ "peerDependencies": {+ "react": ">=16.8.0"+ }+ },"node_modules/@drizzle-team/brocli": {"version": "0.10.2","resolved": "https://registry.npmjs.org/@drizzle-team/brocli/-/brocli-0.10.2.tgz",diff --git a/package.json b/package.jsonindex e0c9d73..f1c479b 100644--- a/package.json+++ b/package.json@@ -18,6 +18,9 @@"release:major": "npm version major && git push && git push --tags"},"dependencies": {+ "@dnd-kit/core": "^6.3.1",+ "@dnd-kit/sortable": "^10.0.0",+ "@dnd-kit/utilities": "^3.2.2","@radix-ui/react-checkbox": "^1.3.3","@radix-ui/react-dialog": "^1.1.15","@radix-ui/react-label": "^2.1.8",