-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
68 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
export const TODO_FILTER_STATUS = { | ||
all: undefined, | ||
active: false, | ||
completed: true, | ||
import { Filter_Statuses } from '../utils/enums/FiltersStatus'; | ||
|
||
export const TODO_FILTER_OPTIONS = [ | ||
{ value: 'all', title: 'All', id: 1 }, | ||
{ value: 'active', title: 'Active', id: 2 }, | ||
{ value: 'completed', title: 'Completed', id: 3 }, | ||
]; | ||
|
||
export const DEFAULT_FILTER_STATE = { | ||
status: Filter_Statuses.All, | ||
filter: '', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export enum Filter_Statuses { | ||
All = 'all', | ||
Active = 'active', | ||
Completed = 'completed', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,24 @@ | ||
import { TODO_FILTER_STATUS } from '../constants/TodoFilter'; | ||
import { ITodoFilter, Todo } from '../types/Todo'; | ||
|
||
export const getTodoFilterStatus = (status = '') => { | ||
if (status in TODO_FILTER_STATUS) { | ||
return TODO_FILTER_STATUS[status as keyof typeof TODO_FILTER_STATUS]; | ||
} | ||
return undefined; | ||
}; | ||
import { Filter_Statuses } from './enums/FiltersStatus'; | ||
|
||
export const getFiltredTodo = ( | ||
todos: Todo[], | ||
{ status, filter }: ITodoFilter, | ||
) => { | ||
const todoStatus = getTodoFilterStatus(status); | ||
|
||
return todos.filter(todo => | ||
todoStatus === undefined | ||
? todo.title.toLowerCase().includes(filter) | ||
: todo.title.toLowerCase().includes(filter) && | ||
todo.completed === todoStatus, | ||
let filteredTodos = todos.filter(({ title }) => | ||
title.toLowerCase().trim().includes(filter), | ||
); | ||
|
||
filteredTodos = filteredTodos.filter(({ completed }) => { | ||
switch (status) { | ||
case Filter_Statuses.Active: | ||
return !completed; | ||
case Filter_Statuses.Completed: | ||
return completed; | ||
default: | ||
return true; | ||
} | ||
}); | ||
|
||
return filteredTodos; | ||
}; |