diff --git a/.phase19-state.json b/.phase19-state.json index 3c324bd..dab472d 100644 --- a/.phase19-state.json +++ b/.phase19-state.json @@ -1,8 +1,9 @@ { "completed_features": [], - "current_feature": "rate-limiting-stub", + "current_feature": "search-history", "started_at": "2026-05-23T07:42:47.919364", "attempted_features": [ - "invitation-flow" + "invitation-flow", + "rate-limiting-stub" ] } \ No newline at end of file diff --git a/GENERATION_LOG.md b/GENERATION_LOG.md index 4f30381..fb098ac 100644 --- a/GENERATION_LOG.md +++ b/GENERATION_LOG.md @@ -2292,3 +2292,20 @@ src/index.ts(27,25): error TS2769: No overload matches this call. Overload 2 of 3, '(plugin: FastifyPluginAsync<{ 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 'FastifyPluginAsync<{ limits: { fileSize: number; }; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>'. Type 'Promise' provides no match for the signature '(instance: FastifyInstance, FastifyBaseLogger, FastifyTy +- `07:45:33` **INFO** Committed feature rate-limiting-stub +- `07:45:33` **INFO** Pushed: rc=0 + +## Phase-3 Feature: search-history (2026-05-23 07:45:33) + +- `07:45:33` **INFO** Description: Letzte 10 Sucheinträge des Users persistieren (localStorage) +- `07:45:33` **INFO** Generating apps/web/src/components/SearchBar.tsx (ERWEITERT — behalte bestehende SearchBar. Persistiere bei jedem Search…) +- `07:46:28` **INFO** wrote 6439 chars in 54.9s (attempt 1) +- `07:46:28` **INFO** Running tsc --noEmit on api… +- `07:46:30` **WARN** tsc errors: +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, FastifyBaseLogger, FastifyTypeProvider>, opts: { ...; }, done: (err?: Error | undefined) => void): void'. + Overload 2 of 3, '(plugin: FastifyPluginAsync<{ 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 'FastifyPluginAsync<{ limits: { fileSize: number; }; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>'. + Type 'Promise' provides no match for the signature '(instance: FastifyInstance, FastifyBaseLogger, FastifyTy diff --git a/apps/web/src/components/SearchBar.tsx b/apps/web/src/components/SearchBar.tsx index 8375e67..b08d2c1 100644 --- a/apps/web/src/components/SearchBar.tsx +++ b/apps/web/src/components/SearchBar.tsx @@ -1,6 +1,6 @@ import React, { useState, useEffect } from 'react'; import { useNavigate } from '@tanstack/react-router'; -import { Search, User, Folder, Clock, X } from 'lucide-react'; +import { Search, User, Folder, Clock, X, History } from 'lucide-react'; import { useQuery } from '@tanstack/react-query'; import { api } from '../lib/api'; @@ -14,11 +14,35 @@ interface SearchResult { export default function SearchBar() { const [query, setQuery] = useState(''); const [isOpen, setIsOpen] = useState(false); + const [history, setHistory] = useState([]); const navigate = useNavigate(); + useEffect(() => { + const saved = localStorage.getItem('search_history'); + if (saved) { + try { + setHistory(JSON.parse(saved)); + } catch (e) { + console.error('Failed to parse search history'); + } + } + }, []); + + const addToHistory = (term: string) => { + if (!term.trim()) return; + const updated = [term, ...history.filter((item) => item !== term)].slice(0, 10); + setHistory(updated); + localStorage.setItem('search_history', JSON.stringify(updated)); + }; + const { data: results, isLoading } = useQuery({ queryKey: ['search', query], - queryFn: () => api.search(query), + queryFn: async () => { + if (query.length >= 2) { + addToHistory(query); + } + return api.search(query); + }, enabled: query.length >= 2, }); @@ -41,6 +65,11 @@ export default function SearchBar() { setIsOpen(false); }; + const handleHistoryClick = (term: string) => { + setQuery(term); + setIsOpen(true); + }; + const getIcon = (type: SearchResult['type']) => { switch (type) { case 'customer': return ; @@ -74,13 +103,33 @@ export default function SearchBar() { )} - {isOpen && (query.length >= 2 || (results && results.length > 0)) && ( + {isOpen && (
- {isLoading ? ( + {query.length === 0 ? ( +
+
+ Recent Searches +
+ {history.length > 0 ? ( + history.map((term) => ( + + )) + ) : ( +
No recent searches
+ )} +
+ ) : isLoading ? (
Searching...
) : results && results.length > 0 ? (
- {['customer', 'project', 'time-entry'].map((type) => { + {(['customer', 'project', 'time-entry'] as const).map((type) => { const filtered = results.filter((r: SearchResult) => r.type === type); if (filtered.length === 0) return null; @@ -97,10 +146,8 @@ export default function SearchBar() { > {getIcon(result.type)}
- {result.label} - {result.subtitle && ( - {result.subtitle} - )} + {result.label} + {result.subtitle && {result.subtitle}}
))} @@ -109,7 +156,7 @@ export default function SearchBar() { })}
) : ( -
No results found
+
No results found
)}
)}