feat: now simple users can only occupy one seat at a time
This commit is contained in:
@@ -65,7 +65,7 @@ export async function createSeatWidget($roomGrid, roomId) {
|
||||
})
|
||||
|
||||
// Listener for takeing or leaving a seat
|
||||
$seat.addEventListener('click', () => {
|
||||
$seat.addEventListener('click', async () => {
|
||||
if (!user) {
|
||||
location.href = '/login.html'
|
||||
return
|
||||
@@ -76,14 +76,38 @@ export async function createSeatWidget($roomGrid, roomId) {
|
||||
if (occupiedBy.length === 0) {
|
||||
const confirmResponse = confirm('Occupare il posto?')
|
||||
if (confirmResponse) {
|
||||
$seat.classList.remove('libero')
|
||||
Database.occupySeat(seatId)
|
||||
try {
|
||||
await Database.occupySeat(seatId)
|
||||
$seat.classList.remove('libero')
|
||||
$seat.classList.add('mio')
|
||||
} catch (e) {
|
||||
alert(e.toString())
|
||||
}
|
||||
}
|
||||
} else if (occupiedBy.length === 1 && occupiedBy[0] === user.id) {
|
||||
const answer = confirm('Lasciare veramente il posto?')
|
||||
if (answer) {
|
||||
$seat.classList.remove('mio')
|
||||
Database.leaveSeat(seatId)
|
||||
try {
|
||||
await Database.leaveSeat(seatId)
|
||||
$seat.classList.remove('mio')
|
||||
$seat.classList.add('libero')
|
||||
} catch (e) {
|
||||
alert(e.toString())
|
||||
}
|
||||
}
|
||||
} else if (
|
||||
user.permissions.includes('admin') ||
|
||||
user.permissions.includes('moderator')
|
||||
) {
|
||||
const answer = confirm(`Liberare veramente il posto di @${occupiedBy[0]}?`)
|
||||
if (answer) {
|
||||
try {
|
||||
await Database.leaveSeat(seatId)
|
||||
$seat.classList.remove('occupato')
|
||||
$seat.classList.add('libero')
|
||||
} catch (e) {
|
||||
alert(e.toString())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
alert('Posto già occupato!')
|
||||
|
||||
Reference in New Issue
Block a user