From 4839be414c218937e57beb3f90c5ac67b5e60495 Mon Sep 17 00:00:00 2001 From: data Date: Thu, 11 Jul 2019 00:32:13 +0200 Subject: [PATCH] filter Articles by Tag --- src/components/articles.js | 86 ++++++++++++++++++++++---------------- src/components/tags.js | 84 +++++++++++++++++-------------------- src/controllers/tags.js | 65 ++++++++++++++++++++++------ 3 files changed, 139 insertions(+), 96 deletions(-) diff --git a/src/components/articles.js b/src/components/articles.js index 910d11a..43ef703 100644 --- a/src/components/articles.js +++ b/src/components/articles.js @@ -1,49 +1,61 @@ import React from 'react' function Articles(props) { - console.log(props.tags, props.articles) - const articles = props.articles || [] + var articles = props.articles || [] if (props.selectedTagId) { - const name = props.tags.filter(t => t.id === props.selectedTagId)['name'] - //articles = props.tags.getArticles() + articles = props.articles.filter(a => + filterArticles(a, props.selectedTagId), + ) + } + function filterArticles(article, tagId) { + if (article.tags && article.tags.filter(t => t.id === tagId).length !== 0) { + return article + } } return (

Articles

+ {props.selectedTagId ? ( + + ) : ( + '' + )}