diff --git a/src/app/runs/page.tsx b/src/app/runs/page.tsx index 7ba7a3c..35a1c37 100644 --- a/src/app/runs/page.tsx +++ b/src/app/runs/page.tsx @@ -16,53 +16,14 @@ import { import { cn } from "@/lib/utils"; import LiveRunRow from "./components/LiveRunNow"; import StatCard from "@/components/app/StatCard"; - -/* ---------------- mock data ---------------- */ - -const liveRuns = [ - { - id: 1, - username: "speedmaster_x", - problem: "Two Sum Dash", - category: "Any%", - time: "1:52.34", - pace: "-0:03", - status: "pb", - }, - { - id: 2, - username: "algo_ninja", - problem: "Binary Sprint", - category: "Any%", - time: "2:04.11", - pace: "+0:05", - status: "normal", - }, - { - id: 3, - username: "stackattack", - problem: "String Scramble", - category: "Easy", - time: "0:48.92", - pace: "-0:01", - status: "pb", - }, - { - id: 4, - username: "reset_king", - problem: "Linked List Rush", - category: "Any%", - time: "1:31.77", - pace: "+0:12", - status: "danger", - }, -]; - -/* ---------------- page ---------------- */ +import useAction from "@/hook/use-action"; +import { getLiveRuns } from "@/modules/live-run/actions"; export default function LiveRuns() { + const [liveRuns, liveRunsLoaded, liveRunsError] = useAction(getLiveRuns); + // Sort top runners (status === 'pb') to the top - const sortedRuns = [...liveRuns].sort((a, b) => { + const sortedRuns = [...(liveRuns || [])].sort((a, b) => { if (a.status === "pb" && b.status !== "pb") return -1; if (a.status !== "pb" && b.status === "pb") return 1; return 0; diff --git a/src/modules/live-run/actions.ts b/src/modules/live-run/actions.ts index 59d1635..221d8eb 100644 --- a/src/modules/live-run/actions.ts +++ b/src/modules/live-run/actions.ts @@ -1,3 +1,45 @@ "use server"; import * as Core from "./core"; +import { Run } from "./types"; + +export async function getLiveRuns(): Promise { + return [ + { + id: 1, + username: "speedmaster_x", + problem: "Two Sum Dash", + category: "Any%", + time: "1:52.34", + pace: "-0:03", + status: "pb", + }, + { + id: 2, + username: "algo_ninja", + problem: "Binary Sprint", + category: "Any%", + time: "2:04.11", + pace: "+0:05", + status: "normal", + }, + { + id: 3, + username: "stackattack", + problem: "String Scramble", + category: "Easy", + time: "0:48.92", + pace: "-0:01", + status: "pb", + }, + { + id: 4, + username: "reset_king", + problem: "Linked List Rush", + category: "Any%", + time: "1:31.77", + pace: "+0:12", + status: "danger", + }, + ]; +} diff --git a/src/modules/live-run/types.ts b/src/modules/live-run/types.ts index e69de29..b29b054 100644 --- a/src/modules/live-run/types.ts +++ b/src/modules/live-run/types.ts @@ -0,0 +1,9 @@ +export interface Run { + id: number; + username: string; + problem: string; + category: string; + time: string; + pace: string; + status: string; +}