Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Oh yeah I forgot the other half
  • Loading branch information
regalijan committed Oct 19, 2023
1 parent 387cf6a commit 0a4ad77
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 13 deletions.
13 changes: 11 additions & 2 deletions app/routes/appeals.tsx
Expand Up @@ -64,9 +64,11 @@ export default function () {
const pageProps = useLoaderData<typeof loader>();
const { isOpen, onClose, onOpen } = useDisclosure();
const [showSuccess, setShowSuccess] = useState(false);
const [loading, setLoading] = useState(false)
const toast = useToast();

async function submit() {
setLoading(true)
const learned = (document.getElementById("learned") as HTMLInputElement)
.value;
const whyBanned = (document.getElementById("whyBanned") as HTMLInputElement)
Expand All @@ -86,25 +88,30 @@ export default function () {
method: "POST",
}).catch(() => {});

if (!submitReq)
if (!submitReq) {
setLoading(false)
return toast({
description: "Please check your internet and try again",
duration: 10000,
isClosable: true,
status: "error",
title: "Request Failed",
});
}

if (!submitReq.ok)
if (!submitReq.ok) {
setLoading(false)
return toast({
description: ((await submitReq.json()) as { error: string }).error,
duration: 10000,
isClosable: true,
status: "error",
title: "Error",
});
}

setShowSuccess(true);
setLoading(false)
}

