11import React , { useState , useEffect } from 'react' ;
2- import ListingsTable from './ListingsTable ' ;
2+ import VehicleListingTabs from './VehicleListingTabs ' ;
33import { findNewListings , findListingsWithPriceChanges } from '../services/dataLoader' ;
44import './NewListings.css' ;
55
@@ -34,7 +34,7 @@ export default function NewListings({ data }) {
3434 const newListings = findNewListings ( data ) ;
3535 const priceChangedListings = findListingsWithPriceChanges ( data ) ;
3636
37- // Combine new and price-changed listings
37+ // Combine new and price-changed listings for source filtering
3838 const allListings = [ ...newListings , ...priceChangedListings ] ;
3939
4040 if ( allListings . length === 0 ) {
@@ -45,9 +45,13 @@ export default function NewListings({ data }) {
4545 const sources = [ ...new Set ( allListings . map ( l => l . source ) ) ] . sort ( ) ;
4646
4747 // Filter listings by source
48- const filteredListings = selectedSource === 'all'
49- ? allListings
50- : allListings . filter ( l => l . source === selectedSource ) ;
48+ const filteredNewListings = selectedSource === 'all'
49+ ? newListings
50+ : newListings . filter ( l => l . source === selectedSource ) ;
51+
52+ const filteredChangedListings = selectedSource === 'all'
53+ ? priceChangedListings
54+ : priceChangedListings . filter ( l => l . source === selectedSource ) ;
5155
5256 const handleSourceChange = ( source ) => {
5357 setSelectedSource ( source ) ;
@@ -60,39 +64,34 @@ export default function NewListings({ data }) {
6064 window . history . pushState ( { } , '' , url ) ;
6165 } ;
6266
67+ const sourceFilterElement = (
68+ < div className = "source-filter" >
69+ < select
70+ id = "source-select"
71+ value = { selectedSource }
72+ onChange = { ( e ) => handleSourceChange ( e . target . value ) }
73+ >
74+ < option value = "all" > All Dealers ({ allListings . length } )</ option >
75+ { sources . map ( source => {
76+ const count = allListings . filter ( l => l . source === source ) . length ;
77+ const displayName = source . charAt ( 0 ) . toUpperCase ( ) + source . slice ( 1 ) ;
78+ return (
79+ < option key = { source } value = { source } >
80+ { displayName } ({ count } )
81+ </ option >
82+ ) ;
83+ } ) }
84+ </ select >
85+ </ div >
86+ ) ;
87+
6388 return (
6489 < div className = "new-listings" >
65- < div className = "new-listings-header" >
66- < div >
67- < h2 > New & Changed Listings </ h2 >
68- < p className = "subtitle" > Recently added vehicles and price changes from the latest scrape</ p >
69- </ div >
70- < div className = "source-filter" >
71- < label htmlFor = "source-select" > Filter by source:</ label >
72- < select
73- id = "source-select"
74- value = { selectedSource }
75- onChange = { ( e ) => handleSourceChange ( e . target . value ) }
76- >
77- < option value = "all" > All Sources ({ allListings . length } )</ option >
78- { sources . map ( source => {
79- const count = allListings . filter ( l => l . source === source ) . length ;
80- const displayName = source . charAt ( 0 ) . toUpperCase ( ) + source . slice ( 1 ) ;
81- return (
82- < option key = { source } value = { source } >
83- { displayName } ({ count } )
84- </ option >
85- ) ;
86- } ) }
87- </ select >
88- </ div >
89- </ div >
90- < ListingsTable
91- listings = { filteredListings }
92- title = ""
93- emptyMessage = "No new or changed listings found"
90+ < VehicleListingTabs
91+ newListings = { filteredNewListings }
92+ changedListings = { filteredChangedListings }
9493 showModel = { true }
95- showPriceChange = { true }
94+ sourceFilter = { sourceFilterElement }
9695 />
9796 </ div >
9897 ) ;
0 commit comments