diff --git a/js/redux/actions/task.js b/js/redux/actions/task.js index 9d05b5f..ca1f4b9 100644 --- a/js/redux/actions/task.js +++ b/js/redux/actions/task.js @@ -215,6 +215,36 @@ export const editTask = dispatch(editTaskState({loading: false, success: true, error})); } }; + +export const editTaskMarkBulkDone = + ({ids}) => + async dispatch => { + if (Array.isArray(ids) && ids.length > 0) { + dispatch(editTaskState({loading: true, success: false, error: null})); + try { + const _d = Date.now(); + const tasksToBeMarkedDone = await database + .get('tasks') + .query(Q.where('id', Q.oneOf(ids))) + .fetch(); + const batchUpdateRecords = tasksToBeMarkedDone.map(task => { + return task.prepareUpdate(t => { + t.isDone = true; + task.doneTimestamp = _d; + }); + }); + database.write(async () => { + database.batch(...batchUpdateRecords); + }); + + dispatch(editTaskState({loading: false, success: true, error: null})); + Logger.pageLogger('editTaskMarkBulkDone : success'); + } catch (error) { + Logger.pageLogger('editTaskMarkBulkDone : error', error); + dispatch(editTaskState({loading: false, success: true, error})); + } + } + }; export const editTaskTitle = ({id, title}) => async dispatch => { diff --git a/js/screens/DayScreen.js b/js/screens/DayScreen.js index 4163894..bbe8dea 100644 --- a/js/screens/DayScreen.js +++ b/js/screens/DayScreen.js @@ -8,7 +8,7 @@ import {connect} from 'react-redux'; import TaskItem from '../components/TaskItem'; import {database} from '../db/db'; import Task from '../db/models/Task'; -import {resetDeleteNoteState} from '../redux/actions'; +import {editTaskMarkBulkDone, resetDeleteNoteState} from '../redux/actions'; /** * @@ -55,6 +55,10 @@ const DayScreen = ({navigation, tasks, deleteNoteSuccess, dispatch}) => { // handle functions const _handleToggleMenu = () => setIsMenuOpen(!isMenuOpen); + const _handleMarkAllDone = () => { + dispatch(editTaskMarkBulkDone({ids: tasks?.map(task => task.id)})); + setIsMenuOpen(false); + }; // navigation functions const _navigateBack = () => { @@ -84,7 +88,11 @@ const DayScreen = ({navigation, tasks, deleteNoteSuccess, dispatch}) => { anchor={ }> - + {}} title="Sort by" leadingIcon={'sort'} />