Newer
Older
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
const CreateArticleForm = require("./create-article-form");
class RootComponent {
constructor() {
this.state = {
selected_tab: ""
};
}
handle_nav_click(e) {
this.state.selected_tab = e.target.tab_name;
obj2htm.renderCycle();
}
render_state() {
switch (this.state.selected_tab) {
case "create":
return new CreateArticleForm().render();
case "update":
return undefined;
default:
return undefined;
}
}
render() {
return {
tag: "main",
contents: [
{ tag: "h1", contents: "Kuadrado admin panel" },
{
tag: "nav",
contents: [
{
tag: "span", contents: "Create article", tab_name: "create",
class: this.state.selected_tab === "create" ? "selected" : "",
onclick: this.handle_nav_click.bind(this),
},
{
tag: "span", contents: "Update article", tab_name: "update",
class: this.state.selected_tab === "update" ? "selected" : "",
onclick: this.handle_nav_click.bind(this),
},
],
},
this.render_state(),
],
};
}
}
module.exports = RootComponent;