Hammer work now?
This commit is contained in:
parent
a5bf9fc329
commit
48fd4981fb
@ -4,6 +4,7 @@ import {
|
|||||||
Card,
|
Card,
|
||||||
CardBody,
|
CardBody,
|
||||||
CardHeader,
|
CardHeader,
|
||||||
|
Center,
|
||||||
Container,
|
Container,
|
||||||
Heading,
|
Heading,
|
||||||
HStack,
|
HStack,
|
||||||
@ -13,8 +14,9 @@ import {
|
|||||||
Stack,
|
Stack,
|
||||||
StackDivider,
|
StackDivider,
|
||||||
Text,
|
Text,
|
||||||
|
useToast,
|
||||||
} from "@chakra-ui/react";
|
} from "@chakra-ui/react";
|
||||||
import { type FormEvent, useState } from "react";
|
import { type FormEvent, type ReactElement, useState } from "react";
|
||||||
|
|
||||||
export async function loader({ context }: { context: RequestContext }) {
|
export async function loader({ context }: { context: RequestContext }) {
|
||||||
const { current_user: currentUser } = context.data;
|
const { current_user: currentUser } = context.data;
|
||||||
@ -42,27 +44,56 @@ export default function () {
|
|||||||
const [status, setStatus] = useState("");
|
const [status, setStatus] = useState("");
|
||||||
const [visible, setVisible] = useState(false);
|
const [visible, setVisible] = useState(false);
|
||||||
const [avatarUrl, setAvatarUrl] = useState("");
|
const [avatarUrl, setAvatarUrl] = useState("");
|
||||||
const [history, setHistory] = useState([]);
|
const [history, setHistory] = useState([] as ReactElement[]);
|
||||||
|
const [hasResults, setHasResults] = useState(true);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const toast = useToast();
|
||||||
|
|
||||||
async function getHistory() {
|
async function getHistory() {
|
||||||
const username = (document.getElementById("username") as HTMLInputElement)
|
setVisible(false);
|
||||||
.value;
|
setLoading(true);
|
||||||
|
setHistory([]);
|
||||||
|
|
||||||
if (username.length < 4) return alert("Username is too short!");
|
if (username.length < 4) {
|
||||||
|
setLoading(false);
|
||||||
|
return toast({
|
||||||
|
title: "Validation Error",
|
||||||
|
description: `Username is too short`,
|
||||||
|
status: "error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const historyResp = await fetch(`/api/game-bans/${username}/history`);
|
const historyResp = await fetch(`/api/game-bans/${username}/history`);
|
||||||
|
|
||||||
if (!historyResp.ok)
|
if (!historyResp.ok) {
|
||||||
return alert(
|
setLoading(false);
|
||||||
`ERROR: ${((await historyResp.json()) as { error: string }).error}`,
|
return toast({
|
||||||
);
|
title: "Failed To Fetch User",
|
||||||
|
description: `${
|
||||||
|
((await historyResp.json()) as { error: string }).error
|
||||||
|
}`,
|
||||||
|
status: "error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const history: { [k: string]: any }[] = await historyResp.json();
|
const history: { [k: string]: any }[] = await historyResp.json();
|
||||||
|
|
||||||
if (!history.length) return alert("No history for this user.");
|
if (!history.length) {
|
||||||
|
setLoading(false);
|
||||||
|
setHasResults(false);
|
||||||
|
return toast({
|
||||||
|
title: "Nothing Found",
|
||||||
|
description: "This user doesn't have any moderation history.",
|
||||||
|
status: "info",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setHasResults(true);
|
||||||
const cardList = [];
|
const cardList = [];
|
||||||
|
|
||||||
|
setUid(history[history.length - 1].entity.properties.target.integerValue);
|
||||||
|
setStatus(history[history.length - 1].entity.properties.action.stringValue);
|
||||||
|
|
||||||
for (const entry of history) {
|
for (const entry of history) {
|
||||||
const url = entry.entity.properties.evidence.stringValue;
|
const url = entry.entity.properties.evidence.stringValue;
|
||||||
const isUrl = () => {
|
const isUrl = () => {
|
||||||
@ -75,41 +106,55 @@ export default function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
cardList.push(
|
cardList.push(
|
||||||
<Card>
|
<Container mb={3}>
|
||||||
<CardHeader>
|
<Card>
|
||||||
<Heading size="md">{new Date().toLocaleString()}</Heading>
|
<CardHeader>
|
||||||
</CardHeader>
|
<Heading size="md">{new Date().toLocaleString()}</Heading>
|
||||||
<CardBody>
|
</CardHeader>
|
||||||
<Stack divider={<StackDivider />} spacing="4">
|
<CardBody>
|
||||||
<Box>
|
<Stack divider={<StackDivider />} spacing="4">
|
||||||
<Heading size="xs">ACTION</Heading>
|
<Box>
|
||||||
<Text pt="2" size="sm">
|
<Heading size="xs">ACTION</Heading>
|
||||||
{entry.entity.properties.action.stringValue}
|
<Text pt="2" size="sm">
|
||||||
</Text>
|
{entry.entity.properties.action.stringValue}
|
||||||
</Box>
|
</Text>
|
||||||
<Box>
|
</Box>
|
||||||
<Heading size="xs">EVIDENCE</Heading>
|
<Box>
|
||||||
<Text pt="2" size="sm">
|
<Heading size="xs">EVIDENCE</Heading>
|
||||||
{isUrl() ? (
|
<Text pt="2" size="sm">
|
||||||
<Link color="#646cff" href={url}>
|
{isUrl() ? (
|
||||||
{url}
|
<Link color="#646cff" href={url}>
|
||||||
</Link>
|
{url}
|
||||||
) : (
|
</Link>
|
||||||
url
|
) : (
|
||||||
)}
|
url
|
||||||
</Text>
|
)}
|
||||||
</Box>
|
</Text>
|
||||||
</Stack>
|
</Box>
|
||||||
</CardBody>
|
</Stack>
|
||||||
</Card>,
|
</CardBody>
|
||||||
|
</Card>
|
||||||
|
</Container>,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setHistory(cardList);
|
||||||
|
setLoading(false);
|
||||||
|
setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container maxW="container.md">
|
<Container maxW="container.md">
|
||||||
<Heading>User Lookup</Heading>
|
<Heading>User Lookup</Heading>
|
||||||
<HStack>
|
<Text>Look up a user's punishment history here.</Text>
|
||||||
|
{!hasResults ? (
|
||||||
|
<Alert status="warning" mt={2}>
|
||||||
|
<AlertIcon />
|
||||||
|
No information was found for this user. Perhaps you misspelt their
|
||||||
|
name?
|
||||||
|
</Alert>
|
||||||
|
) : null}
|
||||||
|
<HStack mt={5}>
|
||||||
<Input
|
<Input
|
||||||
id="username"
|
id="username"
|
||||||
onBeforeInput={(e) => {
|
onBeforeInput={(e) => {
|
||||||
@ -117,9 +162,14 @@ export default function () {
|
|||||||
|
|
||||||
if (data?.match(/\W/)) e.preventDefault();
|
if (data?.match(/\W/)) e.preventDefault();
|
||||||
}}
|
}}
|
||||||
|
onChange={(e) => setUsername(e.target.value)}
|
||||||
placeholder="Roblox username"
|
placeholder="Roblox username"
|
||||||
/>
|
/>
|
||||||
<Button ml="8px" onClick={async () => await getHistory()}>
|
<Button
|
||||||
|
ml="8px"
|
||||||
|
onClick={async () => await getHistory()}
|
||||||
|
isLoading={loading}
|
||||||
|
>
|
||||||
Search
|
Search
|
||||||
</Button>
|
</Button>
|
||||||
</HStack>
|
</HStack>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user