Skip to content

Commit ded2b93

Browse files
authored
Merge pull request #9 from oslabs-beta/convertToDB
Convert to db
2 parents 7a02685 + cd9b855 commit ded2b93

File tree

17 files changed

+12661
-100
lines changed

17 files changed

+12661
-100
lines changed

app/components/Login.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ const Login = React.memo(() => {
2323
// eslint-disable-next-line no-return-assign
2424
// inputFields.forEach(input => (input.value = ''));
2525
const response: boolean | string = ipcRenderer.sendSync('login', { username, password });
26-
if (typeof(response) === 'string') {
26+
if (typeof (response) === 'string') {
27+
console.log('response', response)
2728
setUser(username);
2829
setMode(response);
2930
navigate('/');

app/components/SignUp.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@ const SignUp:React.FC = React.memo(() => {
4343

4444
ipcRenderer.invoke('addUser', { username, email, password})
4545
.then((message) => {
46-
if (message === true) {
47-
setUser(username);
48-
console.log(username)
49-
navigate('/');
50-
} else {
46+
console.log('message', message)
47+
if (message === false) {
5148
setFailedSignUp(<p>Sorry, your sign up failed. Please try a different username or email</p>)
49+
} else {
50+
console.log('in frontend', username)
51+
// setUser(username);
52+
navigate('/login');
53+
alert('USER CREATED: PLEASE LOG IN')
5254
}
5355
}).catch(error => {
5456
console.error('Failed to sign up:', error);
@@ -65,13 +67,13 @@ const SignUp:React.FC = React.memo(() => {
6567

6668
<form className="form" onSubmit={handleSubmit}>
6769
<label className="username">
68-
<input type="text" name="username" id="username" placeholder="enter username" />
70+
<input type="text" name="username" id="username" minLength={4} placeholder="enter username" />
6971
</label>
7072
<label className="email">
7173
<input type="email" name="email" id="email" placeholder="[email protected]" />
7274
</label>
7375
<label className="password">
74-
<input type="password" name="password" id="password" placeholder="enter password" />
76+
<input type="password" name="password" id="password" minLength={9} placeholder="enter password" />
7577
</label>
7678
<label className="passwordConfirm">
7779
<input type="password" name="passwordConfirm" id="passwordConfirm" placeholder="confirm password" />

app/components/Splash.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const Splash: React.FC = React.memo(props => {
55
const [visible, setVisible] = useState(true);
66

77
useEffect(() => {
8-
setTimeout(() => setVisible(false), 4000);
8+
setTimeout(() => setVisible(false), 1000);
99
}, []);
1010

1111
return (

app/context/ApplicationContext.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ const ApplicationContextProvider: React.FC<AppContextProps> = React.memo(props =
5353
});
5454
}, []);
5555

56-
const connectToDB = useCallback((username: string, index: number, application: string) => {
56+
const connectToDB = useCallback((username: string, index: number, application: string, URI: string) => {
5757
ipcRenderer.removeAllListeners('databaseConnected');
58-
ipcRenderer.send('connect', username, index);
58+
ipcRenderer.send('connect', username, index, URI);
5959

6060
ipcRenderer.on('databaseConnected', (event: Electron.Event, data: any) => {
6161
fetchServicesNames(application);

app/modals/ServicesModal.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ interface IService {
1818
}
1919

2020
const ServicesModal: React.FC<ServicesModalProps> = React.memo(({ i, app }) => {
21-
const { user } = useContext(DashboardContext)
21+
const { user, applications } = useContext(DashboardContext)
22+
console.log('hereerer', useContext(DashboardContext))
23+
console.log('aappp', applications[i][2])
2224
const { servicesData, connectToDB } = useContext(ApplicationContext);
2325
const [services, setServices] = useState<Array<string>>([]);
2426

@@ -32,7 +34,7 @@ const ServicesModal: React.FC<ServicesModalProps> = React.memo(({ i, app }) => {
3234
};
3335

3436
useEffect(() => {
35-
connectToDB(user, i, app);
37+
connectToDB(user, i, app, applications[i][2]);
3638
}, [i]);
3739

3840
return (

electron/databases/mongo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import mongoose from 'mongoose';
22
// import { MongoError } from 'mongodb';
33

44
// Mongoose connection wrapped in function that takes the index of the selected database as the parameter. This index is used to target the correct database for querying.
5-
const connectMongoose = async (URI: string) => {
5+
const connectMongoose = async (i:number, URI: string) => {
66
try {
77
await mongoose.connection.close();
88
const db = await mongoose.connect(URI);

0 commit comments

Comments
 (0)