Skip to content

Commit

Permalink
Hide untranslated task groups
Browse files Browse the repository at this point in the history
  • Loading branch information
MikaKattainen committed May 18, 2021
1 parent 1fcbed1 commit c81414f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 22 deletions.
25 changes: 19 additions & 6 deletions src/components/TaskGroupItem/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ? '+' : ''
Expand All @@ -22,16 +33,18 @@ const TaskGroupItem = ({
}) => {
const languageInfo = taskGroup.languages.find(x => x.lang === language)

return (
return languageInfo ? (
<ListItem
guid={taskGroup.guid}
ageGroupGuid={ageGroupGuid}
title={languageInfo ? languageInfo.title : taskGroup.title}
subTitle={subTitle || getSubTaskGroupsOrTasksText(tasksTerm, taskGroup)}
title={languageInfo.title}
subTitle={
subTitle || getSubTaskGroupsOrTasksText(tasksTerm, taskGroup, language)
}
language={language}
icon={taskGroupGraphics[`Group${taskGroup.guid}`] || null}
/>
)
) : null
}

export default TaskGroupItem
34 changes: 18 additions & 16 deletions src/views/TaskGroup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,24 @@ const TaskGroup = () => {
const task_status = status === 'active' ? 'started' : `task_${status}`

return (
<ListItem
key={task.guid}
guid={task.guid}
ageGroupGuid={taskGroup.ageGroupGuid}
title={taskTranslation ? taskTranslation.title : task.title}
subTitle={getTermInLanguage(
generalTranslations,
`${task_status}`,
language
)}
language={language}
itemType={ITEM_TYPES.TASK}
showActions
showFavourite
isFavourite={favourites.includes(task.guid)}
/>
taskTranslation && (
<ListItem
key={task.guid}
guid={task.guid}
ageGroupGuid={taskGroup.ageGroupGuid}
title={taskTranslation.title}
subTitle={getTermInLanguage(
generalTranslations,
`${task_status}`,
language
)}
language={language}
itemType={ITEM_TYPES.TASK}
showActions
showFavourite
isFavourite={favourites.includes(task.guid)}
/>
)
)
})}
</TaskList>
Expand Down

0 comments on commit c81414f

Please sign in to comment.