async function showTournaments() { let url = 'https://dragonmaster.pl/inz/tournaments'; try { let res = await fetch(url); return await res.json(); } catch (error) { console.log(error); } } function saveIdTournament(id) { localStorage.setItem('tournamentId', id); } function checkRoleCreator() { fetch('https://dragonmaster.pl/inz/user', { headers: { Authorization: ("Bearer " + localStorage.getItem("token")) } }) .then(res => res.json()) .then(json => { let test = (json['id']) renderTournaments(test) }) } async function renderTournaments(test) { let tournaments = await showTournaments(); let html = ''; tournaments.forEach(tournament => { // console.log(test) organiser = `${tournament.creator}`; console.log(organiser) // console.log(organiser) if (organiser == test) { let htmlSegment = `

${tournament.name}

${tournament.place} ${tournament.from} do ${tournament.to}
`; html += htmlSegment; } else { let htmlSegment = `

${tournament.name}

${tournament.place} ${tournament.from} do ${tournament.to}
`; html += htmlSegment; } }); let container = document.querySelector('.tournament-list'); container.innerHTML = html; } function checkRoleforDelete() { } function logout() { localStorage.clear(); location.reload(); } function logoutVisibility() { if (localStorage.getItem("token") !== null) { document.getElementById("logout").style.display = ""; } else { document.getElementById("logout").style.display = "none"; } } function loginVisibility() { if (localStorage.getItem("token") !== null) { document.getElementById("login").style.display = "none"; } else { document.getElementById("login").style.display = ""; } } function checkRole() { if (localStorage.getItem("token") !== null) { fetch('https://dragonmaster.pl/inz/user', { headers: { Authorization: ("Bearer " + localStorage.getItem("token")) } }) .then(res => res.json()) .then(json => { if (json['role'] == '1') { document.getElementById("creator").style.display = "none"; } else { document.getElementById("creator").style.display = ''; } }) } else { document.getElementById("creator").style.display = "none"; } } // function creatorVisibility() { // if (localStorage.getItem("token") == null) { // document.getElementById("creator").style.display = "none"; // } // else if (checkRole()) { // document.getElementById("creator").style.display = "none"; // } // else { // document.getElementById("creator").style.display = ""; // } // }