Skip to content

Commit 3ac198a

Browse files
authored
Merge pull request #97 from CS3219-AY2324S1/matching-cancel
Matching cancel
2 parents 9d95347 + 4a0b8f6 commit 3ac198a

File tree

3 files changed

+57
-21
lines changed

3 files changed

+57
-21
lines changed
Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,52 @@
1-
import React from 'react';
2-
import {Oval} from 'react-loader-spinner';
3-
import './LoadPopup.css';
1+
import React, { useState, useEffect } from 'react';
2+
import { Oval } from 'react-loader-spinner';
3+
import axios from 'axios';
4+
import './LoadPopup.css';
45

5-
export const LoadPopup= ({isOpen, isClose}) => {
6-
if (isOpen) {
7-
return (
8-
<div className="load-overlay">
9-
<div className="load-popup">
10-
<h3>Finding you a match...</h3>
11-
<div className="spinner">
12-
<Oval className = "spinner"/>
13-
</div>
14-
<div >
15-
<button onClick={isClose} className="cancel-match">Cancel Matching</button>
16-
</div>
17-
</div>
18-
</div>
19-
);
20-
}
6+
export const LoadPopup = ({ isOpen, isClose, userId, onMatchCancelled }) => {
7+
const [buttonEnabled, setButtonEnabled] = useState(false);
8+
9+
useEffect(() => {
10+
setButtonEnabled(false);
11+
const timer = setTimeout(() => {
12+
setButtonEnabled(true);
13+
}, 5000);
14+
15+
return () => clearTimeout(timer);
16+
}, [isOpen]);
17+
18+
const handleCancelMatching = () => {
19+
setButtonEnabled(false);
20+
21+
const URL = `http://localhost:3004/home/${userId}/matching`;
22+
axios.delete(URL)
23+
.then(response => {
24+
if (response.status !== 200) {
25+
throw new Error(response.data.message);
26+
}
27+
console.log(response.data.message);
28+
onMatchCancelled(); // Inform the parent component that the match is cancelled
29+
})
30+
.catch(error => {
31+
console.error("Error canceling the match: ", error);
32+
setButtonEnabled(true);
33+
})
34+
};
35+
36+
if (isOpen) {
37+
return (
38+
<div className="load-overlay">
39+
<div className="load-popup">
40+
<h3>Finding you a match...</h3>
41+
<div className="spinner">
42+
<Oval className="spinner"/>
43+
</div>
44+
<div>
45+
<button onClick={handleCancelMatching} disabled={!buttonEnabled} className="cancel-match">Cancel Matching</button>
46+
</div>
47+
</div>
48+
</div>
49+
);
50+
}
51+
return null;
2152
};

Frontend/src/Components/Matching/MatchPopup.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ const MatchPopup = ({ isOpen, isClose }) => {
2020
const [chosenProficiency, setChosenProficiency] = useState("None");
2121
const [chosenTopic, setChosenTopic] = useState("None");
2222

23+
const handleMatchCancellation = () => {
24+
setGoToLoadPopup(false);
25+
setShowNotSuccessOutput(true);
26+
};
27+
2328
const initiateMatching = () => {
2429

2530
// Show the loading popup
@@ -121,7 +126,7 @@ const MatchPopup = ({ isOpen, isClose }) => {
121126
</div>
122127
<button className="match-button" onClick={initiateMatching}>Match</button>
123128
</div>
124-
{goToLoadPopup && <LoadPopup isOpen={true} isClose={() => setGoToLoadPopup(false)} />}
129+
{goToLoadPopup && <LoadPopup isOpen={true} isClose={() => setGoToLoadPopup(false)} userId={getUserId()} onMatchCancelled={handleMatchCancellation} />}
125130

126131
{showSuccessOutput &&
127132
<SuccessOutput isOpen={true} isClose={() => setShowSuccessOutput(false)} />}

Frontend/src/Components/Matching/NotSuccessOutput.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const NotSuccessOutput = ({ isOpen, isClose }) => {
77
return (
88
<div className="output-overlay">
99
<div className="output-popup">
10-
<h3>Not Match Found!</h3>
10+
<h3>No Match Found!</h3>
1111
<img src={error_icon} className="image" alt="Error icon" />
1212
<p>Try Again!</p>
1313
<div>

0 commit comments

Comments
 (0)