From f419182a9f5dbf8ae0b9c1b2682c9c9209a756c2 Mon Sep 17 00:00:00 2001 From: regalijan Date: Thu, 19 Oct 2023 16:50:30 -0400 Subject: [PATCH] Finish search method for hammer page --- app/routes/hammer.tsx | 72 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/app/routes/hammer.tsx b/app/routes/hammer.tsx index 0ba87ae..4af651b 100644 --- a/app/routes/hammer.tsx +++ b/app/routes/hammer.tsx @@ -3,11 +3,13 @@ import { Button, Card, CardBody, + CardHeader, Container, Heading, HStack, Image, Input, + Link, Stack, StackDivider, Text, @@ -40,9 +42,72 @@ export default function () { const [status, setStatus] = useState(""); const [visible, setVisible] = useState(false); const [avatarUrl, setAvatarUrl] = useState(""); + const [history, setHistory] = useState([]); + + async function getHistory() { + const username = (document.getElementById("username") as HTMLInputElement) + .value; + + if (username.length < 4) return alert("Username is too short!"); + + const historyResp = await fetch(`/api/game-bans/${username}/history`); + + if (!historyResp.ok) + return alert( + `ERROR: ${((await historyResp.json()) as { error: string }).error}`, + ); + + const history: { [k: string]: any }[] = await historyResp.json(); + + if (!history.length) return alert("No history for this user."); + + const cardList = []; + + for (const entry of history) { + const url = entry.entity.properties.evidence.stringValue; + const isUrl = () => { + try { + new URL(url).href; + return true; + } catch { + return false; + } + }; + + cardList.push( + + + {new Date().toLocaleString()} + + + } spacing="4"> + + ACTION + + {entry.entity.properties.action.stringValue} + + + + EVIDENCE + + {isUrl() ? ( + + {url} + + ) : ( + url + )} + + + + + , + ); + } + } return ( - + User Lookup - + @@ -81,6 +148,7 @@ export default function () { + {history} ); }