-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
50 lines (46 loc) · 1.37 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
import Router from "./src/router/router";
import "./src/components/note/note";
import store from "./src/store";
import "./src/components/notes/notes";
import "./src/components/emojiPicker";
import "./src/components/Todo/Todo";
import "./src/components/Todo/TodoItem/TodoItem";
import "./index.css";
const router = new Router({
mode: "hash",
root: "/",
});
class App extends HTMLElement {
connectedCallback() {
router
.add(/note\/(.*)/, (id) => {
const alreadyNote = store.state.notes.map((i) => +i.id === +id);
if (!alreadyNote.includes(true)) {
return window.history.pushState(
null,
null,
`#note/${
store.state.notes[store.state.notes.length - 1]
? store.state.notes[store.state.notes.length - 1].id || 1
: 1
}`
);
}
this.innerHTML = `<note-pad note-id=${id}></note-pad>`;
store.events.publish("updateNote");
return store.events.publish("hashChange", id);
})
.add("", () => {
return window.history.pushState(
null,
null,
`#note/${
store.state.notes[store.state.notes.length - 1]
? store.state.notes[store.state.notes.length - 1].id || 1
: 1
}`
);
});
}
}
window.customElements.define("main-app", App);