add deleteAllCookies util function,

add functionality to nav buttons

Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
Arthur Lu 2023-01-09 15:08:45 -08:00
parent 78dd24d6cc
commit 9d0e0db27d
4 changed files with 20 additions and 4 deletions

View File

@ -11,8 +11,8 @@
<body>
<header>
<nav class="btn-group">
<button class="active">INSTANCES</button>
<button>LOGOUT</button>
<button id="instances" class="active">INSTANCES</button>
<button id="logout">LOGOUT</button>
</nav>
</header>
<main><div id="instance-container" class="center-div"></div></main>

View File

@ -1,9 +1,20 @@
import {request, goToPage} from "./utils.js";
import {request, goToPage, deleteAllCookies} from "./utils.js";
window.addEventListener("DOMContentLoaded", init);
async function init () {
await populateInstances();
let instances = document.querySelector("nav #instances");
instances.addEventListener("click", () => {
goToPage("index.html");
});
let logout = document.querySelector("nav #logout");
logout.addEventListener("click", () => {
deleteAllCookies();
goToPage("login.html");
});
}
async function populateInstances () {

View File

@ -1,8 +1,9 @@
import {requestTicket, setTicket, ResponseError, NetworkError, goToPage} from "./utils.js";
import {requestTicket, setTicket, ResponseError, NetworkError, goToPage, deleteAllCookies} from "./utils.js";
window.addEventListener("DOMContentLoaded", init);
function init (){
deleteAllCookies();
let formSubmitButton = document.querySelector("#submit");
let status = document.querySelector("#status");
formSubmitButton.addEventListener("click", async (e) => {

View File

@ -87,3 +87,7 @@ export function getURIData () {
let url = new URL(window.location.href);
return Object.fromEntries(url.searchParams);
}
export function deleteAllCookies () {
document.cookie.split(";").forEach(function(c) { document.cookie = c.replace(/^ +/, "").replace(/=.*/, "=;expires=" + new Date().toUTCString() + ";path=/"); });
}