Fixed last broken link probably

main
Antonio De Lucreziis 4 years ago
parent ec4d225c01
commit 3ea0971a2f

@ -15,7 +15,7 @@
</div> </div>
<div class="nav-group center"> <div class="nav-group center">
<div class="nav-item"> <div class="nav-item">
<a href="..">Posti DM</a> <a href=".">Posti DM</a>
</div> </div>
</div> </div>
</nav> </nav>

@ -1,4 +1,4 @@
import { createRoomEventStream, Database, getLoggedUser } from '../index.js' import { BASE_URL, createRoomEventStream, Database, getLoggedUser } from '../index.js'
import { addTooltipElementListener, resetTooltip, setTooltipText } from './tooltip.js' import { addTooltipElementListener, resetTooltip, setTooltipText } from './tooltip.js'
async function renderWidget(elSeatMap, seats) { async function renderWidget(elSeatMap, seats) {
@ -67,7 +67,7 @@ export async function createSeatWidget($roomGrid, roomId) {
// Listener for takeing or leaving a seat // Listener for takeing or leaving a seat
$seat.addEventListener('click', async () => { $seat.addEventListener('click', async () => {
if (!user) { if (!user) {
location.href = '/login.html' location.href = `${BASE_URL}/`
return return
} }

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

@ -1,5 +1,5 @@
import { createGridLineCanvas } from '../components/gridlines.js' import { createGridLineCanvas } from '../components/gridlines.js'
import { getLoggedUser } from '../index.js' import { BASE_URL, getLoggedUser } from '../index.js'
import { createSeatWidget } from '../components/seats-widget.js' import { createSeatWidget } from '../components/seats-widget.js'
import { createClock } from '../components/clock.js' import { createClock } from '../components/clock.js'
import { attachTooltip } from '../components/tooltip.js' import { attachTooltip } from '../components/tooltip.js'
@ -15,8 +15,8 @@ const elLogoutButton = document.querySelector('#logout-button')
const elRoomGrid = document.querySelector('.room-grid') const elRoomGrid = document.querySelector('.room-grid')
async function logout() { async function logout() {
await fetch(`${import.meta.env.BASE_URL}api/logout`, { method: 'POST' }) await fetch(`${BASE_URL}/api/logout`, { method: 'POST' })
location.href = `${import.meta.env.BASE_URL}` location.href = `${BASE_URL}`
} }
async function main() { async function main() {

@ -1,4 +1,4 @@
import { getLoggedUser } from '../index.js' import { BASE_URL, getLoggedUser } from '../index.js'
// //
// Page Element // Page Element
@ -33,7 +33,7 @@ function displayErrorString(e) {
async function login() { async function login() {
try { try {
const response = await fetch(`${import.meta.env.BASE_URL}api/login`, { const response = await fetch(`${BASE_URL}/api/login`, {
method: 'POST', method: 'POST',
headers: { headers: {
Accept: 'application/json, text/plain, */*', Accept: 'application/json, text/plain, */*',
@ -50,7 +50,7 @@ async function login() {
return return
} }
location.href = `${import.meta.env.BASE_URL}` location.href = `${BASE_URL}/`
} catch (e) { } catch (e) {
displayErrorString(e) displayErrorString(e)
} }
@ -64,7 +64,7 @@ async function main() {
const user = await getLoggedUser() const user = await getLoggedUser()
console.log(user) console.log(user)
if (user) { if (user) {
location.href = `${import.meta.env.BASE_URL}` location.href = `${BASE_URL}/`
} }
elLoginButton.addEventListener('click', () => login()) elLoginButton.addEventListener('click', () => login())

Loading…
Cancel
Save