Skip to content

Commit c0766c3

Browse files
Yihe LiuYihe Liu
authored andcommitted
update structure of code
1 parent f5e4d80 commit c0766c3

File tree

3 files changed

+25
-54
lines changed

3 files changed

+25
-54
lines changed

src/components/DBDisplay/FeatureTab.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import useSchemaStore from '../../store/schemaStore';
1515
import useFlowStore from '../../store/flowStore';
1616
import useSettingsStore from '../../store/settingsStore';
1717
import useCredentialsStore from '../../store/credentialsStore';
18+
1819
//import icon
1920
import {
2021
ConnectDatabaseIcon,

src/components/Navbar.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
1+
// *components inside Navbar
2+
// React & React Router & React Query Modules;
13
import React, { useState, useEffect } from 'react';
24
import { NavLink } from 'react-router-dom';
5+
6+
//-- State Stores Imports;
37
import useSchemaStore from '../store/schemaStore';
48
import useCredentialsStore from '../store/credentialsStore';
59
import useSettingsStore from '../store/settingsStore';
610
import logo from '../assets/newLogoWhite.png';
711
import login from '../assets/right-to-bracket-solid.svg';
812
import default_pfp from '../assets/default_pfp.svg';
13+
import { SignOutIcon } from '../FeatureTabIcon';
914

1015
// dbSpy 8.0: add icons for toggle button to control FeatureTab
16+
//-- Sidebar Toggle Icons
1117
import sidebarOpen from '../assets/sidebarOpen.svg';
1218
import sidebarClose from '../assets/sidebarClose.svg';
1319
import sidebarOpenBlack from '../assets/sidebarOpenBlack.svg';
1420
import sidebarCloseBlack from '../assets/sidebarCloseBlack.svg';
1521
import { useNavStore } from '../store/navStore';
1622

23+
// dbSpy 8.0: moved logo animation from FeatureTab to Navbar
1724
// Images for logo animation db 7.0
18-
// dbSpy 8.0: moved logo animation from FeatureTab to Navbar and only kept light version logo
1925
import logo1 from '../assets/newLogoWhite_color1.png';
2026
import logo2 from '../assets/newLogoWhite_color2.png';
2127
import logo3 from '../assets/newLogoWhite_color3.png';
@@ -42,8 +48,6 @@ import darkLogo10 from '../assets/newLogoBlack_color10.png';
4248
import darkLogo11 from '../assets/newLogoBlack_color11.png';
4349
import darkLogo12 from '../assets/newLogoBlack_color12.png';
4450

45-
import { SignOutIcon } from '../FeatureTabIcon';
46-
4751
const linkbtn =
4852
' flex items-center text-[#210d10] hover:text-yellow-500 dark:text-[#f8f4eb] dark:hover:text-yellow-300 inline-block mr-3';
4953

src/pages/DBDisplay.tsx

Lines changed: 17 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
11
//* main dashboard page
22
// React & React Router & React Query Modules;
3-
import React, { useRef, useEffect, useState } from 'react';
3+
import React, { useRef, useEffect } from 'react';
44

5-
// Dashboard Components Imported;
5+
//-- Dashboard Components Imported;
66
import Sidebar from '../components/DBDisplay/Sidebar';
77
import FeatureTab from '../components/DBDisplay/FeatureTab';
88
import AddReference from '../components/DBDisplay/AddReference';
99
import Flow from '../components/ReactFlow/Flow';
1010
import DataFlow from '../components/ReactFlow/DataFlow';
11+
1112
//-- Modals (pop ups) Components Imports;
1213
import InputModal from '../components/Modals/InputModal';
1314
import DataInputModal from '../components/Modals/DataInputModal';
1415
import DbNameInput from '../components/Modals/DbNameInput';
1516
import LoadDbModal from '../components/Modals/LoadDbModal';
1617
import DeleteDbModal from '../components/Modals/DeleteDbModal';
1718
import DeleteTableModal from '../components/Modals/DeleteTableModal';
19+
import { useModalStore } from '../store/useModalStore';
20+
import { accountModalStore } from '../store/accountModalStore';
21+
import QueryModal from '../components/Modals/QueryModal';
22+
1823
//-- State Stores Imports;
1924
import useCredentialsStore from '../store/credentialsStore';
2025
import useSettingsStore from '../store/settingsStore';
21-
22-
import { useModalStore } from '../store/useModalStore';
23-
import { accountModalStore } from '../store/accountModalStore';
2426
import useSchemaStore from '../store/schemaStore';
2527
import useDataStore from '../store/dataStore';
28+
2629
import axios, { AxiosResponse } from 'axios';
2730

28-
import QueryModal from '../components/Modals/QueryModal';
31+
2932

3033
const DBDisplay: React.FC = () => {
3134
const { setUser } = useCredentialsStore();
@@ -49,18 +52,6 @@ const DBDisplay: React.FC = () => {
4952
setDBName,
5053
} = useSettingsStore((state) => state);
5154

52-
// Input Modal state and handlers
53-
type InputModalState = {
54-
isOpen: boolean;
55-
mode: 'table' | 'column';
56-
tableName?: string;
57-
};
58-
//-- helper functions to open specific modals
59-
const openAddTableModal = () => setInputModalState(true, 'table');
60-
const openDeleteTableModal = () => setDeleteTableModalState(true);
61-
62-
// Zustand state management to handle authentication
63-
const { user } = useCredentialsStore((state): any => state);
6455
// dbSpy8.0: Zustand state managemant to handle modals under Account
6556
const { closeQueryModal, queryModalOpened } = useModalStore();
6657
const {
@@ -74,8 +65,11 @@ const DBDisplay: React.FC = () => {
7465
} = accountModalStore();
7566
const { schemaStore, setSchemaStore } = useSchemaStore((state: any) => state);
7667
const { dataStore, setDataStore } = useDataStore((state: any) => state);
77-
// useRef() create a reference to DOM elements
78-
//create references for HTML elements
68+
69+
//-- helper functions to open specific modals
70+
const openAddTableModal = () => setInputModalState(true, 'table');
71+
const openDeleteTableModal = () => setDeleteTableModalState(true);
72+
7973
// mySideBarId is the reference to the sidebar
8074
const mySideBarId: any = useRef();
8175
// mainId is the reference to the main content
@@ -127,37 +121,9 @@ const DBDisplay: React.FC = () => {
127121
message: 'Unable to login with OAuth.',
128122
});
129123
});
130-
// }
131-
// send POST request to /api/oauth with code/state
132-
fetch('/api/oauth', {
133-
method: 'POST',
134-
headers: {
135-
'Content-Type': 'Application/JSON',
136-
},
137-
body: JSON.stringify({ code: code, state: state }),
138-
})
139-
.then((data) => {
140-
// successful codes
141-
if (data.status >= 200 && data.status < 300) {
142-
// convert response to JSON
143-
return data.json();
144-
} else
145-
throw new Error(`Continue with OAuth failed with status code: ${data.status}`);
146-
})
147-
.then((res) => {
148-
// update the state with user data
149-
setUser(res);
150-
})
151-
.catch((err) => {
152-
console.log({
153-
log: `There was an error completing OAuth request: ${err}`,
154-
status: err,
155-
message: 'Unable to login with OAuth.',
156-
});
157-
});
158-
// }
159124
}, []);
160125

