|
|
|
|
@ -1,24 +1,24 @@
|
|
|
|
|
import './style.scss'
|
|
|
|
|
|
|
|
|
|
export const BASE_URL = import.meta.env.BASE_URL.replace(/\/$/, '')
|
|
|
|
|
|
|
|
|
|
let USER = false
|
|
|
|
|
export async function getLoggedUser() {
|
|
|
|
|
if (USER === false) {
|
|
|
|
|
console.log('Caching user data...')
|
|
|
|
|
USER = await (await fetch(`${import.meta.env.BASE_URL}api/user`)).json()
|
|
|
|
|
USER = await (await fetch(`${BASE_URL}/api/user`)).json()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return USER
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function createRoomEventStream(roomId) {
|
|
|
|
|
return new EventSource(`${import.meta.env.BASE_URL}api/room_events?id=${roomId}`)
|
|
|
|
|
return new EventSource(`${BASE_URL}/api/room_events?id=${roomId}`)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const Database = {
|
|
|
|
|
async getSeats(roomId) {
|
|
|
|
|
const seatList = await (
|
|
|
|
|
await fetch(`${import.meta.env.BASE_URL}api/room/seats?id=${roomId}`)
|
|
|
|
|
).json()
|
|
|
|
|
const seatList = await (await fetch(`${BASE_URL}/api/room/seats?id=${roomId}`)).json()
|
|
|
|
|
const seats = {}
|
|
|
|
|
|
|
|
|
|
seatList.forEach(seat => {
|
|
|
|
|
@ -28,7 +28,7 @@ export const Database = {
|
|
|
|
|
return seats
|
|
|
|
|
},
|
|
|
|
|
async occupySeat(seatId) {
|
|
|
|
|
const response = await fetch(`${import.meta.env.BASE_URL}api/seat/occupy?id=${seatId}`, {
|
|
|
|
|
const response = await fetch(`${BASE_URL}/api/seat/occupy?id=${seatId}`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
@ -39,7 +39,7 @@ export const Database = {
|
|
|
|
|
await response.json()
|
|
|
|
|
},
|
|
|
|
|
async leaveSeat(seatId) {
|
|
|
|
|
const response = await fetch(`${import.meta.env.BASE_URL}api/seat/leave?id=${seatId}`, {
|
|
|
|
|
const response = await fetch(`${BASE_URL}/api/seat/leave?id=${seatId}`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|