diff --git a/src/app/api/run/move/route.ts b/src/app/api/run/move/route.ts index 876aa5a..d691e2b 100644 --- a/src/app/api/run/move/route.ts +++ b/src/app/api/run/move/route.ts @@ -27,6 +27,8 @@ export async function POST(req: NextRequest) { { status: 401 }, ); + console.log(moves); + const run = await Core.addLiveRunMoves(liveRun.id, moves); return NextResponse.json({ ok: true, run }); diff --git a/src/app/runs/[runId]/components/Editor.tsx b/src/app/runs/[runId]/components/Editor.tsx index dc9b865..4394595 100644 --- a/src/app/runs/[runId]/components/Editor.tsx +++ b/src/app/runs/[runId]/components/Editor.tsx @@ -43,11 +43,15 @@ function getLanguageExtension(lang: Language) { export default function Editor({ run }: { run: LiveRun | null | undefined }) { const [editorView, setEditorView] = useState(); - const [moves] = useActionOnce( - async () => (run ? (await getLiveRunMoves(run.id)) || [] : []), + const [moves] = useAction( + async () => (run ? await getLiveRunMoves(run.id) : []), [run], ); + useEffect(() => { + console.log(moves); + }, [moves]); + useEffect(() => { if (!editorView || !moves) return; diff --git a/src/lib/redis.ts b/src/lib/redis.ts new file mode 100644 index 0000000..79e09ad --- /dev/null +++ b/src/lib/redis.ts @@ -0,0 +1,4 @@ +import "server-only"; +import Redis from "ioredis"; + +export const redis = new Redis(process.env.REDIS_URL!); diff --git a/src/modules/live-run/actions.ts b/src/modules/live-run/actions.ts index 55b95a6..ce70ac6 100644 --- a/src/modules/live-run/actions.ts +++ b/src/modules/live-run/actions.ts @@ -7,7 +7,7 @@ export async function getLiveRuns(): Promise { return Core.getLiveRuns(); } -export async function getLiveRun(id: string): Promise { +export async function getLiveRun(id: string): Promise { return Core.getLiveRun(id); } diff --git a/src/modules/live-run/core.ts b/src/modules/live-run/core.ts index fde98d8..7958b82 100644 --- a/src/modules/live-run/core.ts +++ b/src/modules/live-run/core.ts @@ -3,9 +3,7 @@ import "server-only"; import { LiveRun, LiveRunMove } from "./types"; import { SupabaseClient } from "@supabase/supabase-js"; -import Redis from "ioredis"; - -const redis = new Redis(process.env.REDIS_URL!); +import { redis } from "@/lib/redis"; /** -------------------- Live Runs in Redis -------------------- */ @@ -57,6 +55,9 @@ export async function addLiveRunMoves(id: string, moves: LiveRunMove[]) { const pipeline = redis.pipeline(); moves.forEach((move) => { pipeline.rpush(`liveRunMoves:${id}`, JSON.stringify(move)); + setTimeout(() => { + redis.del(`liveRunMoves:${id}`); + }, 3000); }); // Optional: keep moves ephemeral automatically after 3s @@ -81,7 +82,7 @@ export async function getLiveRunMoves(id: string): Promise { export async function submitRun( supabase: SupabaseClient, run: LiveRun, - user_id: string + user_id: string, ) { const now = new Date(); const durationMs = now.getTime() - run.start;