Skip to content

Commit 194185c

Browse files
authored
Merge pull request #4 from oslabs-beta/stateUpdate
State update
2 parents 5f874ce + 70ff8d0 commit 194185c

4 files changed

Lines changed: 6 additions & 3 deletions

File tree

app/components/ApplicationsCard/ApplicationsCard.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const ApplicationsCard = (props) => {
4545
setAppIndex(i);
4646
setApp(selectedApp);
4747
setServicesData([]);
48+
//When we open the service modal a connection is made to the db in a useEffect inside of the service modal component
4849
setModal({isOpen:true,type:'serviceModal'})
4950
}
5051
}

app/containers/MainContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useContext } from 'react';
1+
import React, { useContext,useState } from 'react';
22
import { Route, Routes } from 'react-router-dom';
33
import About from '../components/About';
44
import Contact from '../components/Contact';

app/context/ApplicationContext.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ const ApplicationContextProvider: React.FC<AppContextProps> = React.memo(props =
4141
// console.log('app when fetch services name: ', application);
4242
ipcRenderer.send('servicesRequest');
4343
ipcRenderer.on('servicesResponse', (event: Electron.Event, data: any) => {
44+
//data here refers to the data coming the services document of the database
4445
let result: any;
4546
result = JSON.parse(data);
4647
console.log('result from ipcrenderer services response is: ', result);
4748
// console.log('Calling setServicesData passing in above result. Current servicesData is the following: ', servicesData);
4849
setServicesData(result);
49-
// console.log('Leaving fetchedServicesNames function.');
5050
ipcRenderer.removeAllListeners('servicesResponse');
5151
});
5252

@@ -61,6 +61,7 @@ const ApplicationContextProvider: React.FC<AppContextProps> = React.memo(props =
6161
*/
6262
const connectToDB = useCallback((username: string, index: number, application: string, URI: string, databaseType: string) => {
6363
console.log('Hi, inside ApplicationContext, connectToDB function was invoked.');
64+
/* ipcRenderer is referring to electron. The connect string is processed in data.ts inside of the electron folder at the root of the project */
6465
ipcRenderer.removeAllListeners('databaseConnected');
6566
ipcRenderer.send('connect', username, index, URI, databaseType);
6667
ipcRenderer.on('databaseConnected', (event: Electron.Event, data: any) => {

app/modals/ServicesModal.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const ServicesModal: React.FC<ServicesModalProps> = React.memo(({ i, app }) => {
2626
const { user, applications } = useContext(DashboardContext);
2727
const { servicesData, connectToDB } = useContext(ApplicationContext);
2828
const [services, setServices] = useState<Array<string>>([]);
29+
const [ cardName,dbType,dbURI,description,serviceType ] = applications[i]
2930

3031
const toggleService = service => {
3132
if (services.includes(service)) {
@@ -42,7 +43,7 @@ const ServicesModal: React.FC<ServicesModalProps> = React.memo(({ i, app }) => {
4243
// adding database type to make connection and fetchServiceNames more efficient
4344
useEffect(() => {
4445
console.log('Hi, inside useEffect in ServicesModal. Calling connectToDB function.');
45-
connectToDB(user, i, app, applications[i][2], applications[i][1]);
46+
connectToDB(user, i, app, dbURI, dbType);
4647
}, [i]);
4748

4849

0 commit comments

Comments
 (0)