live runs #5
This commit is contained in:
+5
-44
@@ -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;
|
||||
|
||||
@@ -1,3 +1,45 @@
|
||||
"use server";
|
||||
|
||||
import * as Core from "./core";
|
||||
import { Run } from "./types";
|
||||
|
||||
export async function getLiveRuns(): Promise<Run[]> {
|
||||
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",
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
export interface Run {
|
||||
id: number;
|
||||
username: string;
|
||||
problem: string;
|
||||
category: string;
|
||||
time: string;
|
||||
pace: string;
|
||||
status: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user