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
"use strict";
const { fetch_all_articles } = require("../xhr");
class ArticleList {
constructor() {
this.state = {
articles: []
}
this.fetch_list();
}
fetch_list() {
fetch_all_articles()
.then(articles => {
this.state.articles = articles;
this.refresh_list();
})
.catch(err => console.log(err))
}
refresh_list() {
obj2htm.subRender(this.render_list(), document.getElementById("browse-articles-results"), { mode: "replace" })
}
render_list() {
return {
tag: "ul",
id: "browse-articles-results",
contents: this.state.articles.map(art => {
return { tag: "li", contents: `[${art.locale}] <b>${art.title}</b> - ${art._id.$oid}` };
}),
}
}
render() {
return {
tag: "div",
contents: [
{ tag: "button", onclick: this.fetch_list.bind(this), contents: "REFRESH" },
this.render_list()
],
}
}
}
module.exports = ArticleList;