Skip to content

Commit 774955b

Browse files
committed
fix1
1 parent 38ca268 commit 774955b

3 files changed

Lines changed: 152 additions & 151 deletions

File tree

src/pages/DashBoard.tsx

Lines changed: 128 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -6,149 +6,149 @@ import useLoadingDone from "../hooks/useLoadingDone";
66
import UserInviteModal from "../components/UserInviteModal";
77
import { cryptoUtils } from "../App";
88
import {
9-
getUserKeyStoreFromServerAndInitKeyStore,
10-
sendGroupKeyToServer,
9+
getUserKeyStoreFromServerAndInitKeyStore,
10+
sendGroupKeyToServer,
1111
} from "../utils/networkUtils";
1212
import useAuth from "../hooks/useAuth";
1313
import { _genRandomBuffer, genEncryptedMasterKey } from "easy-web-crypto";
1414

1515
interface User {
16-
userName: string;
17-
email: string;
18-
userId: string;
16+
userName: string;
17+
email: string;
18+
userId: string;
1919
}
2020

2121
type userInvites = {
22-
documentName: string;
23-
documentID: string;
24-
participantID: string;
25-
leaderID: string;
26-
preKeyBundle: string;
27-
entityID: string;
28-
entityKeyName: string;
22+
documentName: string;
23+
documentID: string;
24+
participantID: string;
25+
leaderID: string;
26+
preKeyBundle: string;
27+
entityID: string;
28+
entityKeyName: string;
2929
};
3030

