Take 1 at trying to stop double clicks
This commit is contained in:
parent
1bed3edaf9
commit
e7c6b8fa5b
@ -119,9 +119,14 @@ export default function () {
|
|||||||
} = useDisclosure();
|
} = useDisclosure();
|
||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
const [selectedEvent, setSelectedEvent] = useState("");
|
const [selectedEvent, setSelectedEvent] = useState("");
|
||||||
|
const [disableClicks, setDisableClicks] = useState(false);
|
||||||
const [showOld, setShowOld] = useState(false);
|
const [showOld, setShowOld] = useState(false);
|
||||||
|
|
||||||
async function decide(approved: boolean, eventId: string) {
|
async function decide(approved: boolean, eventId: string) {
|
||||||
|
if (disableClicks) return;
|
||||||
|
|
||||||
|
setDisableClicks(true);
|
||||||
|
|
||||||
const decisionResp = await fetch(
|
const decisionResp = await fetch(
|
||||||
`/api/events-team/events/${eventId}/decision`,
|
`/api/events-team/events/${eventId}/decision`,
|
||||||
{
|
{
|
||||||
@ -146,6 +151,7 @@ export default function () {
|
|||||||
title: "Oops!",
|
title: "Oops!",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
setDisableClicks(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,9 +168,14 @@ export default function () {
|
|||||||
newEventData[eventIdx].pending = false;
|
newEventData[eventIdx].pending = false;
|
||||||
|
|
||||||
setEventData([...newEventData]);
|
setEventData([...newEventData]);
|
||||||
|
setDisableClicks(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function certify(eventId: string) {
|
async function certify(eventId: string) {
|
||||||
|
if (disableClicks) return;
|
||||||
|
|
||||||
|
setDisableClicks(true);
|
||||||
|
|
||||||
const certifyResp = await fetch(
|
const certifyResp = await fetch(
|
||||||
`/api/events-team/events/${eventId}/certify`,
|
`/api/events-team/events/${eventId}/certify`,
|
||||||
{
|
{
|
||||||
@ -189,6 +200,7 @@ export default function () {
|
|||||||
title: "Failed to certify game night",
|
title: "Failed to certify game night",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
setDisableClicks(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,9 +217,12 @@ export default function () {
|
|||||||
|
|
||||||
setEventData([...newEventData]);
|
setEventData([...newEventData]);
|
||||||
setSelectedEvent("");
|
setSelectedEvent("");
|
||||||
|
setDisableClicks(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function markComplete(eventId: string) {
|
async function markComplete(eventId: string) {
|
||||||
|
setDisableClicks(true);
|
||||||
|
|
||||||
const completeResp = await fetch(
|
const completeResp = await fetch(
|
||||||
`/api/events-team/events/${eventId}/complete`,
|
`/api/events-team/events/${eventId}/complete`,
|
||||||
{
|
{
|
||||||
@ -234,6 +249,7 @@ export default function () {
|
|||||||
title: "Failed to complete",
|
title: "Failed to complete",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
setDisableClicks(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -251,9 +267,12 @@ export default function () {
|
|||||||
|
|
||||||
setEventData([...newEventData]);
|
setEventData([...newEventData]);
|
||||||
setSelectedEvent("");
|
setSelectedEvent("");
|
||||||
|
setDisableClicks(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function markForgotten(eventId: string) {
|
async function markForgotten(eventId: string) {
|
||||||
|
setDisableClicks(true);
|
||||||
|
|
||||||
const forgottenResp = await fetch(
|
const forgottenResp = await fetch(
|
||||||
`/api/events-team/events/${eventId}/forgotten`,
|
`/api/events-team/events/${eventId}/forgotten`,
|
||||||
{
|
{
|
||||||
@ -280,6 +299,7 @@ export default function () {
|
|||||||
title: "Failed to forget",
|
title: "Failed to forget",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
setDisableClicks(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,9 +308,12 @@ export default function () {
|
|||||||
newEventData[eventData.findIndex((e) => e.id === eventId)].performed_at = 0;
|
newEventData[eventData.findIndex((e) => e.id === eventId)].performed_at = 0;
|
||||||
setEventData([...newEventData]);
|
setEventData([...newEventData]);
|
||||||
setSelectedEvent("");
|
setSelectedEvent("");
|
||||||
|
setDisableClicks(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteEvent(eventId: string) {
|
async function deleteEvent(eventId: string) {
|
||||||
|
setDisableClicks(true);
|
||||||
|
|
||||||
const deleteResp = await fetch(`/api/events-team/events/${eventId}`, {
|
const deleteResp = await fetch(`/api/events-team/events/${eventId}`, {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
});
|
});
|
||||||
@ -310,14 +333,18 @@ export default function () {
|
|||||||
title: "Failed to delete",
|
title: "Failed to delete",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
setDisableClicks(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setEventData(eventData.filter((e) => e.id !== eventId));
|
setEventData(eventData.filter((e) => e.id !== eventId));
|
||||||
setSelectedEvent("");
|
setSelectedEvent("");
|
||||||
|
setDisableClicks(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function reschedule(eventId: string) {
|
async function reschedule(eventId: string) {
|
||||||
|
setDisableClicks(true);
|
||||||
|
|
||||||
const newDate = (
|
const newDate = (
|
||||||
document.getElementById("reschedule-input") as HTMLInputElement
|
document.getElementById("reschedule-input") as HTMLInputElement
|
||||||
).value;
|
).value;
|
||||||
@ -343,6 +370,7 @@ export default function () {
|
|||||||
title: "Failed to reschedule",
|
title: "Failed to reschedule",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
setDisableClicks(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -352,6 +380,7 @@ export default function () {
|
|||||||
setEventData([...newEventData]);
|
setEventData([...newEventData]);
|
||||||
setSelectedEvent("");
|
setSelectedEvent("");
|
||||||
onRescheduleClose();
|
onRescheduleClose();
|
||||||
|
setDisableClicks(false);
|
||||||
toast({
|
toast({
|
||||||
description: `Event rescheduled to ${newDate}`,
|
description: `Event rescheduled to ${newDate}`,
|
||||||
status: "success",
|
status: "success",
|
||||||
@ -373,11 +402,16 @@ export default function () {
|
|||||||
</Text>
|
</Text>
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
<Button colorScheme="red" onClick={onClose}>
|
<Button
|
||||||
|
colorScheme="red"
|
||||||
|
disabled={disableClicks}
|
||||||
|
onClick={onClose}
|
||||||
|
>
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
colorScheme="blue"
|
colorScheme="blue"
|
||||||
|
disabled={disableClicks}
|
||||||
ml="8px"
|
ml="8px"
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
await certify(selectedEvent);
|
await certify(selectedEvent);
|
||||||
@ -401,9 +435,12 @@ export default function () {
|
|||||||
</Text>
|
</Text>
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
<Button onClick={closeComplete}>Cancel</Button>
|
<Button disabled={disableClicks} onClick={closeComplete}>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
colorScheme="blue"
|
colorScheme="blue"
|
||||||
|
disabled={disableClicks}
|
||||||
ml="8px"
|
ml="8px"
|
||||||
onClick={async () => await markComplete(selectedEvent)}
|
onClick={async () => await markComplete(selectedEvent)}
|
||||||
>
|
>
|
||||||
@ -422,9 +459,12 @@ export default function () {
|
|||||||
will be given a 5 point penalty.
|
will be given a 5 point penalty.
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
<Button onClick={onForgottenClose}>Cancel</Button>
|
<Button disabled={disableClicks} onClick={onForgottenClose}>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
colorScheme="blue"
|
colorScheme="blue"
|
||||||
|
disabled={disableClicks}
|
||||||
ml="8px"
|
ml="8px"
|
||||||
onClick={async () => await markForgotten(selectedEvent)}
|
onClick={async () => await markForgotten(selectedEvent)}
|
||||||
>
|
>
|
||||||
@ -443,9 +483,12 @@ export default function () {
|
|||||||
want to continue?
|
want to continue?
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
<Button onClick={onDeleteClose}>Cancel</Button>
|
<Button disabled={disableClicks} onClick={onDeleteClose}>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
colorScheme="red"
|
colorScheme="red"
|
||||||
|
disabled={disableClicks}
|
||||||
ml="8px"
|
ml="8px"
|
||||||
onClick={async () => await deleteEvent(selectedEvent)}
|
onClick={async () => await deleteEvent(selectedEvent)}
|
||||||
>
|
>
|
||||||
@ -478,9 +521,12 @@ export default function () {
|
|||||||
</Text>
|
</Text>
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
<Button onClick={onRescheduleClose}>Cancel</Button>
|
<Button disabled={disableClicks} onClick={onRescheduleClose}>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
colorScheme="blue"
|
colorScheme="blue"
|
||||||
|
disabled={disableClicks}
|
||||||
ml="8px"
|
ml="8px"
|
||||||
onClick={async () => await reschedule(selectedEvent)}
|
onClick={async () => await reschedule(selectedEvent)}
|
||||||
>
|
>
|
||||||
@ -585,12 +631,14 @@ export default function () {
|
|||||||
<>
|
<>
|
||||||
<Button
|
<Button
|
||||||
colorScheme="red"
|
colorScheme="red"
|
||||||
|
disabled={disableClicks}
|
||||||
onClick={async () => await decide(false, event.id)}
|
onClick={async () => await decide(false, event.id)}
|
||||||
>
|
>
|
||||||
Reject
|
Reject
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
colorScheme="blue"
|
colorScheme="blue"
|
||||||
|
disabled={disableClicks}
|
||||||
onClick={async () => await decide(true, event.id)}
|
onClick={async () => await decide(true, event.id)}
|
||||||
>
|
>
|
||||||
Approve
|
Approve
|
||||||
@ -603,6 +651,7 @@ export default function () {
|
|||||||
<>
|
<>
|
||||||
<Button
|
<Button
|
||||||
colorScheme="blue"
|
colorScheme="blue"
|
||||||
|
disabled={disableClicks}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setSelectedEvent(event.id);
|
setSelectedEvent(event.id);
|
||||||
openComplete();
|
openComplete();
|
||||||
@ -612,6 +661,7 @@ export default function () {
|
|||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
colorScheme="red"
|
colorScheme="red"
|
||||||
|
disabled={disableClicks}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setSelectedEvent(event.id);
|
setSelectedEvent(event.id);
|
||||||
onForgottenOpen();
|
onForgottenOpen();
|
||||||
@ -628,6 +678,7 @@ export default function () {
|
|||||||
!event.reached_minimum_player_count ? (
|
!event.reached_minimum_player_count ? (
|
||||||
<Button
|
<Button
|
||||||
colorScheme="blue"
|
colorScheme="blue"
|
||||||
|
disabled={disableClicks}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setSelectedEvent(event.id);
|
setSelectedEvent(event.id);
|
||||||
onOpen();
|
onOpen();
|
||||||
@ -650,6 +701,7 @@ export default function () {
|
|||||||
<IconButton
|
<IconButton
|
||||||
alignSelf="center"
|
alignSelf="center"
|
||||||
aria-label="Delete event"
|
aria-label="Delete event"
|
||||||
|
disabled={disableClicks}
|
||||||
display={
|
display={
|
||||||
(event.created_by === user_id &&
|
(event.created_by === user_id &&
|
||||||
event.day > new Date().getUTCDate()) ||
|
event.day > new Date().getUTCDate()) ||
|
||||||
|
Loading…
x
Reference in New Issue
Block a user