yay
This commit is contained in:
parent
add75dced1
commit
2310ba837a
1 changed files with 98 additions and 99 deletions
|
|
@ -1,126 +1,125 @@
|
||||||
import { createSignal, onMount } from "solid-js";
|
import {createSignal, onMount} from "solid-js";
|
||||||
import { ishover } from "../App";
|
import {ishover} from "../App";
|
||||||
|
|
||||||
interface Review {
|
interface Review {
|
||||||
reviewID: number;
|
id: number;
|
||||||
discordID: string;
|
reviewer: string;
|
||||||
reviewText: string;
|
review: string;
|
||||||
timestamp: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface NeoReview extends Review {
|
interface NeoReview extends Review {
|
||||||
global_name: string;
|
global_name: string;
|
||||||
username: string;
|
username: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Reviews() {
|
export default function Reviews() {
|
||||||
const [reviews, setReviews] = createSignal<NeoReview[]>([]);
|
const [reviews, setReviews] = createSignal<NeoReview[]>([]);
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
fetch("https://maggie.amy.rip/reviews")
|
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}`)
|
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then((user) => ({
|
.then((data: Review[]) => {
|
||||||
...review,
|
const promises = data.map((review) =>
|
||||||
global_name: user.global_name,
|
fetch(`https://discord-info.api.amy.rip/v1/user/${review.reviewer}`)
|
||||||
username: user.username,
|
.then((response) => response.json())
|
||||||
})),
|
.then((user) => ({
|
||||||
);
|
...review,
|
||||||
|
global_name: user.global_name,
|
||||||
|
username: user.username,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
|
||||||
Promise.all(promises)
|
Promise.all(promises)
|
||||||
.then((yeah) => {
|
.then((yeah) => {
|
||||||
setReviews(yeah);
|
setReviews(yeah);
|
||||||
})
|
})
|
||||||
.catch((error) =>
|
.catch((error) =>
|
||||||
console.error("Error fetching Discord user data:", error),
|
console.error("Error fetching Discord user data:", error),
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.catch((error) => console.error("Error fetching reviews:", error));
|
.catch((error) => console.error("Error fetching reviews:", error));
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class="reviewsection">
|
<div class="reviewsection">
|
||||||
<h1 class="reviewheadertext">Reviews</h1>
|
<h1 class="reviewheadertext">Reviews</h1>
|
||||||
<a
|
<a
|
||||||
style={{
|
style={{
|
||||||
opacity: ishover() ? '100%': '0%',
|
opacity: ishover() ? '100%' : '0%',
|
||||||
// visibility: !ishover() ? 'hidden' : 'visible',
|
// visibility: !ishover() ? 'hidden' : 'visible',
|
||||||
}}
|
}}
|
||||||
href="https://discord.com/oauth2/authorize?client_id=1208380910525743134&response_type=token&redirect_uri=https%3A%2F%2Famy.rip%2Freview%2F&scope=identify"
|
href="https://discord.com/oauth2/authorize?client_id=1208380910525743134&response_type=token&redirect_uri=https%3A%2F%2Famy.rip%2Freview%2F&scope=identify"
|
||||||
>
|
>
|
||||||
<p class="fadein">add your reviews here</p>
|
<p class="fadein">add your reviews here</p>
|
||||||
</a>
|
</a>
|
||||||
<div class="actualreviewdiv">
|
<div class="actualreviewdiv">
|
||||||
{reviews().length > 0 ? (
|
{reviews().length > 0 ? (
|
||||||
reviews()
|
reviews()
|
||||||
.reverse()
|
.reverse()
|
||||||
.map((review) => (
|
.map((review) => (
|
||||||
<div>
|
<div>
|
||||||
<SingleReview {...review} />
|
<SingleReview {...review} />
|
||||||
</div>
|
</div>
|
||||||
))
|
))
|
||||||
) : (
|
) : (
|
||||||
<div>Loading reviews...</div>
|
<div>Loading reviews...</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const theImager = async (id: string): Promise<string> =>
|
export const theImager = async (id: string): Promise<string> =>
|
||||||
await fetch(`https://discord-info.api.amy.rip/v1/user/${id}`)
|
await fetch(`https://discord-info.api.amy.rip/v1/user/${id}`)
|
||||||
.then((res) => res.json())
|
.then((res) => res.json())
|
||||||
.then((data) => data.avatar.link)
|
.then((data) => data.avatar.link)
|
||||||
.catch(() => "https://http.cat/status/100");
|
.catch(() => "https://http.cat/status/100");
|
||||||
|
|
||||||
function SingleReview(props: NeoReview) {
|
function SingleReview(props: NeoReview) {
|
||||||
const [imageSrc, setImageSrc] = createSignal("");
|
const [imageSrc, setImageSrc] = createSignal("");
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
const url = await theImager(props.discordID);
|
const url = await theImager(String(props.reviewer));
|
||||||
setImageSrc(url);
|
setImageSrc(url);
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class="singlereview">
|
<div class="singlereview">
|
||||||
<img
|
<img
|
||||||
src={imageSrc()}
|
src={imageSrc()}
|
||||||
alt="User Avatar"
|
alt="User Avatar"
|
||||||
style={{ "max-width": "3em", "border-radius": "30%" }}
|
style={{"max-width": "3em", "border-radius": "30%"}}
|
||||||
/>
|
/>
|
||||||
<div class="reviewinfo">
|
<div class="reviewinfo">
|
||||||
<div class="reviewname">
|
<div class="reviewname">
|
||||||
{props.global_name === null ? props.username : props.global_name}
|
{props.global_name === null ? props.username : props.global_name}
|
||||||
|
</div>
|
||||||
|
<div class="reviewtext">{props.review}</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="reviewtext">{props.reviewText}</div>
|
);
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function sendReview(
|
export async function sendReview(
|
||||||
review: string,
|
review: string,
|
||||||
token: string,
|
token: string,
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`https://maggie.amy.rip/sendreview?review=${review}`,
|
`https://maggie.amy.rip/sendreview?review=${review}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authentication: token,
|
Authentication: token,
|
||||||
},
|
},
|
||||||
method: "POST",
|
method: "POST",
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response.status !== 200) {
|
if (response.status !== 200) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
} catch (error) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue