diff --git a/src/app/dashboard/writer/page.tsx b/src/app/dashboard/writer/page.tsx new file mode 100644 index 00000000..17e26eb3 --- /dev/null +++ b/src/app/dashboard/writer/page.tsx @@ -0,0 +1,124 @@ +"use client"; + +import { useAccount } from "wagmi"; +import { useQuery } from "@tanstack/react-query"; +import { supabase, type Storyline } from "../../../../lib/supabase"; +import { ConnectWallet } from "../../../components/ConnectWallet"; +import { DeadlineCountdown } from "../../../components/DeadlineCountdown"; +import Link from "next/link"; + +async function fetchWriterStorylines( + address: string, +): Promise { + if (!supabase) return []; + const { data } = await supabase + .from("storylines") + .select("*") + .eq("writer_address", address.toLowerCase()) + .eq("hidden", false) + .order("block_timestamp", { ascending: false }) + .returns(); + return data ?? []; +} + +export default function WriterDashboard() { + const { address, isConnected } = useAccount(); + + const { data: storylines = [], isLoading } = useQuery({ + queryKey: ["writer-storylines", address], + queryFn: () => fetchWriterStorylines(address!), + enabled: isConnected && !!address, + }); + + if (!isConnected) { + return ( +
+

+ Connect your wallet to view your dashboard. +

+ +
+ ); + } + + return ( +
+

+ Writer Dashboard +

+

+ {storylines.length}{" "} + {storylines.length === 1 ? "storyline" : "storylines"} +

+ + {isLoading &&

Loading...

} + +
+ {storylines.map((s) => ( + + ))} + {!isLoading && storylines.length === 0 && ( +

+ No storylines yet. +

+ )} +
+
+ ); +} + +function StorylineDetail({ storyline }: { storyline: Storyline }) { + return ( +
+
+ + {storyline.title} + + {storyline.sunset && ( + + complete + + )} +
+ +
+
+ + Plots + + {storyline.plot_count} +
+
+ + Created + + + {storyline.block_timestamp + ? new Date(storyline.block_timestamp).toLocaleDateString( + "en-US", + { month: "short", day: "numeric", year: "numeric" }, + ) + : "—"} + +
+
+ + Deadline + + + {storyline.has_deadline ? "72h" : "none"} + +
+
+ + {!storyline.sunset && + storyline.has_deadline && + storyline.last_plot_time && ( + + )} +
+ ); +}