1
1
import React , { useState , useEffect } from 'react' ;
2
2
import { NavLink } from 'react-router-dom' ;
3
+ import useSchemaStore from '../store/schemaStore' ;
3
4
import useCredentialsStore from '../store/credentialsStore' ;
5
+ import useSettingsStore from '../store/settingsStore' ;
4
6
import logo from '../assets/newLogoWhite.png' ;
5
7
import login from '../assets/right-to-bracket-solid.svg' ;
6
8
import default_pfp from '../assets/default_pfp.svg' ;
@@ -25,16 +27,20 @@ import logo10 from '../assets/newLogoWhite_color10.png';
25
27
import logo11 from '../assets/newLogoWhite_color11.png' ;
26
28
import logo12 from '../assets/newLogoWhite_color12.png' ;
27
29
30
+ import { SignOutIcon } from '../FeatureTabIcon' ;
31
+
28
32
const linkbtn = 'inline-block text-white hover:text-white mr-4' ;
29
33
30
34
function Navbar ( ) {
31
35
// dbSpy 8.0: removed theme state and add state for the animated logo
32
36
const [ currentLogo , setCurrentLogo ] = useState < string > ( logo ) ;
33
37
const toggleClicked = useNavStore ( ( state ) => state . toggleClicked ) ;
34
38
const toggleNav = useNavStore ( ( state ) : any => state . toggleNav ) ;
35
- // toggleNav();
39
+ // dbSpy 8.0: move toggle button to control dark mode in Navbar
40
+ const { setDarkMode, darkMode } = useSettingsStore ( ( state ) => state ) ;
41
+ const { schemaStore, setSchemaStore } = useSchemaStore ( ( state : any ) => state ) ;
36
42
//STATE DECLARATION (dbSpy3.0)
37
- const { user } = useCredentialsStore ( ( state ) : any => state ) ;
43
+ const { user, setUser } = useCredentialsStore ( ( state ) : any => state ) ;
38
44
//END: STATE DECLARATION
39
45
40
46
// dbSpy 8.0: made logo animation sparkling in the navbar
@@ -67,10 +73,25 @@ function Navbar() {
67
73
return ( ) => clearInterval ( interval ) ; // Cleanup on unmount
68
74
} , [ ] ) ;
69
75
76
+ //Toggle function for DarkMode
77
+ const toggleClass = ( ) : void => {
78
+ const page = document . getElementById ( 'body' ) ;
79
+ page ! . classList . toggle ( 'dark' ) ;
80
+ setDarkMode ( ) ;
81
+ } ;
82
+
83
+ // Clears session + reset store
84
+ const signoutSession = async ( ) => {
85
+ await fetch ( `/api/logout` ) ;
86
+ window . open ( '/' , '_self' ) ;
87
+ setSchemaStore ( { } ) ;
88
+ setUser ( null ) ;
89
+ } ;
90
+
70
91
return (
71
92
< >
72
- < nav className = "fixed top-0 z-50 flex w-full flex-wrap items-center justify-between bg-opacity-80 bg-gradient-to-b from-sky-700 to-transparent p-3 backdrop-blur-md" >
73
- < div className = "navItems flex min-w-0 items-center gap-3 " >
93
+ < nav className = "fixed left-1 right-1 top-2 z-50 flex w-[calc(100%-2rem)] items-center overflow-x-auto justify-between rounded-2xl bg-opacity-80 bg-gradient-to-b from-blue-400 to-transparent p-3 backdrop-blur-md" >
94
+ < div className = "navItems flex flex-1 items-center text-[clamp(12px,1.2vw,16px)] min-w-0 items-center gap-2 " >
74
95
{ /* dbSpy 8.0: added toggle button to control FeatureTab */ }
75
96
< img
76
97
className = "w-[25px] shrink-0 filter transition-transform duration-200 hover:translate-y-[-2px] hover:cursor-pointer"
@@ -80,38 +101,63 @@ function Navbar() {
80
101
/>
81
102
82
103
{ /* Sparkling logo */ }
83
- < img className = "mr-3 h-[45px] w-auto shrink-0" src = { currentLogo } alt = "Logo" />
104
+ < img className = "h-[3.5vw] min-h-[30px] max- h-[45px] w-auto shrink-0" src = { currentLogo } alt = "Logo" />
84
105
85
- < div className = "flex min-w-0 items-center gap-2 overflow-hidden whitespace-nowrap" >
106
+ < div className = "flex min-w-0 items-center overflow-hidden whitespace-nowrap" >
86
107
< NavLink to = "/" className = { `${ linkbtn } flex items-center` } >
87
108
Home
88
109
</ NavLink >
89
- < NavLink to = "/display" data-testid = "navbar-display" className = { `${ linkbtn } flex items-center` } >
110
+ < NavLink
111
+ to = "/display"
112
+ data-testid = "navbar-display"
113
+ className = { `${ linkbtn } flex items-center` }
114
+ >
90
115
Display
91
116
</ NavLink >
117
+ < button onClick = { toggleClass } >
118
+ < div className = "ItemLink group inline-flex h-10 w-[160px] items-center justify-start gap-0 rounded-lg py-2 pl-0 pr-0" >
119
+ < svg
120
+ fill = "none"
121
+ viewBox = "0 0 24 24"
122
+ stroke-width = "1.0"
123
+ stroke = "currentColor"
124
+ className = " mr-1 h-[18] stroke-current text-gray-500 group-hover:text-yellow-500 dark:text-[#f8f4eb] dark:group-hover:text-yellow-300"
125
+ xmlns = "http://www.w3.org/2000/svg"
126
+ >
127
+ < path
128
+ d = "M1.50488 10.7569C1.50488 16.4855 6.14803 21.1294 11.8756 21.1294C16.2396 21.1294 19.974 18.4335 21.5049 14.616C20.3104 15.0962 19.0033 15.3668 17.6372 15.3668C11.9095 15.3668 7.26642 10.7229 7.26642 4.99427C7.26642 3.63427 7.53299 2.3195 8.00876 1.12939C4.19637 2.66259 1.50488 6.39536 1.50488 10.7569Z"
129
+ stroke-width = "2"
130
+ stroke-linecap = "round"
131
+ stroke-linejoin = "round"
132
+ />
133
+ </ svg >
134
+ < span className = "DarkMode font-normal leading-normal text-gray-900 group-hover:text-yellow-500 dark:text-[#f8f4eb] dark:group-hover:text-yellow-300 " >
135
+ { darkMode === true ? 'Light' : 'Dark' }
136
+ </ span >
137
+ </ div >
138
+ </ button >
92
139
</ div >
93
140
</ div >
94
- < div className = "flex items-center justify-end gap-2 " >
141
+ < div className = "flex items-center justify-end items-center text-[clamp(12px,1.2vw,16px)] gap-1 shrink-0 whitespace-nowrap " >
95
142
{ user ? (
96
143
< >
97
144
{ /* inline-block: behave like an inline element but allows width and height modifications */ }
98
145
{ /* pt: padding to top, dark:text-white: change text color to white in dark mode */ }
99
146
{ /* lg: large screens, mt-0: margin-top: 0, on lg mode */ }
100
- < span className = "text-blue-200" >
101
- { user . full_name }
102
- </ span >
147
+ < span className = "dark:text-[#f8f4eb]" > { user . full_name } </ span >
103
148
{ /* ml: margin left, mr: margin right, rounded-full: make the image circular, dark:invert: invert color in dark mode */ }
104
- < img
105
- className = "h-[25px] w-[25px] rounded-full invert"
106
- src = { default_pfp }
107
- />
149
+ < img className = "h-[clamp(18px,2.2vw,25px)] w-[clamp(18px,2.2vw,25px)] rounded-full invert" src = { default_pfp } />
150
+ < a
151
+ onClick = { ( ) => signoutSession ( ) }
152
+ className = "group flex cursor-pointer items-center rounded-lg font-normal text-gray-900 hover:text-yellow-500 dark:text-[#f8f4eb] dark:hover:text-yellow-300"
153
+ >
154
+ < SignOutIcon />
155
+ < span className = "flex-1 whitespace-nowrap" > Sign Out</ span >
156
+ </ a >
108
157
</ >
109
158
) : (
110
159
< >
111
- < NavLink
112
- to = "/login"
113
- className = "text-white text-base font-bold"
114
- >
160
+ < NavLink to = "/login" className = "text-base font-bold text-white" >
115
161
Login
116
162
</ NavLink >
117
163
< img className = "h-[20px] w-[20px] invert" src = { login } />
0 commit comments