diff --git a/admin-frontend/src/components/articles-list.js b/admin-frontend/src/components/articles-list.js index 144b708d4fe5e95e5eb3b02ec9884695dc49d3d6..477e13d964fe63efeb805aa7b1740b7960d37757 100644 --- a/admin-frontend/src/components/articles-list.js +++ b/admin-frontend/src/components/articles-list.js @@ -3,7 +3,8 @@ const { fetch_all_articles } = require("../xhr"); class ArticleList { - constructor() { + constructor(params) { + this.params = params; this.state = { articles: [] } @@ -28,7 +29,23 @@ class ArticleList { 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}` }; + return { + tag: "li", + style_rules: { display: "grid", gridTemplateColumns: "auto 100px 100px", gap: "10px" }, + contents: [ + { tag: "span", contents: `[${art.locale}] <b>${art.title}</b> - ${art._id.$oid}` }, + { + tag: "button", contents: "Select", onclick: () => { + this.params.on_select_article(art) + } + }, + { + tag: "button", contents: "Delete", onclick: () => { + this.params.on_delete_article(art) + } + }, + ] + }; }), } } diff --git a/admin-frontend/src/components/root.js b/admin-frontend/src/components/root.js index 4dfc6e540663ea44242d6575c0dd0764a07e8738..ee96c3b54cf18976892571e89128eec59537be48 100644 --- a/admin-frontend/src/components/root.js +++ b/admin-frontend/src/components/root.js @@ -21,8 +21,6 @@ class RootComponent { return new CreateArticleForm().render(); case "update": return new UpdateArticleForm().render(); - case "browse": - return new ArticleList().render(); default: return undefined; } @@ -46,11 +44,6 @@ class RootComponent { class: this.state.selected_tab === "update" ? "selected" : "", onclick: this.handle_nav_click.bind(this), }, - { - tag: "span", contents: "Browse articles", tab_name: "browse", - class: this.state.selected_tab === "browse" ? "selected" : "", - onclick: this.handle_nav_click.bind(this), - }, ], }, this.render_state(), diff --git a/admin-frontend/src/components/update-article-form.js b/admin-frontend/src/components/update-article-form.js index beff4462e4b1246367e431ba4a60f281d1dfa574..67994d3fdf82a9e56da2172634b363e4e996f7b6 100644 --- a/admin-frontend/src/components/update-article-form.js +++ b/admin-frontend/src/components/update-article-form.js @@ -1,13 +1,13 @@ "use strict"; -const { fetch_article_by_title, fetch_delete_article } = require("../xhr"); +const { fetch_article_by_title, fetch_delete_article, fetch_article } = require("../xhr"); +const ArticleList = require("./articles-list"); const CreateArticleForm = require("./create-article-form"); class UpdateArticleForm { constructor() { this.state = { search_article_title: "", - search_result: {}, article_to_update: {}, } } @@ -20,24 +20,17 @@ class UpdateArticleForm { }; } - handle_search_article() { - fetch_article_by_title(this.state.search_article_title) - .then(res => { - this.state.search_result = res; - this.state.article_to_update = {}; - this.refresh_search_result(); + handle_select_article(article) { + fetch_article(article._id.$oid) + .then(art => { + this.state.article_to_update = art; this.refresh_update_form(); - }) - .catch(err => alert(err)); - } - handle_select_result() { - this.state.article_to_update = { ...this.state.search_result }; - this.refresh_update_form(); + }).catch(err => console.log(err)) } - handle_delete_article() { - fetch_delete_article(this.state.search_result._id.$oid) + handle_delete_article(article) { + fetch_delete_article(article._id.$oid) .then(res => { alert(res); this.reset(); @@ -46,28 +39,6 @@ class UpdateArticleForm { .catch(err => alert(err)) } - render_search() { - return { - tag: "form", - onsubmit: e => { - e.preventDefault(); - this.handle_search_article(); - }, - style_rules: { display: "flex", gap: "10px", width: "100%" }, - contents: [ - { - tag: "input", type: "text", value: this.state.search_article_title, - style_rules: { flex: 1 }, - placeholder: "Search article by title", - oninput: e => this.state.search_article_title = e.target.value, - }, - { - tag: "input", type: "submit", value: "SEARCH" - } - ] - } - } - refresh_search_result() { obj2htm.subRender( this.render_search_result(), @@ -139,8 +110,10 @@ class UpdateArticleForm { maxWidth: "800px", }, contents: [ - this.render_search(), - this.render_search_result(), + new ArticleList({ + on_select_article: this.handle_select_article.bind(this), + on_delete_result: this.handle_delete_article.bind(this) + }).render(), { tag: "hr", style_rules: { width: "100%" } }, this.render_update_form(), ] diff --git a/public/games/games.js b/public/games/games.js index e6819c85c7dcfdf8808549806a780b33d5c22cef..95655ba851af3b5262ed62510cf4e53e04e9d218 100644 --- a/public/games/games.js +++ b/public/games/games.js @@ -3688,6 +3688,8 @@ const ImageCarousel = require("../../../generic-components/image-carousel"); const { getArticleBody } = require("../../../lib/article-utils"); const { fetch_json_or_error_text } = require("../../../lib/fetch"); const { MentaloEngine } = require("mentalo-engine"); +const translator = require("ks-cheap-translator"); +const t = translator.trad.bind(translator); class GameArticle { constructor(props) { @@ -3710,7 +3712,7 @@ class GameArticle { this.render_play_button = { tag: "button", class: "play-button", - contents: "Jouer", + contents: t("Jouer"), onclick: this.handle_click_play.bind(this, button_data.filename, button_data.engine) }; } @@ -3847,7 +3849,7 @@ class GameArticle { module.exports = GameArticle; -},{"../../../../../admin-frontend/src/constants":1,"../../../../constants":3,"../../../generic-components/image-carousel":34,"../../../lib/article-utils":35,"../../../lib/fetch":36,"mentalo-engine":5}],39:[function(require,module,exports){ +},{"../../../../../admin-frontend/src/constants":1,"../../../../constants":3,"../../../generic-components/image-carousel":34,"../../../lib/article-utils":35,"../../../lib/fetch":36,"ks-cheap-translator":4,"mentalo-engine":5}],39:[function(require,module,exports){ "use strict"; const { loadArticles } = require("../../../lib/article-utils");