From 77b6a6dfda7229d8723932e9968808f2e1a6fc86 Mon Sep 17 00:00:00 2001 From: erdfern <rexsomnia@pm.me> Date: Tue, 18 Mar 2025 14:11:05 +0100 Subject: [PATCH] --wip-- --- .../AnnotationEditor/AnnotationEditor.svelte | 11 +++++++++++ .../components/AnnotationEditor/live.svelte.ts | 18 ++++++++++++++---- src/lib/surreal.svelte.ts | 2 +- .../(app)/submission/[id]/eval/+page.svelte | 3 ++- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/lib/components/AnnotationEditor/AnnotationEditor.svelte b/src/lib/components/AnnotationEditor/AnnotationEditor.svelte index 49273af1..34afb754 100644 --- a/src/lib/components/AnnotationEditor/AnnotationEditor.svelte +++ b/src/lib/components/AnnotationEditor/AnnotationEditor.svelte @@ -1,6 +1,8 @@ <script lang="ts"> import type { AnnotationEditorProps, SourceSelection } from './types'; import CodeBlock from './CodeBlock.svelte'; + import { onDestroy, onMount } from 'svelte'; + import { liveEvaluation } from './live.svelte'; let { submission, evaluation, onSave = (_) => {} }: AnnotationEditorProps = $props(); @@ -10,6 +12,9 @@ let scoreDelta = $state(0); let annotationColor = $state('#ffeb3b'); // Default yellow + let liveQueryId: string | null = $state(null); + $inspect(liveQueryId); + const handleSelectionChange = (srcSelection: SourceSelection) => { sourceSelection = srcSelection; }; @@ -46,6 +51,12 @@ scoreDelta = 0; }; + onMount(async () => { + if (!evaluation) return; + liveQueryId = (await liveEvaluation(evaluation.id.toString())).toString(); + }); + onDestroy(() => {}); + /* // helper to determine if the selection is a point, in which case we want to annotate the whole line it's on function isSelectionPoint(s: SourceSelection): boolean { diff --git a/src/lib/components/AnnotationEditor/live.svelte.ts b/src/lib/components/AnnotationEditor/live.svelte.ts index bd231ae8..40d3ee6b 100644 --- a/src/lib/components/AnnotationEditor/live.svelte.ts +++ b/src/lib/components/AnnotationEditor/live.svelte.ts @@ -1,7 +1,17 @@ import { getDb } from '$lib/surreal.svelte'; -const liveEvaluation = async (evalId: string) => { - // const db = await getDb(); - // await db.signin({username: "root", password: "root"}); - // db.live() +export const liveEvaluation = async (evalId: string) => { + const db = await getDb(); + await db.signin({ username: 'root', password: 'root' }); + + const queryId = await db.live( + 'evaluation', + (action, result) => { + if (action === 'CLOSE') console.log('Closing live connection'); + if (action === 'UPDATE') console.log(result); + }, + false + ); + + return queryId; }; diff --git a/src/lib/surreal.svelte.ts b/src/lib/surreal.svelte.ts index 0c5c9582..426e7315 100644 --- a/src/lib/surreal.svelte.ts +++ b/src/lib/surreal.svelte.ts @@ -17,7 +17,7 @@ type DbConfig = { }; const DEFAULT_CONFIG: DbConfig = { - url: 'http://localhost:8000', + url: 'ws://localhost:8000/rpc', namespace: 'grady', database: 'dev' }; diff --git a/src/routes/(app)/submission/[id]/eval/+page.svelte b/src/routes/(app)/submission/[id]/eval/+page.svelte index 57fc0173..262de389 100644 --- a/src/routes/(app)/submission/[id]/eval/+page.svelte +++ b/src/routes/(app)/submission/[id]/eval/+page.svelte @@ -5,6 +5,7 @@ import { annotateSubmission } from '$lib/db/queries'; import { RecordId, StringRecordId } from 'surrealdb'; import type { PageProps } from './$types'; + import { onDestroy, onMount } from 'svelte'; ('$lib/components/AnnotationEditor'); // TODO live query @@ -14,7 +15,7 @@ const hasOngoingEvaluation = $derived(data.evaluation !== null); const onSave = async (annotation: Annotation) => { - await annotateSubmission(new StringRecordId(data.evaluation.id), annotation); + //await annotateSubmission(new StringRecordId(data.evaluation.id), annotation); }; function formatJson(obj: any) { -- GitLab