diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts index bebceba..b8b7220 100644 --- a/frontend/src/lib/api.ts +++ b/frontend/src/lib/api.ts @@ -65,3 +65,21 @@ export function createEdge( ): Promise { return post(accessToken, '/intentions/create_edge', data); } + +export interface CreateCommunicationRequest { + title?: string; + participant_ids?: string[]; + metadata?: Record; +} + +export interface CreateCommunicationResponse { + node_id: string; + edge_ids: string[]; +} + +export function createCommunication( + accessToken: string, + data: CreateCommunicationRequest +): Promise { + return post(accessToken, '/intentions/create_communication', data); +} diff --git a/frontend/src/lib/components/ChatInput.svelte b/frontend/src/lib/components/ChatInput.svelte new file mode 100644 index 0000000..bbc19bd --- /dev/null +++ b/frontend/src/lib/components/ChatInput.svelte @@ -0,0 +1,82 @@ + + +
+
+ + {#if error} +

{error}

+ {/if} +
+ +
diff --git a/frontend/src/routes/+page.svelte b/frontend/src/routes/+page.svelte index 37a9b38..474f7e5 100644 --- a/frontend/src/routes/+page.svelte +++ b/frontend/src/routes/+page.svelte @@ -4,7 +4,7 @@ import { connectionState, nodeStore, edgeStore, nodeAccessStore, nodeVisibility } from '$lib/spacetime'; import type { Node } from '$lib/spacetime'; import NodeEditor from '$lib/components/NodeEditor.svelte'; - import { createNode, createEdge } from '$lib/api'; + import { createNode, createEdge, createCommunication } from '$lib/api'; const session = $derived($page.data.session as Record | undefined); const nodeId = $derived(session?.nodeId as string | undefined); @@ -102,6 +102,19 @@ return edges.filter((e) => !e.system).map((e) => e.edgeType); } + /** Create a new communication node and navigate to it */ + async function handleNewChat() { + if (!accessToken) return; + try { + const { node_id } = await createCommunication(accessToken, { + title: 'Ny samtale', + }); + window.location.href = `/chat/${node_id}`; + } catch (e) { + console.error('Feil ved oppretting av samtale:', e); + } + } + /** Submit a new node via maskinrommet */ async function handleCreateNode(data: { title: string; content: string; html: string }) { if (!accessToken) throw new Error('Ikke innlogget'); @@ -156,7 +169,17 @@
-

Mottak

+
+

Mottak

+ {#if connected && accessToken} + + {/if} +
{#if connected && accessToken}
@@ -179,38 +202,64 @@
- + + {/if} {/each} {/if} diff --git a/frontend/src/routes/chat/[id]/+page.svelte b/frontend/src/routes/chat/[id]/+page.svelte new file mode 100644 index 0000000..ee6ccd2 --- /dev/null +++ b/frontend/src/routes/chat/[id]/+page.svelte @@ -0,0 +1,202 @@ + + +
+ +
+
+ + + + + +
+

+ {communicationNode?.title || 'Samtale'} +

+ {#if participants.length > 0} +

+ {participants.map(p => p.title || 'Ukjent').join(', ')} +

+ {/if} +
+ {#if connected} + Tilkoblet + {:else} + {connectionState.current} + {/if} +
+
+ + +
+
+ {#if !connected} +

Venter på tilkobling…

+ {:else if !communicationNode} +
+

Samtale ikke funnet

+

Kommunikasjonsnoden med ID {communicationId} finnes ikke eller er ikke tilgjengelig.

+ Tilbake til mottak +
+ {:else if messages.length === 0} +

+ Ingen meldinger ennå. Skriv den første! +

+ {:else} +
+ {#each messages as msg (msg.id)} + {@const own = isOwnMessage(msg)} +
+
+ {#if !own} +

+ {senderName(msg)} +

+ {/if} +

+ {msg.content || ''} +

+

+ {formatTime(msg)} +

+
+
+ {/each} +
+ {/if} +
+
+ + + {#if connected && accessToken && communicationNode} +
+
+ +
+
+ {/if} +
diff --git a/tasks.md b/tasks.md index 25c6bc7..0b48297 100644 --- a/tasks.md +++ b/tasks.md @@ -81,8 +81,7 @@ Uavhengige faser kan fortsatt plukkes. - [x] 5.1 Opprett kommunikasjonsnode: intensjon `create_communication` → node med `node_kind='communication'`, deltaker-edges, metadata (started_at). - [x] 5.2 Kontekst-arv: input i kommunikasjonsnode → automatisk `belongs_to`-edge. -- [~] 5.3 Chat-visning i frontend: noder med `belongs_to`-edge til kommunikasjonsnode, sortert på tid, sanntid via STDB. - > Påbegynt: 2026-03-17T16:08 +- [x] 5.3 Chat-visning i frontend: noder med `belongs_to`-edge til kommunikasjonsnode, sortert på tid, sanntid via STDB. - [ ] 5.4 Én-til-én chat: opprett kommunikasjonsnode med to deltakere. Full loop: skriv melding → vis i sanntid hos begge. ## Fase 6: CAS og mediefiler