WIP jordan
This commit is contained in:
35
app/composables/useClientFavorites.ts
Normal file
35
app/composables/useClientFavorites.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Client favorites — star customers for quick dashboard access.
|
||||
* Persisted in localStorage. Stores customer IDs.
|
||||
*/
|
||||
import { useLocalStorageRef } from '~/utils/useLocalStorageRef'
|
||||
|
||||
const KEY = 'policy-ui-client-favorites-v1'
|
||||
|
||||
export function useClientFavorites() {
|
||||
const favoriteIds = useLocalStorageRef<string[]>(KEY, () => [])
|
||||
|
||||
function isFavorite(customerId: string) {
|
||||
return favoriteIds.value.includes(customerId)
|
||||
}
|
||||
|
||||
function toggleFavorite(customerId: string) {
|
||||
if (isFavorite(customerId)) {
|
||||
favoriteIds.value = favoriteIds.value.filter(id => id !== customerId)
|
||||
} else {
|
||||
favoriteIds.value = [customerId, ...favoriteIds.value]
|
||||
}
|
||||
}
|
||||
|
||||
function addFavorite(customerId: string) {
|
||||
if (!isFavorite(customerId)) {
|
||||
favoriteIds.value = [customerId, ...favoriteIds.value]
|
||||
}
|
||||
}
|
||||
|
||||
function removeFavorite(customerId: string) {
|
||||
favoriteIds.value = favoriteIds.value.filter(id => id !== customerId)
|
||||
}
|
||||
|
||||
return { favoriteIds, isFavorite, toggleFavorite, addFavorite, removeFavorite }
|
||||
}
|
||||
Reference in New Issue
Block a user