import { Button, Spinner } from "@nextui-org/react"; import { useAppContext } from "../contexts/AppContext"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faXmark } from "@fortawesome/free-solid-svg-icons"; import { ComponentPropsWithoutRef, useEffect, useRef, useState } from "react"; import { api } from "../lib/utils"; import { UserCard } from "./Profile/UserCard"; interface IPixel { userId: string; x: number; y: number; color: string; createdAt: Date; } interface IUser { sub: string; display_name?: string; picture_url?: string; profile_url?: string; isAdmin: boolean; isModerator: boolean; } interface IInstance { hostname: string; name?: string; logo_url?: string; banner_url?: string; } export const PixelWhoisSidebar = () => { const { pixelWhois, setPixelWhois } = useAppContext(); const [loading, setLoading] = useState(true); const [whois, setWhois] = useState<{ pixel: IPixel; otherPixels: number; user: IUser | null; instance: IInstance | null; }>(); useEffect(() => { if (!pixelWhois) return; setLoading(true); setWhois(undefined); api< { pixel: IPixel; otherPixels: number; user: IUser | null; instance: IInstance | null; }, "no_pixel" >(`/api/canvas/pixel/${pixelWhois.x}/${pixelWhois.y}`) .then(({ status, data }) => { if (status === 200) { if (data.success) { setWhois({ pixel: data.pixel, otherPixels: data.otherPixels, user: data.user, instance: data.instance, }); } else { // error wahhhhhh } } else { // error wahhhh } }) .finally(() => { setLoading(false); }); }, [pixelWhois]); return (
Placed At | {whois?.pixel.createdAt?.toString()} |
---|---|
Covered Pixels | {whois?.otherPixels} |