static: add admin shell to improve admin experience
This commit is contained in:
		
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										50
									
								
								passbook/static/static/src/AdminSiteShell.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								passbook/static/static/src/AdminSiteShell.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,50 @@
 | 
			
		||||
import { customElement, html, LitElement, property } from "lit-element";
 | 
			
		||||
 | 
			
		||||
@customElement("pb-admin-shell")
 | 
			
		||||
export class AdminSiteShell extends LitElement {
 | 
			
		||||
 | 
			
		||||
    @property()
 | 
			
		||||
    set defaultUrl(value: string) {
 | 
			
		||||
        if (window.location.hash === "" && value !== undefined) {
 | 
			
		||||
            window.location.hash = `#${value}`;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    createRenderRoot() {
 | 
			
		||||
        return this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    constructor() {
 | 
			
		||||
        super();
 | 
			
		||||
        this.loadContent();
 | 
			
		||||
        window.addEventListener("hashchange", (e) => this.loadContent());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    loadContent() {
 | 
			
		||||
        let url = window.location.hash.slice(1, Infinity);
 | 
			
		||||
        if (url === "") {
 | 
			
		||||
            return
 | 
			
		||||
        }
 | 
			
		||||
        fetch(url).then(r => r.text()).then((t) => {
 | 
			
		||||
            this.innerHTML = t;
 | 
			
		||||
        }).then(() => {
 | 
			
		||||
            this.querySelectorAll("a").forEach(a => {
 | 
			
		||||
                if (a.href === "") {
 | 
			
		||||
                    return;
 | 
			
		||||
                }
 | 
			
		||||
                try {
 | 
			
		||||
                    const url = new URL(a.href);
 | 
			
		||||
                    const qs = url.search || "";
 | 
			
		||||
                    a.href = `#${url.pathname}${qs}`;
 | 
			
		||||
                } catch (e) {
 | 
			
		||||
                    a.href = `#${a.href}`;
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    render() {
 | 
			
		||||
        return html`${this.innerHTML}`;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -10,9 +10,6 @@ export class DropdownButton extends LitElement {
 | 
			
		||||
            btn.addEventListener("click", e => {
 | 
			
		||||
                menu.hidden = !menu.hidden;
 | 
			
		||||
            });
 | 
			
		||||
            btn.addEventListener("blur", e => {
 | 
			
		||||
                menu.hidden = true;
 | 
			
		||||
            });
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -7,3 +7,4 @@ import './FlowShellCard';
 | 
			
		||||
import './Messages';
 | 
			
		||||
import './Tabs';
 | 
			
		||||
import './ModalButton';
 | 
			
		||||
import './AdminSiteShell';
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user