3131
export default function DashBoard() {
32-
const [documentInvites, setDocumentInvites] = useState<any[]>([]);
33-
const [existingdocuments, setExistingDocuments] = useState<any[]>([]);
34-
const protectedAxios = useAxios();
35-
const navigate = useNavigate();
36-
const axios = useAxios();
37-
const auth = useAuth();
38-
// useEffect(() => {
39-
// console.log(auth.userData);
40-
// });
41-
useLoadingDone();
32+
const [documentInvites, setDocumentInvites] = useState<any[]>([]);
33+
const [existingdocuments, setExistingDocuments] = useState<any[]>([]);
34+
const protectedAxios = useAxios();
35+
const navigate = useNavigate();
36+
const axios = useAxios();
37+
const auth = useAuth();
38+
// useEffect(() => {
39+
// console.log(auth.userData);
40+
// });
41+
useLoadingDone();
4242

43-
const handleDocumentCreation: React.FormEventHandler<HTMLFormElement> = async (event) => {
44-
event.preventDefault();
45-
const documentName = event.target["documentName"].value;
46-
console.log(documentName);
47-
const data = await protectedAxios.post("/api/document", {
48-
documentName,
49-
});
50-
console.log("Document Created");
51-
const documentID: string = data.data;
52-
const groupKeys = await cryptoUtils.generateGroupKeys();
53-
await cryptoUtils.saveGroupKeysToIDB(groupKeys, documentID);
54-
await sendGroupKeyToServer(documentID, protectedAxios);
55-
navigate("/document/" + documentID, {
56-
replace: true,
57-
state: {
58-
documentName,
59-
newDocumentCreation: true,
60-
documentID,
61-
},
62-
});
63-
};
43+
const handleDocumentCreation: React.FormEventHandler<HTMLFormElement> = async (event) => {
44+
event.preventDefault();
45+
const documentName = event.target["documentName"].value;
46+
console.log(documentName);
47+
const data = await protectedAxios.post("/api/document", {
48+
documentName,
49+
});
50+
console.log("Document Created");
51+
const documentID: string = data.data;
52+
const groupKeys = await cryptoUtils.generateGroupKeys();
53+
await cryptoUtils.saveGroupKeysToIDB(groupKeys, documentID);
54+
await sendGroupKeyToServer(documentID, protectedAxios);
55+
navigate("/document/" + documentID, {
56+
replace: true,
57+
state: {
58+
documentName,
59+
newDocumentCreation: true,
60+
documentID,
61+
},
62+
});
63+
};
6464

65-
const handleNewDocumentJoining = async (documentInvite: userInvites) => {
66-
navigate("/document/" + documentInvite.documentID, {
67-
replace: true,
68-
state: {
69-
documentID: documentInvite.documentID,
70-
newDocumentJoin: true,
71-
existingDocumentJoin: false,
72-
documentInvite,
73-
},
74-
});
75-
};
76-
77-
const handleExistingDocumentJoining = async (documentID: string, documentName: string) => {
78-
navigate("/document/" + documentID, {
79-
replace: true,
80-
state: {
81-
documentName,
82-
documentID,
83-
newDocumentJoin: false,
84-
existingDocumentJoin: true,
85-
},
86-
});
87-
};
88-
const getExistingDocuments = async () => {
89-
const data = await protectedAxios.get("/api/document/existingdocuments");
90-
return data.data;
91-
};
65+
const handleNewDocumentJoining = async (documentInvite: userInvites) => {
66+
navigate("/document/" + documentInvite.documentID, {
67+
replace: true,
68+
state: {
69+
documentID: documentInvite.documentID,
70+
newDocumentJoin: true,
71+
existingDocumentJoin: false,
72+
documentInvite,
73+
},
74+
});
75+
};
9276

93-
const getDocumentInvites = async () => {
94-
const data = await protectedAxios.get("/api/document/invites");
95-
return data.data;
96-
};
77+
const handleExistingDocumentJoining = async (documentID: string, documentName: string) => {
78+
navigate("/document/" + documentID, {
79+
replace: true,
80+
state: {
81+
documentName,
82+
documentID,
83+
newDocumentJoin: false,
84+
existingDocumentJoin: true,
85+
},
86+
});
87+
};
88+
const getExistingDocuments = async () => {
89+
const data = await protectedAxios.get("/api/document/existingdocuments");
90+
return data.data;
91+
};
9792

98-
useEffect(() => {
99-
getDocumentInvites().then((data) => {
100-
setDocumentInvites(data);
101-
});
102-
getExistingDocuments().then((data) => {
103-
setExistingDocuments(data);
104-
});
93+
const getDocumentInvites = async () => {
94+
const data = await protectedAxios.get("/api/document/invites");
95+
return data.data;
96+
};
10597

106-
getUserKeyStoreFromServerAndInitKeyStore(
107-
auth.userData?.userID as string,
108-
axios
109-
);
110-
}, []);
98+
useEffect(() => {
99+
getDocumentInvites().then((data) => {
100+
setDocumentInvites(data);
101+
});
102+
getExistingDocuments().then((data) => {
103+
setExistingDocuments(data);
104+
});
111105

112-
return (
113-
<>
114-
<div>DashBoard</div>
115-
<form onSubmit={handleDocumentCreation}>
116-
<label>
117-
Document Name:
118-
<input type="text" name="documentName" />
119-
</label>
120-
<button type="submit">Create Document</button>
121-
</form>
122-
<br />
123-
<h1>Document Invites</h1>
124-
{documentInvites.map((invite: userInvites) => (
125-
<ul key={invite.entityID}>
126-
<li>
127-
{invite.documentName}
128-
<Button
129-
variant="primary"
130-
onClick={() => handleNewDocumentJoining(invite)}
131-
>
132-
Open
133-
</Button>
134-
</li>
135-
</ul>
136-
))}
137-
<br />
138-
<h1>Documents you have worked on: </h1>
139-
{existingdocuments.map((documentInfo: any) => (
140-
<ul key={documentInfo.documentID}>
141-
<li>
142-
{documentInfo.documentName}
143-
<Button
144-
variant="primary"
145-
onClick={() => handleExistingDocumentJoining(documentInfo.documentID, documentInfo.documentName)}
146-
>
147-
Open
148-
</Button>
149-
</li>
150-
</ul>
151-
))}
152-
</>
153-
);
106+
getUserKeyStoreFromServerAndInitKeyStore(
107+
auth.userData?.userID as string,
108+
axios
109+
);
110+
}, []);
111+
112+
return (
113+
<>
114+
<div>DashBoard</div>
115+
<form onSubmit={handleDocumentCreation}>
116+
<label>
117+
Document Name:
118+
<input type="text" name="documentName" />
119+
</label>
120+
<button type="submit">Create Document</button>
121+
</form>
122+
<br />
123+
<h1>Document Invites</h1>
124+
{documentInvites.map((invite: userInvites) => (
125+
<ul key={invite.entityID}>
126+
<li>
127+
{invite.documentName}
128+
<Button
129+
variant="primary"
130+
onClick={() => handleNewDocumentJoining(invite)}
131+
>
132+
Open
133+
</Button>
134+
</li>
135+
</ul>
136+
))}
137+
<br />
138+
<h1>Documents you have worked on: </h1>
139+
{existingdocuments.map((documentInfo: any) => (
140+
<ul key={documentInfo.documentID}>
141+
<li>
142+
{documentInfo.documentName}
143+
<Button
144+
variant="primary"
145+
onClick={() => handleExistingDocumentJoining(documentInfo.documentID, documentInfo.documentName)}
146+
>
147+
Open
148+
</Button>
149+
</li>
150+
</ul>
151+
))}
152+
</>
153+
);
154154
}

