From 29646c8015e7ec2f6b48a8a414061c4b3e7cd8ba Mon Sep 17 00:00:00 2001 From: "Dennis (via Claude+Gemma)" Date: Sat, 23 May 2026 09:19:24 +0200 Subject: [PATCH] feat(favorites-system): User kann Customer/Project favoritisieren (localStorage) [tsc:fail] --- .phase29-state.json | 7 ++- GENERATION_LOG.md | 18 ++++++++ apps/web/src/lib/favorites.ts | 87 +++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 apps/web/src/lib/favorites.ts diff --git a/.phase29-state.json b/.phase29-state.json index 49bad46..c219129 100644 --- a/.phase29-state.json +++ b/.phase29-state.json @@ -1,5 +1,8 @@ { "completed_features": [], - "current_feature": "recently-viewed-widget", - "started_at": "2026-05-23T09:18:37.298269" + "current_feature": "favorites-system", + "started_at": "2026-05-23T09:18:37.298269", + "attempted_features": [ + "recently-viewed-widget" + ] } \ No newline at end of file diff --git a/GENERATION_LOG.md b/GENERATION_LOG.md index 9a283a3..c083645 100644 --- a/GENERATION_LOG.md +++ b/GENERATION_LOG.md @@ -3300,3 +3300,21 @@ src/index.ts(27,25): error TS2769: No overload matches this call. Overload 1 of 3, '(plugin: FastifyPluginCallback<{ limits: { fileSize: number; }; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>, opts?: FastifyRegisterOptions<...> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error. Argument of type 'Promise' is not assignable to parameter of type 'FastifyPluginCallback<{ limits: { fileSize: number; }; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>'. Type 'Promise' provides no match for the signature '(instance: FastifyInstance, +- `09:19:02` **INFO** Committed feature recently-viewed-widget +- `09:19:02` **INFO** Pushed: rc=0 + +## Phase-3 Feature: favorites-system (2026-05-23 09:19:02) + +- `09:19:02` **INFO** Description: User kann Customer/Project favoritisieren (localStorage) +- `09:19:02` **INFO** Generating apps/web/src/lib/favorites.ts (useFavorites() hook + util. Manages localStorage 'favorites' Set per e…) +- `09:19:22` **INFO** wrote 2276 chars in 19.9s (attempt 1) +- `09:19:22` **INFO** Running tsc --noEmit on api… +- `09:19:24` **WARN** tsc errors: +src/db/schema.ts(37,14): error TS7022: 'customers' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. +src/db/schema.ts(45,59): error TS7024: Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions. +src/db/schema.ts(49,14): error TS7022: 'projects' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. +src/db/schema.ts(53,56): error TS7024: Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions. +src/index.ts(27,25): error TS2769: No overload matches this call. + Overload 1 of 3, '(plugin: FastifyPluginCallback<{ limits: { fileSize: number; }; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>, opts?: FastifyRegisterOptions<...> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error. + Argument of type 'Promise' is not assignable to parameter of type 'FastifyPluginCallback<{ limits: { fileSize: number; }; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>'. + Type 'Promise' provides no match for the signature '(instance: FastifyInstance, diff --git a/apps/web/src/lib/favorites.ts b/apps/web/src/lib/favorites.ts new file mode 100644 index 0000000..5938d3f --- /dev/null +++ b/apps/web/src/lib/favorites.ts @@ -0,0 +1,87 @@ +import { useState, useEffect } from 'react'; + +const STORAGE_KEY = 'emberclone_favorites'; +const FAVORITES_EVENT = 'emberclone_favorites_updated'; + +export const favoritesUtils = { + getFavorites: (): Record> => { + const data = localStorage.getItem(STORAGE_KEY); + if (!data) return {}; + try { + const parsed = JSON.parse(data); + const result: Record> = {}; + for (const [type, ids] of Object.entries(parsed)) { + result[type] = new Set(ids as string[]); + } + return result; + } catch { + return {}; + } + }, + + saveFavorites: (favorites: Record>) => { + const data: Record = {}; + for (const [type, ids] of Object.entries(favorites)) { + data[type] = Array.from(ids); + } + localStorage.setItem(STORAGE_KEY, JSON.stringify(data)); + window.dispatchEvent(new CustomEvent(FAVORITES_EVENT)); + }, + + isFavorite: (type: string, id: string): boolean => { + const favs = favoritesUtils.getFavorites(); + return favs[type]?.has(id) ?? false; + }, + + toggleFavorite: (type: string, id: string) => { + const favs = favoritesUtils.getFavorites(); + if (!favs[type]) { + favs[type] = new Set(); + } + + if (favs[type].has(id)) { + favs[type].delete(id); + } else { + favs[type].add(id); + } + + favoritesUtils.saveFavorites(favs); + }, + + getAllFavorites: (type: string): string[] => { + const favs = favoritesUtils.getFavorites(); + return Array.from(favs[type] || []); + } +}; + +export function useFavorites() { + const [favorites, setFavorites] = useState(() => favoritesUtils.getFavorites()); + + useEffect(() => { + const handleUpdate = () => { + setFavorites(favoritesUtils.getFavorites()); + }; + + window.addEventListener(FAVORITES_EVENT, handleUpdate); + return () => window.removeEventListener(FAVORITES_EVENT, handleUpdate); + }, []); + + const isFavorite = (type: string, id: string) => { + return favorites[type]?.has(id) ?? false; + }; + + const toggle = (type: string, id: string) => { + favoritesUtils.toggleFavorite(type, id); + }; + + const getAll = (type: string) => { + return Array.from(favorites[type] || []); + }; + + return { + isFavorite, + toggle, + getAll, + favorites + }; +} \ No newline at end of file