Skip to content

Commit a3763a6

Browse files
authored
Merge pull request #80 from CS3219-AY2324S1/add-timeout-matching-service
Add timeout matching service
2 parents b77c741 + 7e7dc5e commit a3763a6

File tree

3 files changed

+33
-30
lines changed

3 files changed

+33
-30
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: 27 additions & 3 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

3138

3239
const titleStyle = {
@@ -57,6 +64,7 @@ const MatchingForm = React.forwardRef(function MatchingForm() {
5764
const { user } = useAuth();
5865
const userEmail = user?.email;
5966
const [openSnackbar, setOpenSnackbar] = React.useState(false);
67+
const [snackbarMessage, setSnackbarMessage] = React.useState("");
6068

6169
const handleConnect = async () => {
6270
const preferences = {
@@ -73,6 +81,7 @@ const MatchingForm = React.forwardRef(function MatchingForm() {
7381
});
7482

7583
if (filteredQuestions.length === 0) {
84+
setSnackbarMessage("No questions match the selected difficulty and category.");
7685
setOpenSnackbar(true);
7786
return;
7887
}
@@ -138,6 +147,20 @@ const MatchingForm = React.forwardRef(function MatchingForm() {
138147
};
139148
}, [difficulty, category, userEmail, navigate]);
140149

150+
React.useEffect(() => {
151+
socket.on("noMatchFound", () => {
152+
console.log("Match Not Found");
153+
setIsMatching(false);
154+
setSnackbarMessage("No eligible match found within the given timeframe.");
155+
setOpenSnackbar(true);
156+
157+
});
158+
159+
return () => {
160+
socket.off("noMatchFound");
161+
};
162+
});
163+
141164
return (
142165
<Box sx={style}>
143166
<h2 style={titleStyle}>
@@ -188,6 +211,7 @@ const MatchingForm = React.forwardRef(function MatchingForm() {
188211
)}
189212

190213
<Snackbar
214+
style={snackbarStyle}
191215
open={openSnackbar}
192216
autoHideDuration={6000}
193217
onClose={() => setOpenSnackbar(false)}
@@ -198,7 +222,7 @@ const MatchingForm = React.forwardRef(function MatchingForm() {
198222
severity="warning"
199223
sx={{ width: "100%" }}
200224
>
201-
No questions match the selected difficulty and category.
225+
{snackbarMessage}
202226
</Alert>
203227
</Snackbar>
204228
</Box>

start_services.sh

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

0 commit comments

Comments
 (0)