Skip to content

Commit a67e813

Browse files
authored
Merge pull request #33 from oslabs-beta/yihe/modals-display
Yihe/modify Navbar
2 parents 35aaf89 + f2e5fdd commit a67e813

File tree

2 files changed

+70
-72
lines changed

2 files changed

+70
-72
lines changed

src/components/DBDisplay/FeatureTab.tsx

Lines changed: 5 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// React & React Router & React Query Modules
2-
import React, { useState, useRef, useEffect } from 'react';
2+
import React, { useState, useRef } from 'react';
33
import axios, { AxiosResponse } from 'axios';
44
import { NavLink, useNavigate } from 'react-router-dom';
55
import { useNavStore } from '../../store/navStore';
@@ -15,7 +15,6 @@ import useSettingsStore from '../../store/settingsStore';
1515
import useCredentialsStore from '../../store/credentialsStore';
1616
//import icon
1717
import {
18-
HomeIcon,
1918
ConnectDatabaseIcon,
2019
UploadSQLFileIcon,
2120
ExportQueryIcon,
@@ -53,9 +52,9 @@ export default function FeatureTab(props: any) {
5352
const { schemaStore, setSchemaStore, undoHandler, redoHandler } = useSchemaStore(
5453
(state) => state
5554
);
56-
const { user, setUser } = useCredentialsStore((state: any) => state);
55+
const { user } = useCredentialsStore((state: any) => state);
5756

58-
const { setWelcome, isSchema, setDarkMode, darkMode, setDBName } = useSettingsStore(
57+
const { setWelcome, isSchema, setDBName } = useSettingsStore(
5958
(state) => state
6059
);
6160
const [action, setAction] = useState(new Array());
@@ -301,27 +300,13 @@ export default function FeatureTab(props: any) {
301300
}
302301
};
303302

304-
// Clears session + reset store
305-
const signoutSession = async () => {
306-
await fetch(`/api/logout`);
307-
window.open('/', '_self');
308-
setSchemaStore({});
309-
setUser(null);
310-
};
311-
312-
//Toggle function for DarkMode
313-
const toggleClass = (): void => {
314-
const page = document.getElementById('body');
315-
page!.classList.toggle('dark');
316-
setDarkMode();
317-
};
318303
// END: HELPER FUNCTIONS
319304

320305
return (
321306
<>
322307
{/* PAGE */}
323308
{/* MODAL FOR CONFIRMATION POPUP */}
324-
{/* dbSpy 8.0: move confirmModal out from FeatureTab */}
309+
{/* dbSpy 8.0: move confirmModal to show on whole page */}
325310
<div
326311
ref={confirmModal}
327312
id="confirmModal"
@@ -352,7 +337,7 @@ export default function FeatureTab(props: any) {
352337
</div>
353338
{/* dbSpy 8.0: added toggle button in Navbar to control FeatureTab */}
354339
<div
355-
className={`bg-blue fixed left-0 top-12 z-10 h-full w-64 transition-transform duration-300 ${
340+
className={`bg-blue fixed left-0 top-8 z-10 h-full w-64 transition-transform duration-300 ${
356341
toggleClicked ? '-translate-x-full' : 'translate-x-0'
357342
}`}
358343
>
@@ -362,28 +347,6 @@ export default function FeatureTab(props: any) {
362347
aria-label="FeatureTab"
363348
>
364349
<div className="menuBar light:bg-sky-800 overflow-auto rounded px-5 py-6 transition-colors duration-500">
365-
<button onClick={toggleClass}>
366-
<div className="ItemLink group inline-flex h-10 w-[160px] items-center justify-start gap-0 rounded-lg py-2 pl-0 pr-0">
367-
<svg
368-
fill="none"
369-
viewBox="0 0 24 24"
370-
strokeWidth="1.0"
371-
stroke="currentColor"
372-
className=" ml-2 mr-2 h-[24] stroke-current text-gray-500 group-hover:text-yellow-500 dark:text-[#f8f4eb] dark:group-hover:text-yellow-300"
373-
xmlns="http://www.w3.org/2000/svg"
374-
>
375-
<path
376-
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"
377-
strokeWidth="2"
378-
strokeLinecap="round"
379-
strokeLinejoin="round"
380-
/>
381-
</svg>
382-
<span className="DarkMode text-sm font-normal leading-normal text-gray-900 group-hover:text-yellow-500 group-hover:underline dark:text-[#f8f4eb] dark:group-hover:text-yellow-300 ">
383-
{darkMode === true ? 'Light' : 'Dark'} Mode
384-
</span>
385-
</div>
386-
</button>
387350
{/* ConnectDB code */}
388351
<p className=" mt-4 text-slate-900 dark:text-[#f8f4eb]">Connect</p>
389352
<hr />
@@ -570,17 +533,6 @@ export default function FeatureTab(props: any) {
570533
<span className="ml-3 flex-1 whitespace-nowrap">Delete Database</span>
571534
</a>
572535
</li>
573-
{user ? (
574-
<li>
575-
<a
576-
onClick={() => signoutSession()}
577-
className="group flex cursor-pointer items-center rounded-lg p-2 text-sm font-normal text-gray-900 hover:text-yellow-500 hover:underline dark:text-[#f8f4eb] dark:hover:text-yellow-300"
578-
>
579-
<SignOutIcon />
580-
<span className="ml-3 flex-1 whitespace-nowrap">Sign Out</span>
581-
</a>
582-
</li>
583-
) : null}
584536
</ul>
585537
</div>
586538
</div>

src/components/Navbar.tsx

Lines changed: 65 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React, { useState, useEffect } from 'react';
22
import { NavLink } from 'react-router-dom';
3+
import useSchemaStore from '../store/schemaStore';
34
import useCredentialsStore from '../store/credentialsStore';
5+
import useSettingsStore from '../store/settingsStore';
46
import logo from '../assets/newLogoWhite.png';
57
import login from '../assets/right-to-bracket-solid.svg';
68
import default_pfp from '../assets/default_pfp.svg';
@@ -25,16 +27,20 @@ import logo10 from '../assets/newLogoWhite_color10.png';
2527
import logo11 from '../assets/newLogoWhite_color11.png';
2628
import logo12 from '../assets/newLogoWhite_color12.png';
2729

30+
import { SignOutIcon } from '../FeatureTabIcon';
31+
2832
const linkbtn = 'inline-block text-white hover:text-white mr-4';
2933

3034
function Navbar() {
3135
// dbSpy 8.0: removed theme state and add state for the animated logo
3236
const [currentLogo, setCurrentLogo] = useState<string>(logo);
3337
const toggleClicked = useNavStore((state) => state.toggleClicked);
3438
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);
3642
//STATE DECLARATION (dbSpy3.0)
37-
const { user } = useCredentialsStore((state): any => state);
43+
const { user, setUser } = useCredentialsStore((state): any => state);
3844
//END: STATE DECLARATION
3945

4046
// dbSpy 8.0: made logo animation sparkling in the navbar
@@ -67,10 +73,25 @@ function Navbar() {
6773
return () => clearInterval(interval); // Cleanup on unmount
6874
}, []);
6975

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+
7091
return (
7192
<>
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">
7495
{/* dbSpy 8.0: added toggle button to control FeatureTab */}
7596
<img
7697
className="w-[25px] shrink-0 filter transition-transform duration-200 hover:translate-y-[-2px] hover:cursor-pointer"
@@ -80,38 +101,63 @@ function Navbar() {
80101
/>
81102

82103
{/* 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" />
84105

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">
86107
<NavLink to="/" className={`${linkbtn} flex items-center`}>
87108
Home
88109
</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+
>
90115
Display
91116
</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>
92139
</div>
93140
</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">
95142
{user ? (
96143
<>
97144
{/* inline-block: behave like an inline element but allows width and height modifications */}
98145
{/* pt: padding to top, dark:text-white: change text color to white in dark mode */}
99146
{/* 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>
103148
{/* 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>
108157
</>
109158
) : (
110159
<>
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">
115161
Login
116162
</NavLink>
117163
<img className="h-[20px] w-[20px] invert" src={login} />

0 commit comments

Comments
 (0)