diff --git a/src/hooks/stores/useCategoriesStore.ts b/src/hooks/stores/useCategoriesStore.ts index 94bf780..ab6d1e3 100644 --- a/src/hooks/stores/useCategoriesStore.ts +++ b/src/hooks/stores/useCategoriesStore.ts @@ -29,10 +29,9 @@ export function useCategoriesStore(options: UseCategoriesStoreOptions = {}) { // Utility functions const generateId = useCallback(() => { - return ( - (crypto as { randomUUID?: () => string }).randomUUID?.() || - `${Date.now()}-${Math.random().toString(36).slice(2)}` - ); + return typeof globalThis.crypto?.randomUUID === "function" + ? globalThis.crypto.randomUUID() + : `${Date.now()}-${Math.random().toString(36).slice(2)}`; }, []); const getNextColor = useCallback(() => { diff --git a/src/hooks/stores/useNotesStore.ts b/src/hooks/stores/useNotesStore.ts index da6adde..2016673 100644 --- a/src/hooks/stores/useNotesStore.ts +++ b/src/hooks/stores/useNotesStore.ts @@ -41,10 +41,9 @@ export function useNotesStore(options: UseNotesStoreOptions = {}) { // Utility functions const generateId = useCallback(() => { - return ( - (crypto as { randomUUID?: () => string }).randomUUID?.() || - `${Date.now()}-${Math.random().toString(36).slice(2)}` - ); + return typeof globalThis.crypto?.randomUUID === "function" + ? globalThis.crypto.randomUUID() + : `${Date.now()}-${Math.random().toString(36).slice(2)}`; }, []); const sortNotes = useCallback((notesList: Note[]): Note[] => { diff --git a/src/hooks/stores/useRecurringTasksStore.ts b/src/hooks/stores/useRecurringTasksStore.ts index 1a55565..d6b11cd 100644 --- a/src/hooks/stores/useRecurringTasksStore.ts +++ b/src/hooks/stores/useRecurringTasksStore.ts @@ -49,10 +49,9 @@ export function useRecurringTasksStore( // Utility functions const generateId = useCallback(() => { - return ( - (crypto as { randomUUID?: () => string }).randomUUID?.() || - `${Date.now()}-${Math.random().toString(36).slice(2)}` - ); + return typeof globalThis.crypto?.randomUUID === "function" + ? globalThis.crypto.randomUUID() + : `${Date.now()}-${Math.random().toString(36).slice(2)}`; }, []); // Date calculation functions diff --git a/src/hooks/stores/useTasksStore.ts b/src/hooks/stores/useTasksStore.ts index d08ebf6..ea09a77 100644 --- a/src/hooks/stores/useTasksStore.ts +++ b/src/hooks/stores/useTasksStore.ts @@ -43,10 +43,9 @@ export function useTasksStore(options: UseTasksStoreOptions = {}) { // Utility functions const generateId = useCallback(() => { - return ( - (crypto as { randomUUID?: () => string }).randomUUID?.() || - `${Date.now()}-${Math.random().toString(36).slice(2)}` - ); + return typeof globalThis.crypto?.randomUUID === "function" + ? globalThis.crypto.randomUUID() + : `${Date.now()}-${Math.random().toString(36).slice(2)}`; }, []); // Task CRUD operations diff --git a/src/hooks/useHabitStore.tsx b/src/hooks/useHabitStore.tsx index 1658047..4cb3031 100644 --- a/src/hooks/useHabitStore.tsx +++ b/src/hooks/useHabitStore.tsx @@ -9,8 +9,9 @@ import { const API_URL = "/api/habits"; const generateId = () => - (crypto as { randomUUID?: () => string }).randomUUID?.() || - `${Date.now()}-${Math.random().toString(36).slice(2)}`; + typeof globalThis.crypto?.randomUUID === "function" + ? globalThis.crypto.randomUUID() + : `${Date.now()}-${Math.random().toString(36).slice(2)}`; const useHabitStoreImpl = () => { const [habits, setHabits] = useState([]); diff --git a/src/hooks/useInventoryStore.tsx b/src/hooks/useInventoryStore.tsx index cbba6a7..88028cc 100644 --- a/src/hooks/useInventoryStore.tsx +++ b/src/hooks/useInventoryStore.tsx @@ -23,8 +23,9 @@ const CATS_URL = "/api/inventory/item-categories"; const TAGS_URL = "/api/inventory/item-tags"; const generateId = () => - (crypto as { randomUUID?: () => string }).randomUUID?.() || - `${Date.now()}-${Math.random().toString(36).slice(2)}`; + typeof globalThis.crypto?.randomUUID === "function" + ? globalThis.crypto.randomUUID() + : `${Date.now()}-${Math.random().toString(36).slice(2)}`; const useInventoryImpl = () => { const [items, setItems] = useState([]); diff --git a/src/hooks/useTaskStore.tsx b/src/hooks/useTaskStore.tsx index 7a8f84a..2306242 100644 --- a/src/hooks/useTaskStore.tsx +++ b/src/hooks/useTaskStore.tsx @@ -23,8 +23,9 @@ const API_URL = "/api/data"; const useTaskStoreImpl = () => { const generateId = () => - (crypto as { randomUUID?: () => string }).randomUUID?.() || - `${Date.now()}-${Math.random().toString(36).slice(2)}`; + typeof globalThis.crypto?.randomUUID === "function" + ? globalThis.crypto.randomUUID() + : `${Date.now()}-${Math.random().toString(36).slice(2)}`; const sortNotes = (list: Note[]): Note[] => { const pinned = list .filter((n) => n.pinned) diff --git a/src/hooks/useWorklog.tsx b/src/hooks/useWorklog.tsx index 2772d30..af94b3e 100644 --- a/src/hooks/useWorklog.tsx +++ b/src/hooks/useWorklog.tsx @@ -9,8 +9,9 @@ const API_COMMUTES = "/api/commutes"; const API_ALL = "/api/all"; const generateId = () => - (crypto as { randomUUID?: () => string }).randomUUID?.() || - `${Date.now()}-${Math.random().toString(36).slice(2)}`; + typeof globalThis.crypto?.randomUUID === "function" + ? globalThis.crypto.randomUUID() + : `${Date.now()}-${Math.random().toString(36).slice(2)}`; const useWorklogImpl = () => { const [trips, setTrips] = useState([]); diff --git a/src/shared/utils.ts b/src/shared/utils.ts index 70d043a..b9e33ad 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -13,10 +13,9 @@ import type { // ID generation utilities export function generateId(): string { - return ( - (crypto as { randomUUID?: () => string }).randomUUID?.() || - `${Date.now()}-${Math.random().toString(36).slice(2)}` - ); + return typeof globalThis.crypto?.randomUUID === "function" + ? globalThis.crypto.randomUUID() + : `${Date.now()}-${Math.random().toString(36).slice(2)}`; } export function generateTimestamp(): number { diff --git a/src/stores/timers.ts b/src/stores/timers.ts index cd8df0e..9d8a0e3 100644 --- a/src/stores/timers.ts +++ b/src/stores/timers.ts @@ -3,8 +3,9 @@ import { persist } from "zustand/middleware"; import { Timer } from "@/types"; const generateId = () => - (crypto as { randomUUID?: () => string }).randomUUID?.() || - `${Date.now()}-${Math.random().toString(36).slice(2)}`; + typeof globalThis.crypto?.randomUUID === "function" + ? globalThis.crypto.randomUUID() + : `${Date.now()}-${Math.random().toString(36).slice(2)}`; interface TimersState { timers: Timer[];