Skip to content

Commit 050ff29

Browse files
committed
2 parents 943e421 + a3763a6 commit 050ff29

File tree

3 files changed

+39
-32
lines changed

3 files changed

+39
-32
lines changed

MatchingService/src/matching/matching.service.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export function initializeMatchingService(io: Server) {
5454
user.preferences.category === category
5555
);
5656
});
57-
57+
let timeoutId: NodeJS.Timeout;
5858
if (matchedUser) {
5959
// Remove both users from the active list
6060
removeUserFromActiveList(socket);
@@ -64,6 +64,11 @@ export function initializeMatchingService(io: Server) {
6464
socket.emit('matchFound', {matchedUserPreferences: matchedUser.preferences, seed: randomSeed});
6565
matchedUser.socket.emit('matchFound', {matchedUserPreferences: preferences, seed: randomSeed});
6666
} else {
67+
68+
timeoutId = setTimeout(() => {
69+
socket.emit('noMatchFound');
70+
removeUserFromActiveList(socket);
71+
}, 30000);
6772
// Handle the case when no match is found for the user
6873
// You can emit a "noMatchFound" event or handle it differently
6974
}

frontend/src/components/MatchingService/MatchingForm.tsx

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,23 @@ const style = {
1717
transform: "translate(-50%, -50%)",
1818
width: "50%",
1919
display: "flex-wrap",
20-
maxHeight: "60%",
20+
// Remove or adjust the maxHeight value
21+
//maxHeight: "60%",
2122
justifyContent: "center",
2223
textAlign: "center",
2324
bgcolor: "background.paper",
2425
border: "2px solid #000",
2526
boxShadow: 24,
26-
overflow: "auto",
2727
p: 4,
2828
};
2929

30+
const snackbarStyle = {
31+
position: "absolute" as "absolute",
32+
top: 3,
33+
left: "50%",
34+
transform: "translate(-50%, 0)",
35+
};
36+
3037
const titleStyle = {
3138
fontSize: "2rem", // Increase the title size
3239
};
@@ -53,6 +60,7 @@ const MatchingForm = React.forwardRef(function MatchingForm() {
5360
const { user } = useAuth();
5461
const userEmail = user?.email;
5562
const [openSnackbar, setOpenSnackbar] = React.useState(false);
63+
const [snackbarMessage, setSnackbarMessage] = React.useState("");
5664

5765
const handleConnect = async () => {
5866
const preferences = {
@@ -69,6 +77,9 @@ const MatchingForm = React.forwardRef(function MatchingForm() {
6977
});
7078

7179
if (filteredQuestions.length === 0) {
80+
setSnackbarMessage(
81+
"No questions match the selected difficulty and category."
82+
);
7283
setOpenSnackbar(true);
7384
return;
7485
}
@@ -121,8 +132,11 @@ const MatchingForm = React.forwardRef(function MatchingForm() {
121132
const matchedUser = matchedUserPreferences.matchedUserPreferences;
122133
setIsMatching(false);
123134
const qId = await getQuestions(seed);
124-
const hashedEmailOne = sha256(userEmail || "");
125-
const hashedEmailTwo = sha256(matchedUser.userEmail);
135+
const emails = [userEmail, matchedUser.userEmail].sort();
136+
137+
// Hash the sorted emails
138+
const hashedEmailOne = sha256(emails[0]);
139+
const hashedEmailTwo = sha256(emails[1]);
126140
navigate(`/collab/question/${qId}/${hashedEmailOne}/${hashedEmailTwo}`);
127141
});
128142

@@ -132,6 +146,19 @@ const MatchingForm = React.forwardRef(function MatchingForm() {
132146
// eslint-disable-next-line react-hooks/exhaustive-deps
133147
}, [difficulty, category, userEmail, navigate]);
134148

149+
React.useEffect(() => {
150+
socket.on("noMatchFound", () => {
151+
console.log("Match Not Found");
152+
setIsMatching(false);
153+
setSnackbarMessage("No eligible match found within the given timeframe.");
154+
setOpenSnackbar(true);
155+
});
156+
157+
return () => {
158+
socket.off("noMatchFound");
159+
};
160+
});
161+
135162
return (
136163
<Box sx={style}>
137164
<h2 style={titleStyle}>
@@ -186,6 +213,7 @@ const MatchingForm = React.forwardRef(function MatchingForm() {
186213
)}
187214

188215
<Snackbar
216+
style={snackbarStyle}
189217
open={openSnackbar}
190218
autoHideDuration={6000}
191219
onClose={() => setOpenSnackbar(false)}
@@ -196,7 +224,7 @@ const MatchingForm = React.forwardRef(function MatchingForm() {
196224
severity="warning"
197225
sx={{ width: "100%" }}
198226
>
199-
No questions match the selected difficulty and category.
227+
{snackbarMessage}
200228
</Alert>
201229
</Snackbar>
202230
</Box>

start_services.sh

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)