-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
106 lines (81 loc) · 2.63 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import {
LitElement,
html,
nothing,
} from "/vendor/@lit/[email protected]/lit-all.min.js";
// Add shoelace once. Use components anywhere.
import { setBasePath } from "/vendor/@shoelace/[email protected]/utilities/base-path.js";
import "/vendor/@shoelace/[email protected]/shoelace.js";
// Import stylesheets
import { mainStyles } from "/styles/app.index.styles.js";
// App state (singleton)
import { store } from "/state/store.js";
import { StoreSubscriber } from "/state/subscribe.js";
// Views
import "/components/views/index.js";
import "/components/views/welcome-dialog/index.js";
// Render chunks
import * as renderMethods from "/components/views/app-view/renders/index.js";
// Router (singleton)
import { getRouter } from "/router/router.js";
// Utils
import debounce from "/utils/debounce.js";
import { bindToClass } from "/utils/class-bind.js";
// Do this once to set the location of shoelace assets (icons etc..)
setBasePath("/vendor/@shoelace/[email protected]/");
class DogemapApp extends LitElement {
static properties = {};
constructor() {
super();
}
connectedCallback() {
super.connectedCallback();
this.context = new StoreSubscriber(this, store);
// Add the resize event listener
// window.addEventListener("resize", this._debouncedHandleResize);
// Initial check to set orientation on load
this._handleResize();
bindToClass(renderMethods, this);
}
disconnectedCallback() {
// window.removeEventListener("resize", this._debouncedHandleResize);
super.disconnectedCallback();
}
firstUpdated() {
// Initialise our router singleton and provide it a target elemenet.
getRouter(this.shadowRoot.querySelector("#Outlet"));
}
_handleResize() {
// Determine the orientation based on the window width
const orientation = window.innerWidth > 920 ? "landscape" : "portrait";
// Update the appContext.orientation state
store.updateState({ appContext: { orientation } });
}
openDrawer() {
const drawer = this.shadowRoot.querySelector("sl-drawer");
drawer.show();
}
handleMenuClick() {
this.menuVisible = !this.menuVisible;
}
render() {
const CURPATH = this.context.store.appContext.pathname || "";
const showChrome = !CURPATH.startsWith("/login");
return html`
<div id="App">
${showChrome ? this.renderNav() : nothing}
<main id="Main">
<div id="Outlet"></div>
</main>
${showChrome ? this.renderFooter() : nothing}
</div>
<aside>
<welcome-dialog></welcome-dialog>
</aside>
<style>
${mainStyles}
</style>
`;
}
}
customElements.define("dogemap-app", DogemapApp);