Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
articles-list.js 1.12 KiB
Newer Older
  • Learn to ignore specific revisions
  • "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;