Jake Vanderwerf
2025-09-30 19d20832e881112d197254b1c41edc4c0f03758e
1
(()=>{class e{constructor(){this.currentPage="",this.a11y=window.jvbA11y,this.mainContent=document.querySelector("main .replace"),this.loadingManager=window.jvbLoading,this.cache=JSON.parse(localStorage.getItem("dashboard-cache")||"{}"),this.cacheTimeout=3e5;const e=window.location.pathname.split("/dash/")[1];this.currentPage=e?e.replace("/",""):"",this.currentPage&&this.initPageContent(this.currentPage),this.initNavigation()}initNavigation(){const e=window.location.pathname.split("/dash/")[1];this.currentPage=e?e.replace("/",""):"",this.updateNavState(this.currentPage),window.addEventListener("popstate",(e=>{const t=e.state?.page||"";this.navigateTo(t,!0)})),document.querySelectorAll("a[data-dash]").forEach((e=>{e.addEventListener("click",(t=>{t.preventDefault(),this.navigateTo(e.dataset.page)}))}))}updateNavState(e){const t=document.querySelector(".dashboard-footer nav");t&&t.querySelectorAll("a").forEach((t=>{const n=t.dataset.page;t.parentElement.classList.toggle("current",n===e),n===e?t.setAttribute("aria-current","page"):t.removeAttribute("aria-current")}))}getCachedContent(e){const t=this.cache[e];return t?Date.now()-t.timestamp>this.cacheTimeout?(delete this.cache[e],localStorage.setItem("dashboard-cache",JSON.stringify(this.cache)),null):t.content:null}setCachedContent(e,t){e&&t&&(this.cache[e]={content:t,timestamp:Date.now()},localStorage.setItem("dashboard-cache",JSON.stringify(this.cache)))}async navigateTo(e,t=!1){try{if("dash"===e&&(e=""),e===this.currentPage)return;if(!t){const t=e?`/dash/${e}/`:"/dash";history.pushState({page:e},"",t)}const n=this.mainContent?.innerHTML;n&&this.setCachedContent(this.currentPage,n);const a=this.getCachedContent(e);if(a)return this.mainContent.innerHTML=a,this.currentPage=e,this.updateNavState(e),void this.initPageContent(e);window.location.href=e?`/dash/${e}/`:"/dash"}catch(e){console.error("Navigation error:",e),this.loadingManager&&this.loadingManager.showError(e.message||"Navigation failed")}finally{this.a11y.announce(`Currently on ${e} dashboard page.`)}}updateContent(e){this.mainContent.innerHTML=e.content,document.title=`${e.title} - edmonton.ink Dashboard`,this.currentPage&&this.initPageContent(this.currentPage)}initPageContent(e){switch(console.log(e),e){case"settings":this.initNorthehSettingsPage();break;case"bio":this.initBioPage();break;case"favourites":new window.favouritesManager;break;case"shop":this.initShopPage();break;case"news":new window.newsManager;break;case"events":new window.crud({content:"event"})}}initBioPage(){const e=document.querySelector("form");e&&(console.log(jvbSettings,"jvbSettings"),new window.formManager(e,{loadingManager:window.jvbLoading,objectId:jvbSettings.currentUser.artistID,highlights:{style:{max:3,name:"jvb_top_styles",label:"Highlight Styles",description:"Select up to 3 styles to highlight"}}}))}initNorthehSettingsPage(){new window.jvbTabs(document.querySelector(".replace"))}initSettingsPage(){const e=document.querySelector("form");window.jvbForm.addForm(e,{content:"artist",onSave:e=>{Object.hasOwn(e,"menu_section_order")&&(e.menu_section_order=JSON.stringify(e.menu_section_order)),e.user=jvbSettings.currentUser,window.jvbQueue.addToQueue({type:"user_settings",data:e})}})}initShopPage(){document.querySelector("form")&&new window.jvbShopManager}clearCache(){this.cache={}}}document.addEventListener("DOMContentLoaded",(()=>{window.dashboardNavigator=new e}))})();