Skip to content

Commit

Permalink
Move useEffect down to handle stale data
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabau committed Nov 13, 2023
1 parent d7142f6 commit 0832792
Showing 1 changed file with 37 additions and 34 deletions.
71 changes: 37 additions & 34 deletions src/pages/collab/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,40 +60,6 @@ const MatchRequestPage = () => {
};
});

useEffect(() => {
if (time === REQUEST_EXPIRY_TIME_SECS && curUserMatchRequest) {
const { difficulty, category, matchType } = curUserMatchRequest;
const sameRequest = { difficulty, category, matchType };
deleteMatchRequest({ matchType: curUserMatchRequest.matchType });
toast(
(t) => (
<div className="flex flex-col justify-evenly text-slate-800">
<span className="text-center mb-2">No requests found 🫠.</span>
<div className="flex justify-stretch">
<button
className="border bg-blue-500 rounded-md text-slate-100 p-2 mr-1"
onClick={() => {
toast.dismiss(t.id);
createMatchRequest(sameRequest);
}}
type="button"
>
Recreate again
</button>
<button
className="border bg-stone-500 rounded-md text-slate-100 p-2"
onClick={() => toast.dismiss(t.id)}
type="button"
>
Dismiss
</button>
</div>
</div>
),
{ duration: 60000, id: "timeout", position: "top-center" },
);
}
}, [time]);

const matchUsers = useMatchUsers();
const [isCreatingMatchRequest, setIsCreatingMatchRequest] = useState(false);
Expand Down Expand Up @@ -177,6 +143,43 @@ const MatchRequestPage = () => {
});
// subscprtions api -- END


useEffect(() => {
if (time >= REQUEST_EXPIRY_TIME_SECS && curUserMatchRequest) {
console.log(curUserMatchRequest);
const { difficulty, category, matchType } = curUserMatchRequest;
const sameRequest = { difficulty, category, matchType };
deleteMatchRequest({ matchType: curUserMatchRequest.matchType });
toast(
(t) => (
<div className="flex flex-col justify-evenly text-slate-800">
<span className="text-center mb-2">No requests found 🫠.</span>
<div className="flex justify-stretch">
<button
className="border bg-blue-500 rounded-md text-slate-100 p-2 mr-1"
onClick={() => {
toast.dismiss(t.id);
createMatchRequest(sameRequest);
}}
type="button"
>
Recreate again
</button>
<button
className="border bg-stone-500 rounded-md text-slate-100 p-2"
onClick={() => toast.dismiss(t.id)}
type="button"
>
Dismiss
</button>
</div>
</div>
),
{ duration: 60000, id: "timeout", position: "top-center" },
);
}
}, [time]);

useEffect(() => {
if (!curUserMatchRequest) {
if (intervalRef.current) {
Expand Down

0 comments on commit 0832792

Please sign in to comment.