Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed save button on admin page such that it only appear in changes #60

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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