From 85e70157ada40ec356c33999023c03cafb36788f Mon Sep 17 00:00:00 2001 From: amy Date: Tue, 24 Dec 2024 22:20:10 +0330 Subject: [PATCH] GAHHH I BROKE IT --- src/components/api.tsx | 198 ++++++++++++++++++++++------------------- 1 file changed, 104 insertions(+), 94 deletions(-) diff --git a/src/components/api.tsx b/src/components/api.tsx index 373b96b..acc3c4f 100644 --- a/src/components/api.tsx +++ b/src/components/api.tsx @@ -1,115 +1,125 @@ -import {createSignal, onMount} from "solid-js" -import {ishover} from "../App"; +import { createSignal, onMount } from "solid-js"; +import { ishover } from "../App"; interface Review { - reviewID: number; - discordID: string; - reviewText: string; - timestamp: string; + reviewID: number; + discordID: string; + reviewText: string; + timestamp: string; } interface NeoReview extends Review { - global_name: string; - username: string + global_name: string; + username: string; } - export default function Reviews() { - const [reviews, setReviews] = createSignal([]); - onMount(() => { - fetch("https://review.exhq.dev/getreviews") - .then(response => response.json()) - .then((data: Review[]) => { - const promises = data.map(review => ( - fetch(`https://dc-lookup.spiro.exhq.dev/v1/user/${review.discordID}`) - .then(response => response.json()) - .then(user => ({ - ...review, - global_name: user.global_name, - username: user.username - })) - )); + const [reviews, setReviews] = createSignal([]); + onMount(() => { + fetch("https://review.exhq.dev/getreviews") + .then((response) => response.json()) + .then((data: Review[]) => { + const promises = data.map((review) => + fetch(`https://dc-lookup.spiro.exhq.dev/v1/user/${review.discordID}`) + .then((response) => response.json()) + .then((user) => ({ + ...review, + global_name: user.global_name, + username: user.username, + })), + ); - Promise.all(promises) - .then(yeah => { - setReviews(yeah); - }) - .catch(error => console.error("Error fetching Discord user data:", error)); - }) - .catch(error => console.error("Error fetching reviews:", error)); - }); + Promise.all(promises) + .then((yeah) => { + setReviews(yeah); + }) + .catch((error) => + console.error("Error fetching Discord user data:", error), + ); + }) + .catch((error) => console.error("Error fetching reviews:", error)); + }); - - return ( - <> - -

add your reviews here

-
-

Reviews

-
- {reviews().length > 0 ? ( - reviews().reverse().map((review) => ( -
- -
- )) - ) : ( -
Loading reviews...
- )} -
- - - ) + return ( + <> + +

add your reviews here

+
+

Reviews

+
+ {reviews().length > 0 ? ( + reviews() + .reverse() + .map((review) => ( +
+ +
+ )) + ) : ( +
Loading reviews...
+ )} +
+ + ); } - -export const theImager = async (id: string): Promise => (await fetch(`https://dc-lookup.spiro.exhq.dev/v1/user/${id}`) - .then(res => res.json()).then(data => "https://proxy.spiro.exhq.dev/_/plain/"+data.avatar.link).catch(() => "https://http.cat/status/100")); +export const theImager = async (id: string): Promise => + await fetch(`https://dc-lookup.spiro.exhq.dev/v1/user/${id}`) + .then((res) => res.json()) + .then((data) => "https://proxy.spiro.exhq.dev/_/plain/" + data.avatar.link) + .catch(() => "https://http.cat/status/100"); function SingleReview(props: NeoReview) { - const [imageSrc, setImageSrc] = createSignal(""); + const [imageSrc, setImageSrc] = createSignal(""); - onMount(async () => { - const url = await theImager(props.discordID); - setImageSrc(url); - }); + onMount(async () => { + const url = await theImager(props.discordID); + setImageSrc(url); + }); - return ( -
- User Avatar -
-
- {props.global_name === null ? props.username : props.global_name} -
-
{props.reviewText}
-
+ return ( +
+ User Avatar +
+
+ {props.global_name === null ? props.username : props.global_name}
- ); +
{props.reviewText}
+
+
+ ); } -export async function sendReview(review: string, token: string): Promise { - try { - const response = await fetch(`https://review.exhq.dev/sendreview?review=${review}`, { - headers: { - "Auth": token, - }, - method: "POST" - }); +export async function sendReview( + review: string, + token: string, +): Promise { + try { + const response = await fetch( + `https://review.exhq.dev/sendreview?review=${review}`, + { + headers: { + Auth: token, + }, + method: "POST", + }, + ); - if (response.status !== 200) { - return false; - } - - return true; - } catch (error) { - return false; + if (response.status !== 200) { + return false; } -} \ No newline at end of file + + return true; + } catch (error) { + return false; + } +}