Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Automatic upload after adding problem solved #30

Open
wants to merge 39 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
ca73969
Setting React framework
lollobeach Oct 5, 2023
bacfd0c
Merge pull request #1 from hacktoberfest-unicam/main
giorgiosld Oct 5, 2023
e364b20
Layout added
lollobeach Oct 6, 2023
649893c
[edit] Added sgreen's changes to avoid conflict
giorgiosld Oct 6, 2023
0619b8b
Merge pull request #3 from hacktoberfest-unicam/main
giorgiosld Oct 6, 2023
e05231a
[edit] Edited logoHorizontal to avoid conflict
giorgiosld Oct 6, 2023
164df77
Merge branch 'main' of github.com:giorgiosld/hacktoberfest-2023-frontend
giorgiosld Oct 6, 2023
cb05eab
Merge branch 'main' into main
giorgiosld Oct 6, 2023
05eeb9e
Layout update and Homepage initialized
lollobeach Oct 7, 2023
c0984fa
Merge branch 'main' of https://github.com/lollobeach/hacktoberfest-20…
lollobeach Oct 7, 2023
765d7b2
Merge pull request #1 from hacktoberfest-unicam/main
lollobeach Oct 9, 2023
0b283f9
Fix background image, Update the Homepage, Routes in the button inser…
lollobeach Oct 9, 2023
ea76eee
Merge pull request #2 from hacktoberfest-unicam/main
lollobeach Oct 10, 2023
b3d53b5
Footer added, LoginPage added with github icon obtained by npm instal…
lollobeach Oct 10, 2023
68776d2
Merge pull request #3 from hacktoberfest-unicam/main
lollobeach Oct 11, 2023
b6e4a61
Add Login Button in HomePage
lollobeach Oct 11, 2023
3c274e0
Merge branch 'main' of https://github.com/lollobeach/hacktoberfest-20…
lollobeach Oct 11, 2023
7e6c1f5
Merge pull request #4 from hacktoberfest-unicam/main
lollobeach Oct 16, 2023
9631c6d
Loading Page fixed, Dynamic Navbar added
lollobeach Oct 16, 2023
4b2f080
Merge branch 'main' of https://github.com/lollobeach/hacktoberfest-20…
lollobeach Oct 16, 2023
926b747
[edit] background image modified
lollobeach Oct 16, 2023
e3d8f49
test new changes
lollobeach Oct 20, 2023
20604c5
merge branch
lollobeach Oct 20, 2023
db74f0c
Merge pull request #7 from lollobeach/hacktoberfest-unicam-main
lollobeach Oct 20, 2023
1be5032
merge updates
lollobeach Oct 20, 2023
6d40d8e
[edit] fix login process
HarlockOfficial Oct 20, 2023
b3ce427
Merge branch 'main' into main_g
HarlockOfficial Oct 20, 2023
5868217
Merge pull request #8 from hacktoberfest-unicam/main
lollobeach Oct 21, 2023
60a782b
[edit] fix login
lollobeach Oct 21, 2023
d0df4b0
[edit] route in Layout
lollobeach Oct 21, 2023
5e4681e
[edit] AdminControlPanel to upadte bonus_points [edit] AdminInfo for …
lollobeach Oct 21, 2023
5b7f1bf
Merge remote-tracking branch 'origin/main' into main_g
HarlockOfficial Oct 23, 2023
0467d21
[fix] add problem
HarlockOfficial Oct 23, 2023
00209a5
Merge remote-tracking branch 'green/main' into main_g
HarlockOfficial Oct 23, 2023
64d8bb9
[edit] AdminControlPanel
lollobeach Oct 23, 2023
45703e7
[fix] profile page
HarlockOfficial Oct 23, 2023
a079495
[add] sponsors
lollobeach Oct 23, 2023
0ac8eea
Merge branch 'main' of https://github.com/lollobeach/hacktoberfest-20…
lollobeach Oct 23, 2023
b277a48
[fix] automatic upload page after adding of problem solved [edit] 'he…
lollobeach Oct 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22,700 changes: 46 additions & 22,654 deletions package-lock.json

Large diffs are not rendered by default.

50 changes: 30 additions & 20 deletions src/components/AdminPage/AdminControlPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import ChallengeController from "./ChallengeController";

