Skip to content

Commit 0fb74cf

Browse files
committed
#125 add divider between search result batches
1 parent c8b7f30 commit 0fb74cf

2 files changed

Lines changed: 50 additions & 16 deletions

File tree

frontend/src/components/app/SearchResult.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const SearchResult: React.FC<SearchResultProps> = ({ searchResult: sr }) => {
1818
const { zipCase: c, caseSummary: summary } = sr;
1919

2020
return (
21-
<div className="bg-white rounded-lg shadow overflow-hidden">
21+
<div className="bg-white rounded-lg shadow overflow-hidden border-t border-gray-100">
2222
<div className="p-4 sm:p-6">
2323
<div className="flex items-start">
2424
<div className="flex-shrink-0 mr-4">

frontend/src/components/app/SearchResultsList.tsx

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,58 @@ import { useSearchResults, useConsolidatedPolling } from '../../hooks/useCaseSea
33
import { SearchResult as SearchResultType } from '../../../../shared/types';
44
import { useEffect, useMemo } from 'react';
55

6-
// Individual case result component - no polling here, just display
6+
type DisplayItem = SearchResultType | 'divider';
7+
78
function CaseResultItem({ searchResult }: { searchResult: SearchResultType }) {
89
return <SearchResult searchResult={searchResult} />;
910
}
1011

1112
export default function SearchResultsList() {
1213
const { data, isLoading, isError, error } = useSearchResults();
1314

14-
// Extract ordered results based on batches (newest searches first)
15-
const searchResults = useMemo(() => {
15+
// Extract batches and create a flat display list with dividers
16+
const displayItems = useMemo(() => {
1617
if (!data || !data.results || !data.searchBatches) {
1718
return [];
1819
}
1920

20-
// Flatten batches while maintaining batch order
21-
const orderedCaseNumbers: string[] = [];
21+
const items: DisplayItem[] = [];
2222
const seenCaseNumbers = new Set<string>();
2323

2424
// Process each batch (newest first)
25-
data.searchBatches.forEach(batch => {
25+
data.searchBatches.forEach((batch, batchIndex) => {
26+
// Collect valid results from this batch first
27+
const batchResults: SearchResultType[] = [];
2628
batch.forEach(caseNumber => {
27-
// Only add case numbers we haven't seen yet to avoid duplicates
2829
if (!seenCaseNumbers.has(caseNumber)) {
29-
orderedCaseNumbers.push(caseNumber);
30-
seenCaseNumbers.add(caseNumber);
30+
const result = data.results[caseNumber];
31+
if (result) {
32+
batchResults.push(result);
33+
seenCaseNumbers.add(caseNumber);
34+
}
3135
}
3236
});
37+
38+
// Only add divider and results if this batch has actual cases
39+
if (batchResults.length > 0) {
40+
// Add divider before each batch except the first (newest) AND only if we already have items
41+
if (batchIndex > 0 && items.length > 0) {
42+
items.push('divider');
43+
}
44+
45+
// Add all the results from this batch
46+
items.push(...batchResults);
47+
}
3348
});
3449

35-
// Map ordered case numbers to their result objects
36-
return orderedCaseNumbers.map(caseNumber => data.results[caseNumber]).filter(Boolean); // Remove any undefined entries
50+
return items;
3751
}, [data]);
3852

53+
// Extract just the search results for polling logic
54+
const searchResults = useMemo(() => {
55+
return displayItems.filter((item): item is SearchResultType => typeof item !== 'string');
56+
}, [displayItems]);
57+
3958
// Use the consolidated polling approach for all non-terminal cases
4059
const polling = useConsolidatedPolling();
4160

@@ -81,12 +100,27 @@ export default function SearchResultsList() {
81100
</div>
82101
) : (
83102
<>
84-
{searchResults.length > 0 ? (
103+
{displayItems.length > 0 ? (
85104
<div className="mt-8">
86105
<h3 className="text-base font-semibold text-gray-900">Search Results</h3>
87-
<div className="mt-4 space-y-4">
88-
{searchResults.map(result => (
89-
<CaseResultItem key={`${result.zipCase.caseNumber}`} searchResult={result} />
106+
<div className="mt-4">
107+
{displayItems.map((item, index) => (
108+
<div key={item === 'divider' ? `divider-${index}` : item.zipCase.caseNumber}>
109+
{item === 'divider' ? (
110+
<div className="relative my-6">
111+
<div className="absolute inset-0 flex items-center" aria-hidden="true">
112+
<div className="w-full border-t border-gray-300" />
113+
</div>
114+
<div className="relative flex justify-center">
115+
<span className="bg-gray-50 px-3 text-sm text-gray-500">◇◇◇</span>
116+
</div>
117+
</div>
118+
) : (
119+
<div className="mb-4">
120+
<CaseResultItem searchResult={item} />
121+
</div>
122+
)}
123+
</div>
90124
))}
91125
</div>
92126
</div>

0 commit comments

Comments
 (0)