11.6 Filter the Tasks based on Search Value

This commit is contained in:
Fredrick W Warren 2021-02-10 14:45:47 -08:00
parent bcc2b87e6e
commit 001b7c6b85

View File

@ -63,20 +63,37 @@ const actions = {
}
const getters = {
tasksTodo: (state) => {
tasksFiltered: (state) => {
const tasksFiltered = {}
if (state.search) {
Object.keys(state.tasks).forEach(function (key) {
const task = state.tasks[key],
taskNameLowerCase = task.name.toLowerCase(),
searchLowerCase = state.search.toLowerCase()
if (taskNameLowerCase.includes(searchLowerCase)) {
tasksFiltered[key] = task
}
})
return tasksFiltered
}
return state.tasks
},
tasksTodo: (state, getters) => {
const tasksFiltered = getters.tasksFiltered
const tasks = {}
Object.keys(state.tasks).forEach(function (key) {
const task = state.tasks[key]
Object.keys(tasksFiltered).forEach(function (key) {
const task = tasksFiltered[key]
if (!task.completed) {
tasks[key] = task
}
})
return tasks
},
tasksCompleted: (state) => {
tasksCompleted: (state, getters) => {
const tasksFiltered = getters.tasksFiltered
const tasks = {}
Object.keys(state.tasks).forEach(function (key) {
const task = state.tasks[key]
Object.keys(tasksFiltered).forEach(function (key) {
const task = tasksFiltered[key]
if (task.completed) {
tasks[key] = task
}