126+
// ****** dbSpy8.0: move from FeatureTab to Display page ******
161127
// for the sidebar of Add table
162128
/* Set the width of the side navigation to 400px and add a right margin of 400px */
163129
const openNav = () => {
@@ -183,7 +149,7 @@ const DBDisplay: React.FC = () => {
183149
openNav();
184150
}
185151
}
186-
// dbSpy8.0: move from FeatureTab to Display page
152+
187153
// Function for saving databases. Reworked for multiple saves - dbspy 7.0
188154
const saveSchema = (inputName: string): void => {
189155
//check to see if a table is present in the schemaStore
@@ -273,6 +239,7 @@ const DBDisplay: React.FC = () => {
273239
}
274240
setDeleteDbModalClose();
275241
};
242+
// ******* End moving from FeatureTab ******
276243

277244
return (
278245
<>
@@ -297,7 +264,6 @@ const DBDisplay: React.FC = () => {
297264
{/* <!-- Add all page content inside this div if you want the side nav to push page content to the right (not used if you only want the sidenav to sit on top of the page --> */}
298265
{/* mx-auto: center the div horizontally, transition-colors: enable smooth color transitions, duration-500: set transition duration to 0.5s */}
299266
<div ref={mainId} id="main" className="mx-auto transition-colors duration-500">
300-
{/* <div>"Current Database Name:"</div> */}
301267
{/* relative: positions relative to its normal location, right-[142px]: move 142px to left */}
302268
{/* m-auto = margin: auto in CSS */}
303269
{/* w-50%: set width to 50% of parent, flex-col: stack children vertically */}

0 commit comments

Comments
 (0)