fix: need selector on results page + retail budget parsing

- Results page: chip strip shows all saved searches — click to switch without
  creating a new search. Defaults to first need instead of most-recently-created
  so pre-existing mock needs load immediately on navigation.
- AI parser: asset-type-aware monthly budget threshold (RETAIL: 500, others: 150)
  so "150 CHF/m²" for retail is correctly converted to 1800 CHF/m²/year instead
  of being stored as an impossibly low annual value that excludes all properties.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Benjamin Sutter
2026-05-21 20:47:14 +02:00
parent 27c53f3af1
commit 11ecd5d900
2 changed files with 32 additions and 11 deletions
+27 -8
View File
@@ -44,6 +44,8 @@ export default function Results() {
(localStorage.getItem('view-results') as 'list' | 'grid') ?? 'list'
)
const [selectedNeedId, setSelectedNeedId] = useState<string | undefined>(undefined)
// When coming from NeedBuilder, invalidate so the freshly created need is included
const activeNeedIdFromNav = (location.state as { activeNeedId?: string } | null)?.activeNeedId
@@ -55,14 +57,12 @@ export default function Results() {
gcTime: 0,
})
// Prefer the ID passed from NeedBuilder; fall back to most-recently-created
const activeNeed = needResp?.data
? activeNeedIdFromNav
? (needResp.data.find(n => n.id === activeNeedIdFromNav) ?? needResp.data[0])
: [...needResp.data].sort((a, b) =>
new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()
)[0]
: undefined
const allNeeds = needResp?.data ?? []
// Priority: explicit user selection → nav (just came from NeedBuilder) → first need in list
const effectiveNeedId = selectedNeedId ?? activeNeedIdFromNav ?? allNeeds[0]?.id
const activeNeed = allNeeds.find(n => n.id === effectiveNeedId) ?? allNeeds[0]
// Ensure query cache is invalidated when a new need was just created
if (activeNeedIdFromNav) {
@@ -127,6 +127,25 @@ export default function Results() {
<Box sx={{ flex: 1, overflowY: 'auto', px: 3, py: 3 }}>
{activeNeed && (
<Card sx={{ bgcolor: '#eff6ff', p: 2, mb: 2, border: '1px solid #bfdbfe' }}>
{/* Need selector — all saved searches as chips */}
{allNeeds.length > 1 && (
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 0.75, mb: 1.5 }}>
{allNeeds.map(n => (
<Chip
key={n.id}
label={`${n.companyName} · ${n.assetType}`}
size="small"
variant={n.id === activeNeed.id ? 'filled' : 'outlined'}
onClick={() => setSelectedNeedId(n.id)}
sx={n.id === activeNeed.id
? { fontSize: '0.68rem', height: 22, bgcolor: '#1e3a5f', color: 'white', cursor: 'pointer' }
: { fontSize: '0.68rem', height: 22, color: '#64748b', borderColor: '#cbd5e1', cursor: 'pointer' }
}
/>
))}
</Box>
)}
<Box sx={{ display: 'flex', alignItems: 'flex-start', justifyContent: 'space-between', gap: 2 }}>
<Box>
<Typography variant="subtitle2" sx={{ fontWeight: 700, mb: 0.5 }} color="#1e3a5f">