async function toggle(active: boolean) {
Expand Down Expand Up @@ -232,6 +239,8 @@ export default function () {
<Button
disabled={pageProps.can_appeal}
onClick={async () => await submit()}
loadingText='Submitting'
isLoading={loading}
>
Submit
</Button>
Expand Down
5 changes: 5 additions & 0 deletions app/routes/data-transfer/start.tsx
Expand Up @@ -13,6 +13,7 @@ import { useState } from "react";

export default function () {
const [showCookieBox, setShowCookieBox] = useState(false);
const [loading, setLoading] = useState(false)
return (
<Container maxW="container.md">
<Heading pt="36px">Let's get started</Heading>
Expand All @@ -31,6 +32,7 @@ export default function () {
/>
<Button
onClick={async () => {
setLoading(true)
const createTransferReq = await fetch("/api/data-transfers/create", {
body: JSON.stringify({
can_access: !showCookieBox,
Expand All @@ -45,6 +47,7 @@ export default function () {
});

if (!createTransferReq.ok) {
setLoading(false)
useToast()({
description: (
(await createTransferReq.json()) as { error: string }
Expand All @@ -62,6 +65,8 @@ export default function () {
);
}}
pt="32px"
isLoading={loading}
loadingText='Processing...'
>
Continue
</Button>
Expand Down
23 changes: 19 additions & 4 deletions app/routes/report.tsx
Expand Up @@ -42,6 +42,7 @@ export default function () {
const [supportsRequestStreams, setSupportsRequestStreams] = useState(false);
const toast = useToast();
const [uploading, setUploading] = useState(false);
const [loading, setLoading] = useState(false)
const fileTypes: { [k: string]: string } = {
gif: "image/gif",
m4v: "video/x-m4v",
Expand Down Expand Up @@ -75,6 +76,7 @@ export default function () {
const { logged_in, site_key } = useLoaderData<typeof loader>();

async function submit() {
setLoading(true)
const usernames = (
document.getElementById("usernames") as HTMLInputElement
).value
Expand All @@ -83,29 +85,35 @@ export default function () {
const files = (document.getElementById("evidence") as HTMLInputElement)
.files;

if (!usernames.length)
if (!usernames.length) {
setLoading(false)
return toast({
description: "Must provide at least one username",
isClosable: true,
status: "error",
title: "Error",
});
}

if (!files?.length)
if (!files?.length) {
setLoading(false)
return toast({
description: "Must attach at least one file",
isClosable: true,
status: "error",
title: "Error",
});
}

if (usernames.length > 20)
if (usernames.length > 20) {
setLoading(false)
return toast({
description: "Only up to twenty users can be reported at a time",
isClosable: true,
status: "error",
title: "Too Many Usernames",
});
}

let turnstileToken = "";

Expand All @@ -114,13 +122,15 @@ export default function () {
.getElementsByName("cf-turnstile-response")
.item(0) as HTMLInputElement;

if (!tokenElem.value)
if (!tokenElem.value) {
setLoading(false)
return toast({
description: "Please complete the captcha and try again",
isClosable: true,
status: "error",
title: "Captcha not completed",
});
}

turnstileToken = tokenElem.value;
}
Expand Down Expand Up @@ -150,6 +160,7 @@ export default function () {
});

if (!submitReq.ok) {
setLoading(false)
if (!logged_in) {
try {
// @ts-expect-error
Expand Down Expand Up @@ -224,6 +235,7 @@ export default function () {
}

if (shouldRecall) {
setLoading(false)
await fetch("/api/reports/recall", {
body: JSON.stringify({ id }),
headers: {
Expand Down Expand Up @@ -252,6 +264,7 @@ export default function () {
});

setShowSuccess(true);
setLoading(false)
}

useEffect(() => {
Expand Down Expand Up @@ -319,6 +332,8 @@ export default function () {
disabled={uploading}
mr="8px"
onClick={async () => await submit()}
loadingText='Submitting'
isLoading={loading}
>
Submit
</Button>
Expand Down
7 changes: 7 additions & 0 deletions components/AppealCard.tsx
Expand Up @@ -27,6 +27,7 @@ export default function (props: AppealCardProps) {
);
const [action, setAction] = useState("");
const [feedback, setFeedback] = useState("");
const [loading, setLoading] = useState(false)
const toast = useToast();

useEffect(() => {
Expand All @@ -41,6 +42,7 @@ export default function (props: AppealCardProps) {
}

async function takeAction(action: string) {
setLoading(true)
const actionReq = await fetch(`/api/appeals/${props.id}/${action}`, {
body: feedback ? JSON.stringify({ feedback }) : "{}",
headers: {
Expand All @@ -50,6 +52,7 @@ export default function (props: AppealCardProps) {
});

if (actionReq.ok) {
setLoading(false)
toast({
description: `Appeal ${action === "accept" ? "accepted" : "denied"}`,
duration: 5000,
Expand All @@ -59,6 +62,7 @@ export default function (props: AppealCardProps) {

document.getElementById(`appeal_${props.id}`)?.remove();
} else {
setLoading(false)
toast({
description: ((await actionReq.json()) as { error: string }).error,
duration: 10000,
Expand All @@ -68,6 +72,7 @@ export default function (props: AppealCardProps) {
}

onClose();
setLoading(false)
}

return (
Expand All @@ -86,6 +91,8 @@ export default function (props: AppealCardProps) {
<ModalFooter>
<Button
onClick={async () => await takeAction(action.toLowerCase())}
isLoading={loading}
loadingText='Submitting...'
>
Submit
</Button>
Expand Down
7 changes: 7 additions & 0 deletions components/GameAppealCard.tsx
Expand Up @@ -18,9 +18,12 @@ import {
useDisclosure,
useToast,
} from "@chakra-ui/react";
import { useState } from "react";

export default function (props: GameAppealProps) {
const [loading, setLoading] = useState(false)
async function performAction(action: "accept" | "deny"): Promise<void> {
setLoading(true)
const statsReduction = parseInt(
(document.getElementById("reductPercentage") as HTMLInputElement).value,
);
Expand Down Expand Up @@ -51,6 +54,8 @@ export default function (props: GameAppealProps) {
title: "An error occurred...",
},
);

setLoading(false)
}

const { isOpen, onClose, onOpen } = useDisclosure();
Expand Down Expand Up @@ -108,6 +113,8 @@ export default function (props: GameAppealProps) {
colorScheme="blue"
ml="8px"
onClick={async () => await performAction("accept")}
isLoading={loading}
loadingText='Submitting...'
>
Submit
</Button>
Expand Down
9 changes: 9 additions & 0 deletions components/InactivityNoticeCard.tsx
Expand Up @@ -13,11 +13,14 @@ import {
UnorderedList,
useToast
} from "@chakra-ui/react";
import { useState } from "react";

export default function(props: InactivityNoticeProps) {
const toast = useToast();
const [loading, setLoading] = useState(false)

async function makeDecision(accepted: boolean) {
setLoading(true)
const decisionReq = await fetch(`/api/inactivity/${props.id}`, {
body: JSON.stringify({ accepted }),
headers: {
Expand All @@ -27,6 +30,7 @@ export default function(props: InactivityNoticeProps) {
});

if (!decisionReq.ok) {
setLoading(false)
toast({
description: ((await decisionReq.json()) as { error: string }).error,
isClosable: true,
Expand All @@ -44,6 +48,7 @@ export default function(props: InactivityNoticeProps) {
title: "Success"
});

setLoading(false)
location.reload();
}

Expand Down Expand Up @@ -103,13 +108,17 @@ export default function(props: InactivityNoticeProps) {
<Button
colorScheme="red"
onClick={async () => await makeDecision(false)}
isLoading={loading}
loadingText='Processing...'
>
Deny
</Button>
<Button
colorScheme="blue"
ml="8px"
onClick={async () => await makeDecision(true)}
isLoading={loading}
loadingText='Processing...'
>
Accept
</Button>
Expand Down
13 changes: 12 additions & 1 deletion components/NewGameBan.tsx
Expand Up @@ -27,6 +27,7 @@ import { useState } from "react";
export default function(props: { isOpen: boolean; onClose: () => void }) {
const actionMap: { [k: string]: number } = {};
const [users, setUsers] = useState([] as string[]);
const [loading, setLoading] = useState(true)
const toast = useToast();
const fileTypes: { [k: string]: string } = {
gif: "image/gif",
Expand Down Expand Up @@ -79,6 +80,7 @@ export default function(props: { isOpen: boolean; onClose: () => void }) {
}

async function submit() {
setLoading(true)
const actions: number[] = [];
const usernames: string[] = [];

Expand All @@ -92,7 +94,10 @@ export default function(props: { isOpen: boolean; onClose: () => void }) {
const files = (document.getElementById("evidence") as HTMLInputElement)
.files;

if (!files) return;
if (!files) {
setLoading(false)
return
}

const [evidence] = files;

Expand All @@ -111,6 +116,7 @@ export default function(props: { isOpen: boolean; onClose: () => void }) {
});

if (!submitReq.ok) {
setLoading(false)
toast({
description: ((await submitReq.json()) as { error: string }).error,
status: "error",
Expand All @@ -135,6 +141,7 @@ export default function(props: { isOpen: boolean; onClose: () => void }) {
});

if (!fileUpload.ok) {
setLoading(false)
await fetch("/api/reports/recall", {
body: JSON.stringify({ id }),
headers: {
Expand Down Expand Up @@ -165,6 +172,8 @@ export default function(props: { isOpen: boolean; onClose: () => void }) {
status: "success",
title: "Success"
});

setLoading(false)
}

return (
Expand Down Expand Up @@ -276,6 +285,8 @@ export default function(props: { isOpen: boolean; onClose: () => void }) {
}
ml="8px"
onClick={async () => await submit()}
isLoading={loading}
loadingText='Submitting...'
>
Submit
</Button>
Expand Down

0 comments on commit 0a4ad77

Please sign in to comment.