11.6 Filter the Tasks based on Search Value
This commit is contained in:
parent
bcc2b87e6e
commit
001b7c6b85
@ -63,20 +63,37 @@ const actions = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getters = {
|
const getters = {
|
||||||
tasksTodo: (state) => {
|
tasksFiltered: (state) => {
|
||||||
const tasks = {}
|
const tasksFiltered = {}
|
||||||
|
if (state.search) {
|
||||||
Object.keys(state.tasks).forEach(function (key) {
|
Object.keys(state.tasks).forEach(function (key) {
|
||||||
const task = state.tasks[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(tasksFiltered).forEach(function (key) {
|
||||||
|
const task = tasksFiltered[key]
|
||||||
if (!task.completed) {
|
if (!task.completed) {
|
||||||
tasks[key] = task
|
tasks[key] = task
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return tasks
|
return tasks
|
||||||
},
|
},
|
||||||
tasksCompleted: (state) => {
|
tasksCompleted: (state, getters) => {
|
||||||
|
const tasksFiltered = getters.tasksFiltered
|
||||||
const tasks = {}
|
const tasks = {}
|
||||||
Object.keys(state.tasks).forEach(function (key) {
|
Object.keys(tasksFiltered).forEach(function (key) {
|
||||||
const task = state.tasks[key]
|
const task = tasksFiltered[key]
|
||||||
if (task.completed) {
|
if (task.completed) {
|
||||||
tasks[key] = task
|
tasks[key] = task
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user