diff --git a/src/app/run/page.tsx b/src/app/run/page.tsx index 8daf170..a464677 100644 --- a/src/app/run/page.tsx +++ b/src/app/run/page.tsx @@ -10,9 +10,16 @@ import useAction, { useActionInterval } from "@/hook/use-action"; import { getLiveRun } from "@/modules/live-run/actions"; import ProblemCard from "../problems/components/ProblemCard"; import ProfileCard from "./components/ProfileCard"; +import { getProblem } from "@/modules/problems/actions"; export default function Run() { - const [runInfo] = useActionInterval(getLiveRun, 1000); + const [run] = useActionInterval(getLiveRun, 1000); + const [problem] = useAction( + async () => (run?.id ? getProblem(run.problem) : null), + [run], + ); + + console.log(problem); const chatMessages: ChatMessage[] = [ { user: "Alice", message: "Nice split!", time: "1:53" }, @@ -40,21 +47,11 @@ export default function Run() {
- {runInfo && } + {run && }
- + {problem && }
diff --git a/src/hook/use-action.ts b/src/hook/use-action.ts index 4df2ca0..1af384a 100644 --- a/src/hook/use-action.ts +++ b/src/hook/use-action.ts @@ -2,7 +2,7 @@ import { useEffect, useState } from "react"; export default function useAction( action: () => Promise, - dependencies = [], + dependencies: any[] = [], ): [T | null, boolean, Error | null] { const [value, setValue] = useState(null); const [loaded, setLoaded] = useState(false); @@ -21,7 +21,7 @@ export default function useAction( export function useActionInterval( action: () => Promise, interval: number, - dependencies = [], + dependencies: any[] = [], ): [T | null, boolean, Error | null] { const [value, setValue] = useState(null); const [loaded, setLoaded] = useState(false); diff --git a/src/modules/live-run/actions.ts b/src/modules/live-run/actions.ts index c25967c..b1055ec 100644 --- a/src/modules/live-run/actions.ts +++ b/src/modules/live-run/actions.ts @@ -56,7 +56,7 @@ export async function getLiveRun(): Promise { username: "selimaj", start: 1770497350654, views: 230, - problem: "solve", + problem: "fix-auth-callback", category: "any%", runsCount: 0, }; diff --git a/src/modules/problems/actions.ts b/src/modules/problems/actions.ts index a549c80..22eb133 100644 --- a/src/modules/problems/actions.ts +++ b/src/modules/problems/actions.ts @@ -6,3 +6,7 @@ import { Problem } from "./types"; export async function getProblems(): Promise { return await Core.getProblems(); } + +export async function getProblem(id: string): Promise { + return await Core.getProblem(id); +} diff --git a/src/modules/problems/core.ts b/src/modules/problems/core.ts index 0189644..707a28f 100644 --- a/src/modules/problems/core.ts +++ b/src/modules/problems/core.ts @@ -1,7 +1,7 @@ "use server"; import "server-only"; -import { ProblemDefinition } from "./types"; +import { Problem, ProblemDefinition } from "./types"; const problems: ProblemDefinition[] = [ { @@ -35,7 +35,7 @@ const problems: ProblemDefinition[] = [ }, ]; -export async function getProblems() { +export async function getProblems(): Promise { return problems.map((def) => ({ id: def.id, title: def.title, @@ -44,3 +44,17 @@ export async function getProblems() { language: def.language, })); } + +export async function getProblem(id: string): Promise { + const problem = problems.find((p) => p.id === id); + + if (!problem) return; + + return { + id: problem.id, + title: problem.title, + description: problem.description, + difficulty: problem.difficulty, + language: problem.language, + }; +}