11import React , { useState , useEffect } from 'react' ;
2- import { model } from '../model.js' ;
3- import kth_logo from '../assets/kth_logo.png' ;
42import { getAuth , signInWithPopup , signOut , GoogleAuthProvider } from "firebase/auth" ;
3+ import kth_logo from '../assets/kth_logo.png' ;
4+ import project_logo from '../assets/project_icon.png' ;
5+ import FavouritesDropdown from './Components/FavouriteDropdown.jsx' ;
56
67function SearchbarView ( props ) {
78 const [ searchQuery , setSearchQuery ] = useState ( '' ) ;
89 const [ user , setUser ] = useState ( null ) ;
10+ const [ showFavourites , setShowFavourites ] = useState ( false ) ;
11+
912 const auth = getAuth ( ) ;
1013 const provider = new GoogleAuthProvider ( ) ;
1114
1215 useEffect ( ( ) => {
13- const unsubscribe = auth . onAuthStateChanged ( setUser ) ;
16+ const unsubscribe = auth . onAuthStateChanged ( ( user ) => {
17+ setUser ( user ) ;
18+ } ) ;
1419 return ( ) => unsubscribe ( ) ;
15- } , [ auth ] ) ;
20+ } , [ auth ] ) ;
1621
17- const handleSearch = ( ) => {
18- const results = props . courses . filter ( course =>
19- course . name . toLowerCase ( ) . includes ( searchQuery . toLowerCase ( ) )
20- ) . splice ( 0 , 10 ) ;
21- props . searchResults ( results ) ;
22+ const handleSearch = ( query ) => {
23+ setSearchQuery ( query ) ;
24+ props . searchCourses ( query ) ;
2225 } ;
2326
2427 const handleSignIn = async ( ) => {
@@ -37,7 +40,7 @@ function SearchbarView(props) {
3740 < div className = "w-full px-6 py-6 bg-[#000061] flex items-center justify-between" >
3841 < a href = "https://www.kth.se" className = "flex items-center h-[90px] w-auto" >
3942 < img
40- src = { kth_logo }
43+ src = { project_logo }
4144 className = "h-[90px] w-auto"
4245 alt = "KTH Logo"
4346 />
@@ -47,36 +50,54 @@ function SearchbarView(props) {
4750 type = "text"
4851 placeholder = "What course are you looking for?"
4952 value = { searchQuery }
50- onChange = { ( e ) => setSearchQuery ( e . target . value ) }
51- onKeyPress = { ( e ) => e . key === "Enter" && handleSearch ( ) }
53+ onChange = { ( e ) => handleSearch ( e . target . value ) }
5254 className = "w-[400px] h-[44px] pl-14 pr-4 bg-white text-black rounded-full"
5355 />
5456
55- < div className = "flex gap-4 " >
57+ < div className = "flex gap-6 items-center " >
5658 < button
57- className = "w-[100px ] h-[44px] bg-white text-black rounded-full text-center border border-solid cursor-pointer hover:bg-[#000061] hover:text-white "
59+ className = "w-[120px ] h-[44px] bg-[#003399] text-white rounded-full border border-[#000061] cursor-pointer hover:bg-[#001a4d] transition-all duration-200 "
5860 onClick = { ( ) => window . location . href = "https://inferencekth.github.io/Find-My-Next-Course/" } >
5961 About us
6062 </ button >
6163
62- < div className = "w-[100px] h-[44px] bg-white text-black rounded-full text-center border border-solid cursor-pointer hover:bg-[#000061] hover:text-white flex items-center justify-center" >
64+ < button onClick = { ( ) => setShowFavourites ( ! showFavourites ) }
65+ className = "w-[120px] h-[44px] bg-[#003399] text-white rounded-full border border-[#000061] cursor-pointer hover:bg-[#001a4d] transition-all duration-200" >
66+ Favourites
67+ </ button >
68+
69+ < div className = "relative" >
70+ { showFavourites && (
71+ < FavouritesDropdown
72+ favouriteCourses = { props . favouriteCourses }
73+ removeFavourite = { props . removeFavourite }
74+ />
75+ ) }
76+ </ div >
77+
78+ < div className = "flex items-center cursor-pointer" >
6379 { user ? (
64- < div className = "flex items-center cursor-pointer" >
65- < img src = { user . photoURL } alt = "Profile" className = "h-6 w-6 rounded-full mr-2" />
66- < button
67- onClick = { handleSignOut }
68- className = "flex items-center justify-center w-full h-full curspor-pointer" >
69- Sign out
70- </ button >
71- </ div >
80+ < button
81+ onClick = { handleSignOut }
82+ className = "w-[120px] h-[44px] bg-[#003399] text-white rounded-full border border-[#000061] cursor-pointer hover:bg-[#001a4d] transition-all duration-200" >
83+ Sign out
84+ </ button >
7285 ) : (
7386 < button
7487 onClick = { handleSignIn }
75- className = "flex items-center justify-center w-full h-full cursor-pointer" >
88+ className = "w-auto min-w-[120px] h-[44px] bg-[#003399] text-white text-sm rounded- full border border-[#001a4d] cursor-pointer hover:bg-[#001a4d] transition-all duration-200 flex items-center justify-center px-4 " >
7689 Sign in with Google
7790 </ button >
7891 ) }
7992 </ div >
93+
94+ { user && (
95+ < img
96+ src = { user . photoURL }
97+ alt = "Profile"
98+ className = "w-[44px] h-[44px] rounded-full border border-[#000061]"
99+ />
100+ ) }
80101 </ div >
81102 </ div >
82103 ) ;
0 commit comments