mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-28 09:33:46 +00:00
- Remove legacy .eslintrc.cjs and .eslintignore - Add eslint.config.js with flat config, security rules (no-eval, no-implied-eval, no-new-func, no-script-url) - Add .prettierrc and .prettierignore - Format entire codebase with prettier
53 lines
1.1 KiB
TypeScript
53 lines
1.1 KiB
TypeScript
import { useState, useEffect, useCallback } from 'react';
|
|
|
|
const STORAGE_KEY = 'admin_favorite_settings';
|
|
|
|
export function useFavoriteSettings() {
|
|
const [favorites, setFavorites] = useState<string[]>(() => {
|
|
try {
|
|
const stored = localStorage.getItem(STORAGE_KEY);
|
|
return stored ? JSON.parse(stored) : [];
|
|
} catch {
|
|
return [];
|
|
}
|
|
});
|
|
|
|
// Sync to localStorage
|
|
useEffect(() => {
|
|
try {
|
|
localStorage.setItem(STORAGE_KEY, JSON.stringify(favorites));
|
|
} catch {
|
|
// Ignore storage errors
|
|
}
|
|
}, [favorites]);
|
|
|
|
const toggleFavorite = useCallback((settingKey: string) => {
|
|
setFavorites((prev) => {
|
|
if (prev.includes(settingKey)) {
|
|
return prev.filter((key) => key !== settingKey);
|
|
} else {
|
|
return [...prev, settingKey];
|
|
}
|
|
});
|
|
}, []);
|
|
|
|
const isFavorite = useCallback(
|
|
(settingKey: string) => {
|
|
return favorites.includes(settingKey);
|
|
},
|
|
[favorites],
|
|
);
|
|
|
|
const clearFavorites = useCallback(() => {
|
|
setFavorites([]);
|
|
}, []);
|
|
|
|
return {
|
|
favorites,
|
|
toggleFavorite,
|
|
isFavorite,
|
|
clearFavorites,
|
|
count: favorites.length,
|
|
};
|
|
}
|