Skip to content

Commit

Permalink
Merge pull request #60 from abakus-ntnu/change_save_button
Browse files Browse the repository at this point in the history
changed save button on admin page such that it only appear in changes
  • Loading branch information
ShaileshS1702 authored Nov 2, 2023
2 parents fca5c01 + 0d44623 commit 7cb078c
Show file tree
Hide file tree
Showing 4 changed files with 2,114 additions and 154 deletions.
20 changes: 14 additions & 6 deletions client/src/components/adminLeaderboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const AdminLeaderboard = ({
hasStarted,
}: LeaderboardProps) => {
const [users, setUsers] = useState(data);
const [changeId, setChangeId] = useState([]);

useEffect(() => {
data.sort((a, b) => b.score - a.score);
Expand All @@ -19,6 +20,7 @@ const AdminLeaderboard = ({
const deleteUser = DeleteUser();
const softDeleteUser = SoftDeleteUser();
const updateUser = UpdateUser();

const Delete = (id: string) =>
deleteUser.mutate(
users.find((user) => user._id === id),
Expand All @@ -33,15 +35,18 @@ const AdminLeaderboard = ({
onSuccess: () => getUsersQuery.refetch(),
},
);
const Update = (id: string) =>
const Update = (id: string) => {
setChangeId([]);
updateUser.mutate(
users.find((user) => user._id === id),
{
onSuccess: () => getUsersQuery.refetch(),
},
);
};

const handleChange = (id: string, event: any, changeName = false) => {
setChangeId([...changeId, id]);
const arr = [...users];
const user = arr.find((user) => user._id === id);
if (changeName) {
Expand Down Expand Up @@ -84,11 +89,14 @@ const AdminLeaderboard = ({
/>
</td>
<td className="imageBox">
<img
src="src/public/save.svg"
className="save"
onClick={() => Update(user._id)}
/>
{changeId.includes(user._id) && (
<img
src="src/public/save.svg"
className="save"
onClick={() => Update(user._id)}
/>
)}

<img
src="src/public/x.svg"
className="x"
Expand Down
2 changes: 1 addition & 1 deletion client/src/styles/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ h2 {
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
justify-content: flex-end;
gap: 1rem;
}

Expand Down
Loading

0 comments on commit 7cb078c

Please sign in to comment.