added roominvites in frontend in a notifications page and added clap to define backend port

This commit is contained in:
2025-12-31 12:14:46 +01:00
parent fb514f1efe
commit e7a575ae03
12 changed files with 258 additions and 145 deletions

View File

@@ -1,5 +1,5 @@
import { fetch } from '@tauri-apps/plugin-http';
import { initAuth, logout } from '../store.ts'
import { getAuthData, clearAuthData } from '../authStore'
import { API } from '../main.ts'
import router from '../router'
@@ -7,12 +7,11 @@ export async function apiFetch<T>(
path: string,
options: RequestInit = {}
): Promise<T> {
const auth = await initAuth()
const auth = await getAuthData()
const res = await fetch(`${API}${path}`, {
method: options.method || 'GET',
body: options.body,
...options,
method: options.method || 'GET',
headers: {
'Content-Type': 'application/json',
...(auth.token ? { Authorization: `Bearer ${auth.token}` } : {}),
@@ -21,7 +20,7 @@ export async function apiFetch<T>(
})
if (res.status === 401) {
await logout()
await clearAuthData()
router.push('/login')
throw new Error("Session expired")
}

View File

@@ -1,8 +1,8 @@
import { apiFetch } from './client'
import type { Room } from '../types'
import type { Room, RoomInvite } from '../types'
export function fetchRooms(userUuid: string) {
return apiFetch<Room[]>(`/rooms/${userUuid}`)
export function fetchRooms() {
return apiFetch<Room[]>(`/rooms`)
}
export function createRoom(name: string, global: boolean) {
@@ -12,3 +12,20 @@ export function createRoom(name: string, global: boolean) {
})
}
export function fetchRoomInvites() {
return apiFetch<RoomInvite[]>('/rooms/invites')
}
export function sendRoomInvite(receiverUsername: string, roomUuid: string) {
return apiFetch<void>('/rooms/invite', {
method: 'POST',
body: JSON.stringify({ receiver_username: receiverUsername, room_uuid: roomUuid }),
});
}
export function acceptRoomInvite(senderUuid: string, roomUuid: string) {
return apiFetch<void>('/rooms/join', {
method: 'POST',
body: JSON.stringify({ sender_uuid: senderUuid, room_uuid: roomUuid }),
})
}