1
- import React , { useState } from 'react'
2
- import Menu from '../assets/Menu'
3
- import logo from "../assets/ytLogo.png"
4
- import { Link } from 'react-router-dom' ;
5
- import { setSidebarExtendedValue } from '../redux/categorySlice' ;
6
- import { useNavigate } from 'react-router-dom' ;
7
- import { useDispatch , useSelector } from 'react-redux' ;
8
- import Stack from '@mui/material/Stack' ;
9
- import LinearProgress from '@mui/material/LinearProgress' ;
1
+ import React , { useState } from "react" ;
2
+ import Menu from "../assets/Menu" ;
3
+ import logo from "../assets/ytLogo.png" ;
4
+ import logoDark from "../assets/ytLogo-dark.png" ;
5
+
6
+ import { Link } from "react-router-dom" ;
7
+ import { setSidebarExtendedValue } from "../redux/categorySlice" ;
8
+ import { useNavigate } from "react-router-dom" ;
9
+ import { useDispatch , useSelector } from "react-redux" ;
10
+ import Stack from "@mui/material/Stack" ;
11
+ import LinearProgress from "@mui/material/LinearProgress" ;
12
+ import DarkModeButton from "./DarkModeButton" ;
10
13
11
14
function Navbar ( { sidebarExtended, setSidebarExtended } ) {
12
- const dispatch = useDispatch ( )
13
- const pageRoute = useNavigate ( )
14
- const [ searchValue , setSearchValue ] = useState ( "" )
15
+ const dispatch = useDispatch ( ) ;
16
+ const pageRoute = useNavigate ( ) ;
17
+ const [ searchValue , setSearchValue ] = useState ( "" ) ;
15
18
const { isLoading } = useSelector ( ( state ) => state . category ) ;
16
- const channelLoading = useSelector ( ( state ) => state . channel . isLoading )
17
- const videoLoading = useSelector ( ( state ) => state . video . isLoading )
18
- const searchLoading = useSelector ( ( state ) => state . search . isLoading )
19
-
19
+ const channelLoading = useSelector ( ( state ) => state . channel . isLoading ) ;
20
+ const videoLoading = useSelector ( ( state ) => state . video . isLoading ) ;
21
+ const searchLoading = useSelector ( ( state ) => state . search . isLoading ) ;
22
+ const { darkMode } = useSelector ( ( state ) => state . darkMode ) ;
20
23
21
24
const handleOnSubmit = ( e ) => {
22
- e . preventDefault ( )
23
- pageRoute ( `/search/${ searchValue } ` )
24
- e . target . value = " "
25
- }
25
+ e . preventDefault ( ) ;
26
+ pageRoute ( `/search/${ searchValue } ` ) ;
27
+ e . target . value = " " ;
28
+ } ;
29
+
26
30
return (
27
31
< >
28
- < div className = 'h-[50px] fixed z-10 bg-[#ffff] w-[100%]' >
29
- {
30
- videoLoading || channelLoading || isLoading || searchLoading ? < Stack sx = { { width : "100%" , color : "grey.500" } } spacing = { 2 } >
32
+ < div
33
+ className = { `h-[50px] fixed z-10 w-[100%] ${
34
+ darkMode ? "bg-dark text-white" : "bg-white"
35
+ } `}
36
+ >
37
+ { videoLoading || channelLoading || isLoading || searchLoading ? (
38
+ < Stack sx = { { width : "100%" , color : "grey.500" } } spacing = { 2 } >
31
39
< LinearProgress color = "error" />
32
- </ Stack > : ""
33
- }
40
+ </ Stack >
41
+ ) : (
42
+ ""
43
+ ) }
34
44
35
- < nav className = 'flex h-[60px] items-center space-x-2 lg:space-x-20 xl:space-x-64' >
36
- < div className = 'flex items-center space-x-4 ml-3 -mt-4 pl-2' >
37
- < button className = '' onClick = { ( ) => {
38
- dispatch ( setSidebarExtendedValue ( ! sidebarExtended ) )
39
- setSidebarExtended ( ! sidebarExtended )
40
- } } >
45
+ < nav className = "flex h-[60px] items-center space-x-2 lg:space-x-20 xl:space-x-64" >
46
+ < div className = "flex items-center space-x-4 ml-3 -mt-4 pl-2" >
47
+ < button
48
+ className = ""
49
+ onClick = { ( ) => {
50
+ dispatch ( setSidebarExtendedValue ( ! sidebarExtended ) ) ;
51
+ setSidebarExtended ( ! sidebarExtended ) ;
52
+ } }
53
+ >
41
54
< Menu />
42
-
43
55
</ button >
44
56
{ /* <button className='block sm:hidden' onClick={() => {
45
57
}}>
46
58
<Menu />
47
59
48
60
</button> */ }
49
- < Link to = '/' >
50
-
51
- < img className = 'w-32' src = { logo } alt = "" />
61
+ < Link to = "/" >
62
+ { darkMode ? (
63
+ < img className = "w-24 ml-4" src = { logoDark } alt = "" />
64
+ ) : (
65
+ < img className = "w-32" src = { logo } alt = "" />
66
+ ) }
52
67
</ Link >
53
-
54
68
</ div >
55
- < form onSubmit = { handleOnSubmit } className = ' -mt-3' >
69
+ < form onSubmit = { handleOnSubmit } className = " -mt-3" >
56
70
< div className = "relative w-[170px] sm:w-[420px] " >
57
- < input onChange = { ( e ) => setSearchValue ( e . target . value ) } type = "search" name = 'search' id = "default-search" className = "block p-2 pl-10 w-full text-sm text-gray-900 bg-gray-50 rounded-lg border-[1px] border-[#cccccc] focus:outline-none" placeholder = "Search" required />
58
- < button type = "submit" className = "text-white absolute right-0 bottom-0 top-0 font-medium text-sm px-4 py-2 bg-[#f8f8f8] border-[1px] border-[#cccccc]" > < svg className = "w-5 h-5 text-gray-500 dark:text-gray-400" fill = "none" stroke = "currentColor" viewBox = "0 0 24 24" xmlns = "http://www.w3.org/2000/svg" > < path strokeLinecap = "round" strokeLinejoin = "round" strokeWidth = "2" d = "M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" > </ path > </ svg >
71
+ < input
72
+ onChange = { ( e ) => setSearchValue ( e . target . value ) }
73
+ type = "search"
74
+ name = "search"
75
+ id = "default-search"
76
+ className = { `block p-2 pl-10 w-full text-sm text-gray-900 ${
77
+ darkMode ? "bg-dark" : "bg-gray-50"
78
+ } rounded-lg border-[1px] border-[#cccccc] focus:outline-none`}
79
+ placeholder = "Search"
80
+ required
81
+ />
82
+ < button
83
+ type = "submit"
84
+ className = { `text-white absolute right-0 bottom-0 top-0 font-medium text-sm px-4 py-2 ${
85
+ darkMode ? "bg-dark" : "bg-[#f8f8f8]"
86
+ } border-[1px] border-[#cccccc]`}
87
+ >
88
+ { " " }
89
+ < svg
90
+ className = "w-5 h-5 text-gray-500 dark:text-gray-400"
91
+ fill = "none"
92
+ stroke = "currentColor"
93
+ viewBox = "0 0 24 24"
94
+ xmlns = "http://www.w3.org/2000/svg"
95
+ >
96
+ < path
97
+ strokeLinecap = "round"
98
+ strokeLinejoin = "round"
99
+ strokeWidth = "2"
100
+ d = "M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"
101
+ > </ path >
102
+ </ svg >
59
103
</ button >
60
104
</ div >
61
105
</ form >
62
- </ nav >
63
106
107
+ < DarkModeButton />
108
+ </ nav >
64
109
</ div >
65
110
</ >
66
- )
111
+ ) ;
67
112
}
68
113
69
- export default Navbar
114
+ export default Navbar ;
0 commit comments