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', name: 'Remove',
icon: 'delete', icon: 'delete',
func: () => { func: () => {
close(); close('permanant_delete');
}, },
}, },
]; ];

View File

@@ -75,6 +75,21 @@ export class Dialog extends Component {
} }
break; 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: { case dialogActions.ACTION_EXIT: {
this.setState({ this.setState({
visible: false, visible: false,
@@ -86,7 +101,10 @@ export class Dialog extends Component {
case dialogActions.ACTION_EMPTY_TRASH: { case dialogActions.ACTION_EMPTY_TRASH: {
await db.trash.clear(); await db.trash.clear();
updateEvent({type: ACTIONS.TRASH}); 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({ this.setState({
visible: false, visible: false,
}); });

View File

@@ -40,6 +40,7 @@ export const dialogActions = {
ACTION_EMPTY_TRASH: 513, ACTION_EMPTY_TRASH: 513,
ACTION_EXIT_FULLSCREEN: 514, ACTION_EXIT_FULLSCREEN: 514,
ACTION_TRASH: 515, ACTION_TRASH: 515,
ACTION_PERMANANT_DELETE: 516,
}; };
export const ActionSheetEvent = ( 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 => { export const TEMPLATE_TRASH = type => {
return { return {
title: `Delete ${type}`, title: `Delete ${type}`,
@@ -348,6 +358,10 @@ export class DialogManager extends Component {
this._showSimpleDialog(TEMPLATE_DELETE(this.state.item.type)); this._showSimpleDialog(TEMPLATE_DELETE(this.state.item.type));
break; break;
} }
case 'permanant_delete': {
this._showSimpleDialog(TEMPLATE_PERMANANT_DELETE);
break;
}
case 'lock': { case 'lock': {
this._showVaultDialog(); this._showVaultDialog();
break; break;