import Link from "next/link"; import React, { useEffect, useState } from "react"; import { toast } from "sonner"; export default function AdminDashboard({ animeCount, infoCount, metaCount, report, }) { const [message, setMessage] = useState(""); const [selectedTime, setSelectedTime] = useState(""); const [unixTimestamp, setUnixTimestamp] = useState(null); const [broadcast, setBroadcast] = useState(); const [reportId, setReportId] = useState(); useEffect(() => { async function getBroadcast() { const res = await fetch("/api/v2/admin/broadcast", { method: "GET", headers: { "Content-Type": "application/json", "X-Broadcast-Key": "get-broadcast", }, }); const data = await res.json(); if (data) { setBroadcast(data); } } getBroadcast(); }, []); const handleSubmit = async (e) => { e.preventDefault(); let unixTime; if (selectedTime) { unixTime = Math.floor(new Date(selectedTime).getTime() / 1000); setUnixTimestamp(unixTime); } const res = await fetch("/api/v2/admin/broadcast", { method: "POST", headers: { "Content-Type": "application/json", "X-Broadcast-Key": "get-broadcast", }, body: JSON.stringify({ message, startAt: unixTime, show: true, }), }); const data = await res.json(); console.log({ message, unixTime, data }); }; const handleRemove = async () => { try { const res = await fetch("/api/v2/admin/broadcast", { method: "DELETE", headers: { "Content-Type": "application/json", "X-Broadcast-Key": "get-broadcast", }, }); const data = await res.json(); console.log(data); } catch (error) { console.log(error); } }; const handleResolved = async () => { try { console.log(reportId); if (!reportId) return toast.error("reportId is required"); const res = await fetch("/api/v2/admin/bug-report", { method: "DELETE", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ reportId, }), }); const data = await res.json(); if (res.status === 200) { toast.success(data.message); } } catch (error) { console.log(`error while resolving ${error}`); } }; return (
Stats
{animeCount}
Anime
{infoCount}
detail info
{metaCount}
Metadata
Broadcast
Unix Timestamp: {unixTimestamp}
)}Recent Reports