make trash work properly

This commit is contained in:
ammarahm-ed
2020-03-04 11:58:44 +05:00
parent 0bd19e7bce
commit 12be797c61
3 changed files with 34 additions and 2 deletions

View File

@@ -272,7 +272,7 @@ export const ActionSheetComponent = ({
name: 'Remove',
icon: 'delete',
func: () => {
close();
close('permanant_delete');
},
},
];

View File

@@ -75,6 +75,21 @@ export class Dialog extends Component {
}
break;
}
case dialogActions.ACTION_PERMANANT_DELETE: {
if (item.dateCreated && history.selectedItemsList.length === 0) {
history.selectedItemsList = [];
history.selectedItemsList.push(item);
}
let ids = [];
history.selectedItemsList.forEach(item => ids.push(item.id));
await db.trash.delete(...ids);
updateEvent({type: ACTIONS.TRASH});
updateEvent({type: ACTIONS.CLEAR_SELECTION});
updateEvent({type: ACTIONS.SELECTION_MODE, enabled: false});
ToastEvent.show('Item permanantly deleted');
break;
}
case dialogActions.ACTION_EXIT: {
this.setState({
visible: false,
@@ -86,7 +101,10 @@ export class Dialog extends Component {
case dialogActions.ACTION_EMPTY_TRASH: {
await db.trash.clear();
updateEvent({type: ACTIONS.TRASH});
ToastEvent.show('Trash cleared', 'error', 1000, () => {}, '');
updateEvent({type: ACTIONS.CLEAR_SELECTION});
updateEvent({type: ACTIONS.SELECTION_MODE, enabled: false});
ToastEvent.show('Trash cleared', 'error');
this.setState({
visible: false,
});

View File

@@ -40,6 +40,7 @@ export const dialogActions = {
ACTION_EMPTY_TRASH: 513,
ACTION_EXIT_FULLSCREEN: 514,
ACTION_TRASH: 515,
ACTION_PERMANANT_DELETE: 516,
};
export const ActionSheetEvent = (
@@ -106,6 +107,15 @@ export const TEMPLATE_DELETE = type => {
};
};
export const TEMPLATE_PERMANANT_DELETE = {
title: `Delete Permanantly`,
paragraph: `Are you sure you want to delete this item permanantly from trash?`,
positiveText: 'Delete',
negativeText: 'Cancel',
action: dialogActions.ACTION_PERMANANT_DELETE,
icon: 'delete',
};
export const TEMPLATE_TRASH = type => {
return {
title: `Delete ${type}`,
@@ -348,6 +358,10 @@ export class DialogManager extends Component {
this._showSimpleDialog(TEMPLATE_DELETE(this.state.item.type));
break;
}
case 'permanant_delete': {
this._showSimpleDialog(TEMPLATE_PERMANANT_DELETE);
break;
}
case 'lock': {
this._showVaultDialog();
break;