web: remove Roblox.ts

This commit is contained in:
rhpidfyre 2024-12-14 00:37:52 -05:00
parent dff37906c6
commit ae6e968135
4 changed files with 7 additions and 68 deletions

View File

@ -1,24 +1,11 @@
"use client"
import { useState, useEffect } from "react"
import { SubmissionInfo } from "@/app/ts/Submission" import { SubmissionInfo } from "@/app/ts/Submission"
import { AssetImage } from "@/app/ts/Roblox"
import Image from "next/image"
interface AssetID { interface AssetID {
id: SubmissionInfo["AssetID"] id: SubmissionInfo["AssetID"]
} }
function MapImage(asset: AssetID) { function MapImage() {
const [assetImage, setAssetImage] = useState(""); return <p>Fetching map image...</p>
useEffect(() => {
AssetImage(asset.id, "420x420").then(image => setAssetImage(image))
}, [asset.id]);
if (!assetImage) {
return <p>Fetching map image...</p>;
}
return <Image src={assetImage} alt="Map Image"/>
} }
export { export {

View File

@ -9,7 +9,7 @@ interface ReviewButton {
} }
function ReviewButtonClicked(action: Action) { function ReviewButtonClicked(action: Action) {
const post = fetch(`http://localhost:3000/v1/submissions/1/status/${action}`, { fetch(`http://localhost:3000/v1/submissions/1/status/${action}`, {
method: "POST", method: "POST",
headers: { headers: {
"Content-type": "application/json", "Content-type": "application/json",

View File

@ -2,7 +2,7 @@
import { SubmissionStatus, SubmissionStatusToString } from "@/app/ts/Submission"; import { SubmissionStatus, SubmissionStatusToString } from "@/app/ts/Submission";
import type { CreatorAndReviewStatus } from "./_comments"; import type { CreatorAndReviewStatus } from "./_comments";
import { MapImage, type AssetID } from "./_map"; import { MapImage } from "./_map";
import { useParams } from "next/navigation"; import { useParams } from "next/navigation";
import ReviewButtons from "./_reviewButtons"; import ReviewButtons from "./_reviewButtons";
import { Rating } from "@mui/material"; import { Rating } from "@mui/material";
@ -34,11 +34,11 @@ function Ratings() {
) )
} }
function RatingArea(asset: AssetID) { function RatingArea() {
return ( return (
<aside className="review-area"> <aside className="review-area">
<section className="map-image-area"> <section className="map-image-area">
<MapImage id={asset.id}/> <MapImage/>
</section> </section>
<Ratings/> <Ratings/>
<ReviewButtons/> <ReviewButtons/>
@ -71,7 +71,7 @@ export default function SubmissionInfoPage() {
<Webpage> <Webpage>
<main className="map-page-main"> <main className="map-page-main">
<section className="review-section"> <section className="review-section">
<RatingArea id={432}/> <RatingArea/>
<TitleAndComments name={dynamicId.submissionId} creator="Quaternions" review={SubmissionStatus.Accepted} comments={[]}/> <TitleAndComments name={dynamicId.submissionId} creator="Quaternions" review={SubmissionStatus.Accepted} comments={[]}/>
</section> </section>
</main> </main>

View File

@ -1,48 +0,0 @@
const FALLBACK_IMAGE = ""
type thumbsizes = "420" | "720"
type thumbsize<S extends thumbsizes> = `${S}x${S}`
type ParsedJson<A> = {
errors: A,
data: {
[0]: {
state: string,
imageUrl: string,
}
}
}
function Parse<A>(json: ParsedJson<A>): string {
if (json.errors) {
console.warn(json.errors)
return FALLBACK_IMAGE
}
if (json.data) {
const data = json.data[0]
if (!data) { //For whatever reason roblox will sometimes return an empty array instead of an error message
console.warn("Roblox gave us no data,", data)
return FALLBACK_IMAGE
}
if (data.state === "Completed") {
return data.imageUrl
}
console.warn(data)
return FALLBACK_IMAGE
}
return FALLBACK_IMAGE
}
async function AvatarHeadshot<S extends thumbsizes>(userid: number, size: thumbsize<S>): Promise<string> {
const avatarthumb_api = fetch(`https://thumbnails.roproxy.com/v1/users/avatar-headshot?userIds=${userid}&size=${size}&format=Png&isCircular=false`)
return avatarthumb_api.then(res => res.json()).then(json => Parse(json))
}
async function AssetImage<S extends thumbsizes>(assetid: number, size: thumbsize<S>): Promise<string> {
const avatarthumb_api = fetch(`https://thumbnails.roblox.com/v1/assets?assetIds=${assetid}&returnPolicy=PlaceHolder&size=${size}&format=Png&isCircular=false`)
return avatarthumb_api.then(res => res.json()).then(json => Parse(json))
}
export {
AvatarHeadshot,
AssetImage
}