export default function AdminControlPanel() {
const [LeaderboardData, setLeaderboardData] = useState([]);
const [problemsSolved, setProblemsSolved] = useState();
const [problemsSolved, setProblemsSolved] = useState([]);
const [usersWithProblemsSolved, setUsersWithProblemsSolved] = useState();

useEffect(() => {
Expand All @@ -30,14 +30,11 @@ export default function AdminControlPanel() {
});

axios
.get(`${process.env.REACT_APP_BACKEND_URL}api/submission/all`, {
headers: {
Authorization: localStorage.getItem("token"),
},
})
.get(`${process.env.REACT_APP_BACKEND_URL}api/submission/all`)
.then((response) => {
//console.log(response.data.submission_list);
setProblemsSolved(response.data.submission_list);
console.log(response.data.submission_list)
const users = new Set();
response.data.submission_list.forEach((problem) => {
users.add(problem.user.github_username);
Expand All @@ -52,22 +49,29 @@ export default function AdminControlPanel() {
}, [setProblemsSolved]);

const changeBonusPoints = (event, problem) => {
const newBonusPoints = event.target?.value
problem.bonus_points = newBonusPoints
axios.put(`${process.env.REACT_APP_BACKEND_URL}/api/submission/${problem.id}`, {"bonus_points": problem.bonus_points}, { headers: { Authorization: localStorage.getItem("token") } })
.then((response) => {
console.log(response)
const problemsSolvedToUpdate = [...problemsSolved]
const problemToUpdate = problemsSolvedToUpdate.find(item => item.id === problem.id)
problemToUpdate.bonus_points = newBonusPoints
setProblemsSolved(problemsSolvedToUpdate)
})
.catch((err) => console.error(err))
}
const newBonusPoints = event.target?.value;
problem.bonus_points = newBonusPoints;
axios
.put(
`${process.env.REACT_APP_BACKEND_URL}/api/submission/${problem.id}`,
{ bonus_points: problem.bonus_points },
{ headers: { Authorization: localStorage.getItem("token") } }
)
.then((response) => {
console.log(response);
const problemsSolvedToUpdate = [...problemsSolved];
const problemToUpdate = problemsSolvedToUpdate.find(
(item) => item.id === problem.id
);
problemToUpdate.bonus_points = newBonusPoints;
setProblemsSolved(problemsSolvedToUpdate);
})
.catch((err) => console.error(err));
};

return (
<>
<ChallengeController />
<ChallengeController addProblemsSolved={setProblemsSolved} allProblemsSolved={problemsSolved} />
<Typography variant="h1" color="secondary.light">
Users
</Typography>
Expand Down Expand Up @@ -104,7 +108,13 @@ export default function AdminControlPanel() {
<InputLabel id="bonus-points">
{problem.bonus_points}
</InputLabel>
<Select value={problem.bonus_points} label="bonus points" onChange={(event) => changeBonusPoints(event, problem)}>
<Select
value={problem.bonus_points}
label="bonus points"
onChange={(event) =>
changeBonusPoints(event, problem)
}
>
<MenuItem value={-5}>-5</MenuItem>
<MenuItem value={-4}>-4</MenuItem>
<MenuItem value={-3}>-3</MenuItem>
Expand Down
223 changes: 134 additions & 89 deletions src/components/AdminPage/ChallengeController.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,50 @@
import React, { useEffect, useState } from 'react'
import axios from 'axios';
import { Button, FormControl, InputLabel, MenuItem, Select } from '@mui/material';
import React, { useEffect, useState } from "react";
import axios from "axios";
import {
Button,
FormControl,
InputLabel,
MenuItem,
Select,
} from "@mui/material";
import Cookies from "js-cookie";

export default function ChallengeController() {

const [userData, setUserData] = useState()
const [problemsData, setProblemsData] = useState()
export default function ChallengeController({ addProblemsSolved, allProblemsSolved }) {
const [userData, setUserData] = useState();
const [problemsData, setProblemsData] = useState();

useEffect(() => {
const apiUsers = `${process.env.REACT_APP_BACKEND_URL}api/user/all`;
axios.get(apiUsers
).then((response) => {
setUserData(response.data)
})
.catch((error) => {
console.error("Zio pera")
});
}, []);
const apiUsers = `${process.env.REACT_APP_BACKEND_URL}api/user/all`;
axios
.get(apiUsers)
.then((response) => {
setUserData(response.data);
})
.catch((error) => {
console.error(error);
});
}, []);

useEffect(() => {
const apiProblems = `${process.env.REACT_APP_BACKEND_URL}api/problem/all`;
axios.get(apiProblems
).then((response) => {
setProblemsData(response.data)
})
.catch((error) => {
console.error("Zio pera")
});
}, []);
axios
.get(apiProblems)
.then((response) => {
setProblemsData(response.data);
})
.catch((error) => {
console.error(error);
});
}, []);

let users_nickname, problems_name
if(userData && problemsData){
users_nickname = userData.user_list.map((item) => item.github_username)
problems_name = problemsData.problem_list.map((item) => item.name)
let users_nickname, problems_name;
if (userData && problemsData) {
users_nickname = userData.user_list.map((item) => item.github_username);
problems_name = problemsData.problem_list.map((item) => item.name);
}

const [selectedUser, setSelectedUser] = React.useState('');
const [selectedProblem, setSelectedProblem] = React.useState('');
const [selectedUser, setSelectedUser] = React.useState("");
const [selectedProblem, setSelectedProblem] = React.useState("");

const handleUserChange = (event) => {
setSelectedUser(event.target.value);
Expand All @@ -47,72 +54,110 @@ export default function ChallengeController() {
setSelectedProblem(event.target.value);
};

const handleChange = (event) => {
const problemFound = problemsData.problem_list.find(problem => problem.name === selectedProblem)
console.log(problemFound)
const userFound = userData.user_list.find(user => user.github_username === selectedUser)
console.log(userFound)
const handleChange = () => {
const problemFound = problemsData.problem_list.find(
(problem) => problem.name === selectedProblem
);
console.log(problemFound);
const userFound = userData.user_list.find(
(user) => user.github_username === selectedUser
);
console.log(userFound);
const token = localStorage.getItem("token");
const apiSubmitProblem = `${process.env.REACT_APP_BACKEND_URL}api/submission/add`;
Cookies.remove("authorization");
axios.post(apiSubmitProblem, {
user: userFound,
problem: problemFound,
bonus_points: 0,
},{
headers: { Authorization: `${token}` },
}).then((response) => {
console.log(response.data)
})
.catch((error) => {
console.error(error)
});
axios
.post(
apiSubmitProblem,
{
user: userFound,
problem: problemFound,
bonus_points: 0,
},
{
headers: { Authorization: `${token}` },
}
)
.then((response) => {
console.log(response.data);
addProblemsSolved([
...allProblemsSolved,
response.data.result
])
})
.catch((error) => {
console.error(error);
});
};

return (
<>
<FormControl sx={{ m: 4, minWidth: 350, backgroundColor: "initial", border: "2px solid rgb(210, 184, 99)" }}>
<InputLabel sx={{color: "#FFF" }} id="demo-simple-select-label">Username</InputLabel>
<Select
labelId="demo-simple-select-label"
id="demo-simple-select"
value={selectedUser}
label="Users"
sx={{color: "#FFF" }}
onChange={handleUserChange}
>
{users_nickname?.map((name, index) => (
<MenuItem key={index} value={name}>
{name}
</MenuItem>
))}
</Select>
</FormControl>
<FormControl sx={{ m: 4, minWidth: 350, backgroundColor: "initial", border: "2px solid rgb(210, 184, 99)" }} >
<InputLabel sx={{color: "#FFF" }} id="demo-simple-select-label">Problems</InputLabel>
<Select
labelId="demo-simple-select-label"
id="demo-simple-select"
value={selectedProblem}
label="Problems"
sx={{color: "#FFF" }}
onChange={handleProblemChange}
>
{problems_name?.map((name, index) => (
<MenuItem key={index} value={name}>
{name}
</MenuItem>
))}
</Select>
</FormControl>
<Button
variant="outlined"
size="large"
sx={{ m: 4, minWidth: 350, backgroundColor: "initial", border: "2px solid rgb(210, 184, 99)", minHeight: "1.4375em" }}
onClick={handleChange}
<FormControl
sx={{
m: 4,
minWidth: 350,
backgroundColor: "initial",
border: "2px solid rgb(210, 184, 99)",
}}
>
<InputLabel sx={{ color: "#FFF" }} id="demo-simple-select-label">
Username
</InputLabel>
<Select
labelId="demo-simple-select-label"
id="demo-simple-select"
value={selectedUser}
label="Users"
sx={{ color: "#FFF" }}
onChange={handleUserChange}
>
{users_nickname?.map((name, index) => (
<MenuItem key={index} value={name}>
{name}
</MenuItem>
))}
</Select>
</FormControl>
<FormControl
sx={{
m: 4,
minWidth: 350,
backgroundColor: "initial",
border: "2px solid rgb(210, 184, 99)",
}}
>
<InputLabel sx={{ color: "#FFF" }} id="demo-simple-select-label">
Problems
</InputLabel>
<Select
labelId="demo-simple-select-label"
id="demo-simple-select"
value={selectedProblem}
label="Problems"
sx={{ color: "#FFF" }}
onChange={handleProblemChange}
>
Apply
</Button>
{problems_name?.map((name, index) => (
<MenuItem key={index} value={name}>
{name}
</MenuItem>
))}
</Select>
</FormControl>
<Button
variant="outlined"
size="large"
sx={{
m: 4,
minWidth: 350,
backgroundColor: "initial",
border: "2px solid rgb(210, 184, 99)",
minHeight: "1.4375em",
}}
onClick={handleChange}
>
Apply
</Button>
</>
)
);
}
1 change: 0 additions & 1 deletion src/components/Layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ export default function Layout() {
Profile
</Typography>
</Button>

</Box>
</Box>
</Box>
Expand Down
2 changes: 1 addition & 1 deletion src/components/RankingPage/RankingTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function RankingTable() {
setLeaderboardData(response.data)
})
.catch((error) => {
console.error("Zio pera")
console.error(error)
});
}, []);

Expand Down
Loading