src/pages/LoginPage.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ export default function Login() {
4343
"user": user,
4444
"password": password
4545
});
46-
await getUserKeyStoreFromServerAndInitKeyStore(userData.data.userID, axios);
4746
userAuth.loginUser(userData.data);
47+
await getUserKeyStoreFromServerAndInitKeyStore(userData.data.userID, axios);
4848
}
4949
catch (error: any) {
5050

@@ -57,15 +57,15 @@ export default function Login() {
5757

5858
for (const paramError of paramErrorList) {
5959
switch (paramError.param) {
60-
case "user":
61-
setUserError(paramError.msg);
62-
break;
63-
case "password":
64-
setPasswordError(paramError.msg);
65-
break;
66-
default:
67-
errorHandler.addError(paramError.msg);
68-
break;
60+
case "user":
61+
setUserError(paramError.msg);
62+
break;
63+
case "password":
64+
setPasswordError(paramError.msg);
65+
break;
66+
default:
67+
errorHandler.addError(paramError.msg);
68+
break;
6969
}
7070
}
7171

src/pages/SignUpPage.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable indent */
12
import { Link } from "react-router-dom";
23
import { useState } from "react";
34
import useAuth from "../hooks/useAuth";
@@ -50,8 +51,8 @@ export default function SignUp() {
5051
"email": email,
5152
"password": password
5253
});
53-
sendPreKeyBundleAndUserKeyStoreToServer(userData.data, axios);
5454
userAuth.loginUser(userData.data);
55+
sendPreKeyBundleAndUserKeyStoreToServer(userAuth.userData?.userID as string, axios);
5556
}
5657
catch (error: any) {
5758

@@ -64,18 +65,18 @@ export default function SignUp() {
6465

6566
for (const paramError of paramErrorList) {
6667
switch (paramError.param) {
67-
case "username":
68-
setUsernameError(paramError.msg);
69-
break;
70-
case "email":
71-
setEmailError(paramError.msg);
72-
break;
73-
case "password":
74-
setPasswordError(paramError.msg);
75-
break;
76-
default:
77-
errorHandler.addError(paramError.msg);
78-
break;
68+
case "username":
69+
setUsernameError(paramError.msg);
70+
break;
71+
case "email":
72+
setEmailError(paramError.msg);
73+
break;
74+
case "password":
75+
setPasswordError(paramError.msg);
76+
break;
77+
default:
78+
errorHandler.addError(paramError.msg);
79+
break;
7980
}
8081
}
8182
}

0 commit comments

Comments
 (0)