From c81414f9e37136dbf1b1e6eb7b18c175ec9732f6 Mon Sep 17 00:00:00 2001 From: Mika Kattainen Date: Fri, 14 May 2021 16:14:16 +0300 Subject: [PATCH] Hide untranslated task groups --- src/components/TaskGroupItem/index.js | 25 +++++++++++++++----- src/views/TaskGroup/index.js | 34 ++++++++++++++------------- 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/src/components/TaskGroupItem/index.js b/src/components/TaskGroupItem/index.js index 725885d..40d6b87 100644 --- a/src/components/TaskGroupItem/index.js +++ b/src/components/TaskGroupItem/index.js @@ -2,11 +2,22 @@ import React from 'react' import ListItem from 'components/ListItem' import taskGroupGraphics from 'graphics/taskGroups' -export const getSubTaskGroupsOrTasksText = (tasksTerm, taskGroup) => { +const getTranslatedTaskCount = (tasks, lang) => { + return tasks.reduce((acc, task) => { + if (task.languages.find(language => language.lang === lang)) { + acc++ + } + return acc + }, 0) +} + +export const getSubTaskGroupsOrTasksText = (tasksTerm, taskGroup, language) => { const term = tasksTerm || 'aktiviteettia' const tasksExist = taskGroup.tasks.length > 0 const tasksGroupsExist = taskGroup.taskgroups.length > 0 - const tasksText = tasksExist ? taskGroup.tasks.length : '' + const tasksText = tasksExist + ? getTranslatedTaskCount(taskGroup.tasks, language) + : '' const taskGroupsText = tasksGroupsExist ? taskGroup.taskgroups.length : '' return `${tasksText} ${ tasksExist && tasksGroupsExist ? '+' : '' @@ -22,16 +33,18 @@ const TaskGroupItem = ({ }) => { const languageInfo = taskGroup.languages.find(x => x.lang === language) - return ( + return languageInfo ? ( - ) + ) : null } export default TaskGroupItem diff --git a/src/views/TaskGroup/index.js b/src/views/TaskGroup/index.js index 4aada0b..f4c4f41 100644 --- a/src/views/TaskGroup/index.js +++ b/src/views/TaskGroup/index.js @@ -95,22 +95,24 @@ const TaskGroup = () => { const task_status = status === 'active' ? 'started' : `task_${status}` return ( - + taskTranslation && ( + + ) ) })}