added decline action for friend requests and room invites

This commit is contained in:
2026-01-05 20:57:25 +01:00
parent 23b1555dc7
commit 2612f1b4d1
9 changed files with 174 additions and 97 deletions

View File

@@ -25,10 +25,22 @@ export async function apiFetch<T>(
throw new Error("Session expired")
}
// Handle error responses
if (!res.ok) {
const text = await res.text()
throw new Error(text || res.statusText)
}
return res.json() as Promise<T>
// Get the response as text first
const responseText = await res.text()
if (!responseText) {
return {} as T
}
try {
return JSON.parse(responseText) as T
} catch (e) {
return responseText as unknown as T
}
}

View File

@@ -22,3 +22,10 @@ export function acceptFriendRequest(senderUuid: string) {
body: JSON.stringify({ sender_uuid: senderUuid }),
})
}
export function declineFriendRequest(senderUuid: string) {
return apiFetch<void>('/friends/decline', {
method: 'POST',
body: JSON.stringify({ sender_uuid: senderUuid }),
})
}

View File

@@ -33,3 +33,10 @@ export function acceptRoomInvite(senderUuid: string, roomUuid: string) {
body: JSON.stringify({ sender_uuid: senderUuid, room_uuid: roomUuid }),
})
}
export function declineRoomInvite(senderUuid: string, roomUuid: string) {
return apiFetch<void>('/rooms/decline', {
method: 'POST',
body: JSON.stringify({ sender_uuid: senderUuid, room_uuid: roomUuid }),
})
}