import './style.scss' let USER = false export async function getLoggedUser() { if (USER === false) { console.log('Caching user data...') USER = await (await fetch('/api/user')).json() } return USER } export function createRoomEventStream(roomId) { return new EventSource(`/api/room_events?id=${roomId}`) } export const Database = { async getSeats(roomId) { const seatList = await (await fetch(`/api/room/seats?id=${roomId}`)).json() const seats = {} seatList.forEach(seat => { seats[seat.id] = seat }) return seats }, async occupySeat(seatId) { await (await fetch(`/api/seat/occupy?id=${seatId}`, { method: 'POST' })).json() }, async leaveSeat(seatId) { await (await fetch(`/api/seat/leave?id=${seatId}`, { method: 'POST' })).json() }, }