diff --git a/src/components/api.tsx b/src/components/api.tsx index 40cf6d8..638fdbf 100644 --- a/src/components/api.tsx +++ b/src/components/api.tsx @@ -1,126 +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; + id: number; + reviewer: string; + review: 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://maggie.amy.rip/reviews") - .then((response) => response.json()) - .then((data: Review[]) => { - const promises = data.map((review) => - fetch(`https://discord-info.api.amy.rip/v1/user/${review.discordID}`) + const [reviews, setReviews] = createSignal([]); + onMount(() => { + fetch("https://maggie.amy.rip/reviews") .then((response) => response.json()) - .then((user) => ({ - ...review, - global_name: user.global_name, - username: user.username, - })), - ); + .then((data: Review[]) => { + const promises = data.map((review) => + fetch(`https://discord-info.api.amy.rip/v1/user/${review.reviewer}`) + .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 ( -
-

Reviews

- +

Reviews

+
-

add your reviews here

-
-
- {reviews().length > 0 ? ( - reviews() - .reverse() - .map((review) => ( -
- -
- )) - ) : ( -
Loading reviews...
- )} -
-
- ); + }} + href="https://discord.com/oauth2/authorize?client_id=1208380910525743134&response_type=token&redirect_uri=https%3A%2F%2Famy.rip%2Freview%2F&scope=identify" + > +

add your reviews here

+ +
+ {reviews().length > 0 ? ( + reviews() + .reverse() + .map((review) => ( +
+ +
+ )) + ) : ( +
Loading reviews...
+ )} +
+ + ); } export const theImager = async (id: string): Promise => - await fetch(`https://discord-info.api.amy.rip/v1/user/${id}`) - .then((res) => res.json()) - .then((data) => data.avatar.link) - .catch(() => "https://http.cat/status/100"); + await fetch(`https://discord-info.api.amy.rip/v1/user/${id}`) + .then((res) => res.json()) + .then((data) => 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(String(props.reviewer)); + setImageSrc(url); + }); - return ( -
- User Avatar -
-
- {props.global_name === null ? props.username : props.global_name} + return ( +
+ User Avatar +
+
+ {props.global_name === null ? props.username : props.global_name} +
+
{props.review}
+
-
{props.reviewText}
-
-
- ); + ); } export async function sendReview( - review: string, - token: string, + review: string, + token: string, ): Promise { - try { - const response = await fetch( - `https://maggie.amy.rip/sendreview?review=${review}`, - { - headers: { - Authentication: token, - }, - method: "POST", - }, - ); + try { + const response = await fetch( + `https://maggie.amy.rip/sendreview?review=${review}`, + { + headers: { + Authentication: token, + }, + method: "POST", + }, + ); - if (response.status !== 200) { - return false; + if (response.status !== 200) { + return false; + } + + return true; + } catch (error) { + return false; } - - return true; - } catch (error) { - return false; - } }