created a new branch with alert functionality and added the compose files etc ..

This commit is contained in:
Siavash Sameni
2025-08-26 16:15:20 +04:00
parent 0d06090865
commit 6c4a8dfe83
13 changed files with 980 additions and 58 deletions

42
utils/useLocalStorage.ts Normal file
View File

@@ -0,0 +1,42 @@
import { useEffect, useState } from 'react';
export function useLocalStorage<T>(key: string, initial: T) {
const [value, setValue] = useState<T>(() => {
try {
if (typeof window !== 'undefined') {
const raw = localStorage.getItem(key);
if (raw) {
const parsed = JSON.parse(raw);
console.log('[useLocalStorage] Init from storage', { key, value: parsed });
return parsed as T;
}
}
} catch {}
return initial;
});
useEffect(() => {
try {
const raw = typeof window !== 'undefined' ? localStorage.getItem(key) : null;
if (raw) {
const parsed = JSON.parse(raw);
console.log('[useLocalStorage] Loaded', { key, value: parsed });
setValue(parsed);
} else {
console.log('[useLocalStorage] No existing value, using initial', { key, initial });
}
} catch {}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [key]);
useEffect(() => {
try {
if (typeof window !== 'undefined') {
localStorage.setItem(key, JSON.stringify(value));
console.log('[useLocalStorage] Saved', { key, value });
}
} catch {}
}, [key, value]);
return [value, setValue] as const;
}