Live run moves
This commit is contained in:
@@ -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 });
|
||||
|
||||
@@ -43,11 +43,15 @@ function getLanguageExtension(lang: Language) {
|
||||
|
||||
export default function Editor({ run }: { run: LiveRun | null | undefined }) {
|
||||
const [editorView, setEditorView] = useState<EditorView>();
|
||||
const [moves] = useActionOnce<LiveRunMove[]>(
|
||||
async () => (run ? (await getLiveRunMoves(run.id)) || [] : []),
|
||||
const [moves] = useAction<LiveRunMove[]>(
|
||||
async () => (run ? await getLiveRunMoves(run.id) : []),
|
||||
[run],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
console.log(moves);
|
||||
}, [moves]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!editorView || !moves) return;
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
import "server-only";
|
||||
import Redis from "ioredis";
|
||||
|
||||
export const redis = new Redis(process.env.REDIS_URL!);
|
||||
@@ -7,7 +7,7 @@ export async function getLiveRuns(): Promise<LiveRun[]> {
|
||||
return Core.getLiveRuns();
|
||||
}
|
||||
|
||||
export async function getLiveRun(id: string): Promise<LiveRun | undefined> {
|
||||
export async function getLiveRun(id: string): Promise<LiveRun | null> {
|
||||
return Core.getLiveRun(id);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<LiveRunMove[]> {
|
||||
export async function submitRun(
|
||||
supabase: SupabaseClient,
|
||||
run: LiveRun,
|
||||
user_id: string
|
||||
user_id: string,
|
||||
) {
|
||||
const now = new Date();
|
||||
const durationMs = now.getTime() - run.start;
|
||||
|
||||
Reference in New Issue
Block a user