Challenging and room creating working now
This commit is contained in:
@@ -23,9 +23,11 @@ router.post("/create", checkAuth, async (req, res, next) => {
|
||||
let challenges = pendingChallenges.get(challenged);
|
||||
challenges.push(challenger);
|
||||
} else {
|
||||
pendingChallenges.set(challenged, [challenger]);
|
||||
pendingChallenges.set(challenged, [{ challenger, roomID }]);
|
||||
}
|
||||
|
||||
console.log("Pending challenges", pendingChallenges);
|
||||
|
||||
// sendEmail(
|
||||
// challengedEmail,
|
||||
// `Challenge from ${challenger}`,
|
||||
|
||||
@@ -37,6 +37,7 @@ router.get("/:username/challenges", async (req, res, next) => {
|
||||
let username = req.params.username;
|
||||
let challenges = pendingChallenges.get(username);
|
||||
if (!challenges) challenges = [];
|
||||
console.log(username,challenges);
|
||||
res.json({ success: true, challenges: challenges });
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Button, Group, Stack, Text, Title } from '@mantine/core';
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { getUserData } from '../../utils/auth'
|
||||
|
||||
const Challenges = () => {
|
||||
const navigate = useNavigate();
|
||||
@@ -8,14 +9,15 @@ const Challenges = () => {
|
||||
{ challenger: 'moonpatel', roomID: 'sgnkjsdbnojsnvjsdnkl' },
|
||||
{ challenger: 'user1', roomID: 'sgnkjsdbnojsnvjsdnkl' }
|
||||
]
|
||||
const [challenges, setChallenges] = useState(dummyChallenges);
|
||||
const [challenges, setChallenges] = useState([]);
|
||||
const { username } = getUserData()
|
||||
|
||||
useEffect(() => {
|
||||
const abortController = new AbortController();
|
||||
let response = null;
|
||||
|
||||
const fetchData = async () => {
|
||||
let url = `${import.meta.env.VITE_BACKEND_HOST}/api/user/challenges`;
|
||||
let url = `${import.meta.env.VITE_BACKEND_HOST}/api/user/${username}/challenges`;
|
||||
try {
|
||||
response = await fetch(url, { signal: abortController.signal })
|
||||
const data = await response.json();
|
||||
@@ -32,7 +34,15 @@ const Challenges = () => {
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
fetchData();
|
||||
|
||||
return () => {
|
||||
if (!response) {
|
||||
abortController.abort();
|
||||
}
|
||||
}
|
||||
}, [])
|
||||
|
||||
if (!challenges || challenges.length === 0) {
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user