created frontend with login, room listing and creation, and message page with all features

This commit is contained in:
2025-12-15 14:50:50 +01:00
parent f10c761f1b
commit d6a26c0d09
18 changed files with 653 additions and 165 deletions

27
src/api/client.ts Normal file
View File

@@ -0,0 +1,27 @@
import { useAuthStore } from '../stores/auth'
const BASE_URL = 'http://localhost:8080'
export async function apiFetch<T>(
path: string,
options: RequestInit = {}
): Promise<T> {
const auth = useAuthStore()
const res = await fetch(`${BASE_URL}${path}`, {
...options,
headers: {
'Content-Type': 'application/json',
...(auth.token ? { Authorization: `Bearer ${auth.token}` } : {}),
...options.headers,
},
})
if (!res.ok) {
const text = await res.text()
throw new Error(text || res.statusText)
}
return res.json()
}

17
src/api/messages.ts Normal file
View File

@@ -0,0 +1,17 @@
import { apiFetch } from './client'
import type { Message } from '../types/api'
export function fetchMessages(roomUuid: string) {
return apiFetch<Message[]>(`/messages/${roomUuid}`)
}
export function sendMessage(roomUuid: string, content: string) {
return apiFetch<Message>(`/messages/${roomUuid}`, {
method: 'POST',
body: JSON.stringify({
message_type: 'text',
content,
}),
})
}

14
src/api/rooms.ts Normal file
View File

@@ -0,0 +1,14 @@
import { apiFetch } from './client'
import type { Room } from '../types/api'
export function fetchRooms(userUuid: string) {
return apiFetch<Room[]>(`/rooms/${userUuid}`)
}
export function createRoom(name: string) {
return apiFetch<Room>('/rooms', {
method: 'POST',
body: JSON.stringify({ name }),
})
}