fix: remove need selector chip strip from results page
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { Box, Button, Card, Chip, Typography } from '@mui/material'
|
import { Box, Button, Card, Typography } from '@mui/material'
|
||||||
import { useNavigate, useLocation } from 'react-router'
|
import { useNavigate, useLocation } from 'react-router'
|
||||||
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
||||||
import { useUnifiedResults } from '../../hooks/useUnifiedResults'
|
import { useUnifiedResults } from '../../hooks/useUnifiedResults'
|
||||||
@@ -44,27 +44,22 @@ export default function Results() {
|
|||||||
(localStorage.getItem('view-results') as 'list' | 'grid') ?? 'list'
|
(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
|
// When coming from NeedBuilder, invalidate so the freshly created need is included
|
||||||
const activeNeedIdFromNav = (location.state as { activeNeedId?: string } | null)?.activeNeedId
|
const activeNeedIdFromNav = (location.state as { activeNeedId?: string } | null)?.activeNeedId
|
||||||
|
|
||||||
const { data: needResp } = useQuery({
|
const { data: needResp } = useQuery({
|
||||||
queryKey: ['needs'],
|
queryKey: ['needs'],
|
||||||
queryFn: () => needService.getAll(),
|
queryFn: () => needService.getAll(),
|
||||||
// Refetch on mount when navigating from NeedBuilder to pick up the new need
|
|
||||||
refetchOnMount: activeNeedIdFromNav ? 'always' : true,
|
refetchOnMount: activeNeedIdFromNav ? 'always' : true,
|
||||||
gcTime: 0,
|
gcTime: 0,
|
||||||
})
|
})
|
||||||
|
|
||||||
const allNeeds = needResp?.data ?? []
|
const allNeeds = needResp?.data ?? []
|
||||||
// Only show named needs in the selector — skip auto-generated "Neue Suche" entries
|
|
||||||
const namedNeeds = allNeeds.filter(n => n.companyName !== 'Neue Suche')
|
|
||||||
|
|
||||||
// Priority: explicit user selection → nav (just came from NeedBuilder) → first named need
|
// Nav ID (from NeedBuilder) takes priority; otherwise first named need
|
||||||
const effectiveNeedId = selectedNeedId ?? activeNeedIdFromNav ?? namedNeeds[0]?.id
|
const effectiveNeedId = activeNeedIdFromNav ?? allNeeds.find(n => n.companyName !== 'Neue Suche')?.id
|
||||||
|
|
||||||
const activeNeed = allNeeds.find(n => n.id === effectiveNeedId) ?? namedNeeds[0]
|
const activeNeed = allNeeds.find(n => n.id === effectiveNeedId) ?? allNeeds[0]
|
||||||
|
|
||||||
// Ensure query cache is invalidated when a new need was just created
|
// Ensure query cache is invalidated when a new need was just created
|
||||||
if (activeNeedIdFromNav) {
|
if (activeNeedIdFromNav) {
|
||||||
@@ -129,25 +124,6 @@ export default function Results() {
|
|||||||
<Box sx={{ flex: 1, overflowY: 'auto', px: 3, py: 3 }}>
|
<Box sx={{ flex: 1, overflowY: 'auto', px: 3, py: 3 }}>
|
||||||
{activeNeed && (
|
{activeNeed && (
|
||||||
<Card sx={{ bgcolor: '#eff6ff', p: 2, mb: 2, border: '1px solid #bfdbfe' }}>
|
<Card sx={{ bgcolor: '#eff6ff', p: 2, mb: 2, border: '1px solid #bfdbfe' }}>
|
||||||
{/* Need selector — named searches only */}
|
|
||||||
{namedNeeds.length > 1 && (
|
|
||||||
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 0.75, mb: 1.5 }}>
|
|
||||||
{namedNeeds.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 sx={{ display: 'flex', alignItems: 'flex-start', justifyContent: 'space-between', gap: 2 }}>
|
||||||
<Box>
|
<Box>
|
||||||
<Typography variant="subtitle2" sx={{ fontWeight: 700, mb: 0.5 }} color="#1e3a5f">
|
<Typography variant="subtitle2" sx={{ fontWeight: 700, mb: 0.5 }} color="#1e3a5f">
|
||||||
|
|||||||
Reference in New Issue
Block a user