1
1
//* main dashboard page
2
2
// React & React Router & React Query Modules;
3
- import React , { useRef , useEffect , useState } from 'react' ;
3
+ import React , { useRef , useEffect } from 'react' ;
4
4
5
- // Dashboard Components Imported;
5
+ //-- Dashboard Components Imported;
6
6
import Sidebar from '../components/DBDisplay/Sidebar' ;
7
7
import FeatureTab from '../components/DBDisplay/FeatureTab' ;
8
8
import AddReference from '../components/DBDisplay/AddReference' ;
9
9
import Flow from '../components/ReactFlow/Flow' ;
10
10
import DataFlow from '../components/ReactFlow/DataFlow' ;
11
+
11
12
//-- Modals (pop ups) Components Imports;
12
13
import InputModal from '../components/Modals/InputModal' ;
13
14
import DataInputModal from '../components/Modals/DataInputModal' ;
14
15
import DbNameInput from '../components/Modals/DbNameInput' ;
15
16
import LoadDbModal from '../components/Modals/LoadDbModal' ;
16
17
import DeleteDbModal from '../components/Modals/DeleteDbModal' ;
17
18
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
+
18
23
//-- State Stores Imports;
19
24
import useCredentialsStore from '../store/credentialsStore' ;
20
25
import useSettingsStore from '../store/settingsStore' ;
21
-
22
- import { useModalStore } from '../store/useModalStore' ;
23
- import { accountModalStore } from '../store/accountModalStore' ;
24
26
import useSchemaStore from '../store/schemaStore' ;
25
27
import useDataStore from '../store/dataStore' ;
28
+
26
29
import axios , { AxiosResponse } from 'axios' ;
27
30
28
- import QueryModal from '../components/Modals/QueryModal' ;
31
+
29
32
30
33
const DBDisplay : React . FC = ( ) => {
31
34
const { setUser } = useCredentialsStore ( ) ;
@@ -49,18 +52,6 @@ const DBDisplay: React.FC = () => {
49
52
setDBName,
50
53
} = useSettingsStore ( ( state ) => state ) ;
51
54
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 ) ;
64
55
// dbSpy8.0: Zustand state managemant to handle modals under Account
65
56
const { closeQueryModal, queryModalOpened } = useModalStore ( ) ;
66
57
const {
@@ -74,8 +65,11 @@ const DBDisplay: React.FC = () => {
74
65
} = accountModalStore ( ) ;
75
66
const { schemaStore, setSchemaStore } = useSchemaStore ( ( state : any ) => state ) ;
76
67
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
+
79
73
// mySideBarId is the reference to the sidebar
80
74
const mySideBarId : any = useRef ( ) ;
81
75
// mainId is the reference to the main content
@@ -127,37 +121,9 @@ const DBDisplay: React.FC = () => {
127
121
message : 'Unable to login with OAuth.' ,
128
122
} ) ;
129
123
} ) ;
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
- // }
159
124
} , [ ] ) ;
160
125
126
+ // ****** dbSpy8.0: move from FeatureTab to Display page ******
161
127
// for the sidebar of Add table
162
128
/* Set the width of the side navigation to 400px and add a right margin of 400px */
163
129
const openNav = ( ) => {
@@ -183,7 +149,7 @@ const DBDisplay: React.FC = () => {
183
149
openNav ( ) ;
184
150
}
185
151
}
186
- // dbSpy8.0: move from FeatureTab to Display page
152
+
187
153
// Function for saving databases. Reworked for multiple saves - dbspy 7.0
188
154
const saveSchema = ( inputName : string ) : void => {
189
155
//check to see if a table is present in the schemaStore
@@ -273,6 +239,7 @@ const DBDisplay: React.FC = () => {
273
239
}
274
240
setDeleteDbModalClose ( ) ;
275
241
} ;
242
+ // ******* End moving from FeatureTab ******
276
243
277
244
return (
278
245
< >
@@ -297,7 +264,6 @@ const DBDisplay: React.FC = () => {
297
264
{ /* <!-- 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 --> */ }
298
265
{ /* mx-auto: center the div horizontally, transition-colors: enable smooth color transitions, duration-500: set transition duration to 0.5s */ }
299
266
< div ref = { mainId } id = "main" className = "mx-auto transition-colors duration-500" >
300
- { /* <div>"Current Database Name:"</div> */ }
301
267
{ /* relative: positions relative to its normal location, right-[142px]: move 142px to left */ }
302
268
{ /* m-auto = margin: auto in CSS */ }
303
269
{ /* w-50%: set width to 50% of parent, flex-col: stack children vertically */ }
0 commit comments