@@ -3,42 +3,71 @@ import { fetchData } from "../utils";
33import Globe from "../components/Globe" ;
44import CityList from "../components/CityList" ;
55import Searchbar from "../components/Searchbar/Searchbar" ;
6+ import Notification from "../components/Notification" ;
67
78export default function Content ( ) {
89 const [ recommendations , setRecommendations ] = useState ( [ ] ) ;
910 const [ query , setQuery ] = useState ( "" ) ;
11+ const [ selectedDate , setSelectedDate ] = useState ( new Date ( ) . toISOString ( ) . split ( 'T' ) [ 0 ] ) ;
1012 const [ searchResults , setSearchResults ] = useState ( [ ] ) ;
1113 const [ selectedCity , setSelectedCity ] = useState ( null ) ;
1214 const jwt = localStorage . getItem ( "jwt" ) ;
15+ const [ notification , setNotification ] = useState ( null ) ;
1316
1417 useEffect ( ( ) => {
1518 const loadRecommendations = async ( ) => {
1619 const data = await fetchData ( "report/cityNames" , "GET" , null , jwt ) ;
17- console . log ( "🚀 ~ loadRecommendations ~ data:" , data )
20+ console . log ( "🚀 ~ loadRecommendations ~ data:" , data ) ;
1821 if ( data ) setRecommendations ( data ) ;
1922 } ;
2023 loadRecommendations ( ) ;
21- } , [ ] ) ;
24+ } , [ searchResults ] ) ;
2225
2326 const handleSearch = async ( ) => {
24- const result = await fetchData ( `report?city=${ query } ` , "GET" , null , jwt ) ;
25- if ( result ) {
26- setSearchResults ( ( prev ) => [ result , ...prev ] ) ;
27- setSelectedCity ( result ) ;
27+ if ( ! query || ! selectedDate ) return ;
28+
29+ try {
30+ const result = await fetchData (
31+ `report?city=${ query } &date=${ selectedDate } ` ,
32+ "GET" ,
33+ null ,
34+ jwt
35+ ) ;
36+ if ( result ) {
37+ setSearchResults ( ( prev ) => [ result , ...prev ] ) ;
38+ setSelectedCity ( result ) ;
39+ }
40+ } catch ( error ) {
41+ setNotification ( { type : "error" , message : error . message } ) ;
2842 }
2943 } ;
3044
3145 return (
32- < div className = "p-6 w-full flex flex-col gap-4 z-10 h-screen box-border" >
33- < Searchbar recommendations = { recommendations } setQuery = { setQuery } query = { query } handleSearch = { handleSearch } > </ Searchbar >
34- < div className = "w-full overflow-x-auto" >
35- < CityList cities = { searchResults } />
36- </ div >
37-
38- < div className = "flex-1 min-h-0 flex justify-center items-center" >
39- < Globe city = { selectedCity } />
40- </ div >
41- </ div >
42-
46+ < div className = "p-6 w-full flex flex-col gap-4 z-10 h-screen box-border" >
47+ < Searchbar
48+ recommendations = { recommendations }
49+ setQuery = { setQuery }
50+ query = { query }
51+ selectedDate = { selectedDate }
52+ setSelectedDate = { setSelectedDate }
53+ handleSearch = { handleSearch }
54+ />
55+ < div className = "flex" >
56+ < div className = "w-full overflow-x-auto backdrop-blur-md bg-white/10 border border-white/20 basis-6/12" >
57+ < h1 className = "text-center text-3xl my-2 sticky left-0" > Previous Searches</ h1 >
58+ < CityList cities = { searchResults } />
59+ </ div >
60+ < div className = "flex-1 min-h-0 flex justify-center items-center" >
61+ < Globe city = { selectedCity } />
62+ </ div >
63+ </ div >
64+ { notification && (
65+ < Notification
66+ type = { notification . type }
67+ message = { notification . message }
68+ onClose = { ( ) => setNotification ( null ) }
69+ />
70+ ) }
71+ </ div >
4372 ) ;
44- }
73+ }
0 commit comments