Skip to content

Commit

Permalink
mark all done
Browse files Browse the repository at this point in the history
  • Loading branch information
ragsav committed Sep 17, 2022
1 parent 8d37da4 commit cdf38ab
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
30 changes: 30 additions & 0 deletions js/redux/actions/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
12 changes: 10 additions & 2 deletions js/screens/DayScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
*
Expand Down Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -84,7 +88,11 @@ const DayScreen = ({navigation, tasks, deleteNoteSuccess, dispatch}) => {
anchor={
<Appbar.Action icon={'dots-vertical'} onPress={_handleToggleMenu} />
}>
<Menu.Item title="Mark all done" leadingIcon={'check-all'} />
<Menu.Item
title="Mark all done"
leadingIcon={'check-all'}
onPress={_handleMarkAllDone}
/>
<Menu.Item onPress={() => {}} title="Sort by" leadingIcon={'sort'} />
</Menu>
</Appbar.Header>
Expand Down

0 comments on commit cdf38ab

Please sign in to comment.