-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathApp.js
More file actions
40 lines (31 loc) · 969 Bytes
/
App.js
File metadata and controls
40 lines (31 loc) · 969 Bytes
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
import SideBar from "../components/SideBar/SideBar.js";
import Content from "../components/Content/Content.js";
import { initRouter } from "../utils/router.js";
export default function App({ $target }) {
const $layout = document.createElement("div");
$layout.classList.add("layout-main");
const sideBar = new SideBar({
$target: $layout,
});
const content = new Content({
$target: $layout,
initialState: {
documentId: "new",
},
});
this.route = async () => {
$target.innerHTML = ``;
const { pathname } = window.location;
if (pathname === "/") {
await sideBar.setState();
await content.setState({ documentId: "new" });
} else if (pathname.indexOf("/documents/" === 0)) {
const [, , documentId] = pathname.split("/");
await sideBar.setState();
await content.setState({ documentId });
}
$target.appendChild($layout);
};
this.route();
initRouter(() => this.route());
}