refactor dialog to show dialogs impertively

This commit is contained in:
ammarahm-ed
2021-07-01 22:34:18 +05:00
parent 4957497553
commit 56e67097b3
12 changed files with 267 additions and 394 deletions

View File

@@ -16,6 +16,7 @@ import {Actions} from '../../provider/Actions';
import {
useMenuStore,
useSelectionStore,
useTrashStore,
useUserStore,
} from '../../provider/stores';
import {DDS} from '../../services/DeviceDetection';
@@ -37,6 +38,7 @@ import {MMKV} from '../../utils/mmkv';
import {SIZE} from '../../utils/SizeUtils';
import {sleep, timeConverter} from '../../utils/TimeUtils';
import {Button} from '../Button';
import {presentDialog} from '../Dialog/functions';
import {PressableButton} from '../PressableButton';
import Heading from '../Typography/Heading';
import Paragraph from '../Typography/Paragraph';
@@ -264,10 +266,28 @@ export const ActionSheetComponent = ({
},
},
{
name: 'Remove',
name: 'Delete',
icon: 'delete',
func: () => {
close('permanant_delete');
func: async () => {
close();
await sleep(300);
presentDialog({
title: `Permanent delete`,
paragraph: `Are you sure you want to delete this ${note.itemType} permanantly from trash?`,
positiveText: 'Delete',
negativeText: 'Cancel',
positivePress: async () => {
await db.trash.delete(note.id);
useTrashStore.getState().setTrash();
useSelectionStore.getState().setSelectionMode(false);
ToastEvent.show({
heading: 'Permanantly deleted items',
type: 'success',
context: 'local',
});
},
positiveType: 'errorShade',
});
},
},
{

View File

@@ -0,0 +1,24 @@
import { eSendEvent } from "../../services/EventManager";
import { eCloseSimpleDialog, eOpenSimpleDialog } from "../../utils/Events";
type DialogInfo = {
title?: string,
paragraph?: string,
positiveText?: string,
negativeText?: string,
positivePress?: () => void,
onClose?: () => void,
positiveType?: "transparent" | "gray" | "grayBg" | "accent" | "inverted" | "shade" | "error" | "errorShade",
icon?: string,
paragraphColor: string
}
export function presentDialog(data: DialogInfo): void {
eSendEvent(eOpenSimpleDialog, data);
}
export function hideDialog(): void {
eSendEvent(eCloseSimpleDialog);
}

View File

@@ -1,132 +1,101 @@
import React, { Component } from 'react';
import React, { useEffect, useState } from 'react';
import { View } from 'react-native';
import { useSelectionStore, useTrashStore } from '../../provider/stores';
import { useTracked } from '../../provider';
import { DDS } from '../../services/DeviceDetection';
import { ToastEvent } from '../../services/EventManager';
import { getElevation, history } from '../../utils';
import { db } from '../../utils/DB';
import { deleteItems } from '../../utils/functions';
import {
eSubscribeEvent,
eUnSubscribeEvent
} from '../../services/EventManager';
import { getElevation } from '../../utils';
import { eCloseSimpleDialog, eOpenSimpleDialog } from '../../utils/Events';
import { ph, pv } from '../../utils/SizeUtils';
import { dialogActions } from '../DialogManager/DialogActions';
import Seperator from '../Seperator';
import BaseDialog from './base-dialog';
import DialogButtons from './dialog-buttons';
import DialogHeader from './dialog-header';
export class Dialog extends Component {
constructor(props) {
super(props);
this.state = {
visible: false,
selecteItemsLength: 0,
};
}
export const Dialog = () => {
const [state] = useTracked();
const colors = state.colors;
const [visible, setVisible] = useState(false);
const [dialogInfo, setDialogInfo] = useState({
title: '',
paragraph: '',
positiveText: 'Done',
negativeText: 'Cancel',
positivePress: () => {},
onClose: () => {},
negativeText: hide,
positiveType: 'transparent',
icon: null,
paragraphColor:colors.pri
});
_onPress = async () => {
let {template, item} = this.props;
switch (template.action) {
case dialogActions.ACTION_DELETE:
deleteItems();
this.hide();
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);
useTrashStore.getState().setTrash();
useSelectionStore.getState().clearSelection();
ToastEvent.show({
heading: 'Permanantly deleted items',
type: 'success',
context: 'local',
});
this.hide();
break;
}
case dialogActions.ACTION_EMPTY_TRASH: {
await db.trash.clear();
useTrashStore.getState().setTrash();
useSelectionStore.getState().clearSelection();
ToastEvent.show({
heading: 'Trash cleared',
message:"All notes and notebooks in the trash have been removed permanantly.",
type: 'success',
context: 'local',
});
this.hide();
break;
}
}
const show = data => {
setDialogInfo({...dialogInfo, ...data});
setVisible(true);
};
_onClose = () => {
let {template, item} = this.props;
if (dialogActions.ACTION_TRASH === template.action) {
// delete item forever.
db.trash.delete(item.id);
const hide = () => {
setVisible(false);
};
useEffect(() => {
eSubscribeEvent(eOpenSimpleDialog, show);
eSubscribeEvent(eCloseSimpleDialog, hide);
return () => {
eUnSubscribeEvent(eOpenSimpleDialog, show);
eUnSubscribeEvent(eCloseSimpleDialog, hide);
};
}, []);
const onPressPositive = async () => {
if (dialogInfo.positivePress) {
await dialogInfo.positivePress();
}
this.setState({
visible: false,
});
hide();
};
show = () => {
this.setState({
visible: true,
selectedItemsLength: history.selectedItemsList.length,
});
};
hide = () => {
this.setState({
visible: false,
});
const onNegativePress = async () => {
if (dialogInfo.onClose) {
await dialogInfo.onClose();
}
hide();
};
render() {
const {template, colors} = this.props;
const {title, paragraph, positiveText, negativeText, icon} = template;
const {visible} = this.state;
if (!visible) return null;
return (
<BaseDialog visible={true} onRequestClose={this.hide}>
<View
style={{
const style = {
...getElevation(5),
width: DDS.isTab ? 350 : '85%',
maxHeight: 350,
width: DDS.isTab ? 400 : '85%',
maxHeight: 450,
borderRadius: 5,
backgroundColor: colors.bg,
paddingHorizontal: ph,
paddingVertical: pv,
}}>
};
return (
visible && (
<BaseDialog visible={true} onRequestClose={hide}>
<View style={style}>
<DialogHeader
title={title}
icon={icon}
paragraph={
this.state.selectedItemsLength > 0
? 'Delete ' +
this.state.selectedItemsLength +
' selected items?'
: paragraph
}
title={dialogInfo.title}
icon={dialogInfo.icon}
paragraph={dialogInfo.paragraph}
paragraphColor={dialogInfo.paragraphColor}
/>
<Seperator />
{template.noButtons ? null : (
<DialogButtons
onPressNegative={this._onClose}
onPressPositive={this._onPress}
positiveTitle={positiveText}
negativeTitle={negativeText}
onPressNegative={onNegativePress}
onPressPositive={onPressPositive}
positiveTitle={dialogInfo.positiveText}
negativeTitle={dialogInfo.negativeText}
positiveType={dialogInfo.positiveType}
/>
)}
</View>
</BaseDialog>
)
);
}
}
};

View File

@@ -1,12 +0,0 @@
export const dialogActions = {
ACTION_DELETE: 511,
ACTION_EXIT: 512,
ACTION_EMPTY_TRASH: 513,
ACTION_EXIT_FULLSCREEN: 514,
ACTION_TRASH: 515,
ACTION_PERMANANT_DELETE: 516,
ACTION_APPLY_CHANGES: 517,
ACTION_UPIN:518,
ACTION_NEW_NOTE:519,
ACTION_UPIN_MENU:520,
};

View File

@@ -4,13 +4,11 @@ import {
eCloseAddNotebookDialog,
eCloseAddTopicDialog,
eCloseMoveNoteDialog,
eCloseSimpleDialog,
eDispatchAction,
eOpenActionSheet,
eOpenAddNotebookDialog,
eOpenAddTopicDialog,
eOpenMoveNoteDialog,
eOpenSimpleDialog,
eDispatchAction,
} from '../../utils/Events';
export const ActionSheetEvent = (
@@ -34,14 +32,6 @@ export const ActionSheetHideEvent = () => {
eSendEvent(eCloseActionSheet);
};
export const simpleDialogEvent = data => {
eSendEvent(eOpenSimpleDialog, data);
};
export const simpleDialogHideEvent = () => {
eSendEvent(eCloseSimpleDialog);
};
export const moveNoteEvent = () => {
eSendEvent(eOpenMoveNoteDialog);
};
@@ -63,6 +53,5 @@ export const HideAddTopicEvent = notebook => {
};
export const updateEvent = data => {
eSendEvent(eDispatchAction, data);
};

View File

@@ -1,111 +0,0 @@
import {dialogActions} from './DialogActions';
import {timeConverter} from "../../utils/TimeUtils";
export const TEMPLATE_DELETE = type => {
return {
title: `Delete ${type}`,
paragraph: `Are you sure you want to delete this ${type}?`,
positiveText: 'Delete',
negativeText: 'Cancel',
action: dialogActions.ACTION_DELETE,
icon: 'delete',
};
};
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}`,
paragraph: `Restore or delete ${type} forever`,
positiveText: 'Restore',
negativeText: 'Delete',
action: dialogActions.ACTION_TRASH,
icon: 'delete-restore',
};
};
export const TEMPLATE_APPLY_CHANGES = {
title: `Apply changes`,
paragraph: `Apply selected changes to note?`,
positiveText: 'Apply',
negativeText: 'Cancel',
action: dialogActions.ACTION_APPLY_CHANGES,
icon: 'check',
};
export const TEMPLATE_EXIT_FULLSCREEN = () => {
return {
title: `Exit fullscreen editor?`,
paragraph: `Are you sure you want to exit fullscreen editor?`,
positiveText: 'Exit',
negativeText: 'Cancel',
action: dialogActions.ACTION_EXIT_FULLSCREEN,
icon: 'close',
};
};
export const TEMPLATE_EXIT = type => {
return {
title: `Close ${type}`,
paragraph: `Are you sure you want to close ${type}`,
positiveText: `Close`,
negativeText: 'Cancel',
action: dialogActions.ACTION_EXIT,
icon: 'close',
};
};
export const TEMPLATE_INFO = dateCreated => {
return {
title: `Note info`,
paragraph: `Created on ${timeConverter(dateCreated)} `,
positiveText: ``,
negativeText: '',
noButtons: true,
noTitle: true,
action: dialogActions.ACTION_CLOSE,
icon: 'information-outline',
};
};
export const TEMPLATE_EMPTY_TRASH = {
title: 'Clear trash',
paragraph: 'Are you sure you want to clear the trash?',
icon: 'delete-outline',
positiveText: 'Clear',
negativeText: 'Cancel',
action: dialogActions.ACTION_EMPTY_TRASH,
};
export const TEMPLATE_NEW_NOTE = {
title: 'Close note',
paragraph: 'Are you sure you want to close this note?',
icon: 'close',
positiveText: 'Yes',
negativeText: 'Cancel',
action: dialogActions.ACTION_NEW_NOTE,
};
export const TEMPLATE_UNPIN = (type) => { return {
title: 'Unpin' + type,
paragraph: 'Are you sure you want to unpin this ' + type + '?',
icon: 'pin-off-outline',
positiveText: 'Unpin',
negativeText: 'Cancel',
action: dialogActions.ACTION_UPIN
}};
export const TEMPLATE_UNPIN_MENU = (name,type) => { return {
title: 'Unpin' + name,
paragraph: 'Remove this ' + type + 'from menu?',
positiveText: 'Unpin',
negativeText: 'Cancel',
action: dialogActions.ACTION_UPIN_MENU
}};

View File

@@ -1,39 +1,29 @@
import React, {Component, createRef} from 'react';
import React, { Component, createRef } from 'react';
import {
eSendEvent,
eSubscribeEvent,
eUnSubscribeEvent,
openVault,
openVault
} from '../../services/EventManager';
import {getCurrentColors} from '../../utils/Colors';
import { getCurrentColors } from '../../utils/Colors';
import {
eCloseActionSheet,
eCloseAddNotebookDialog,
eCloseLoginDialog,
eCloseMoveNoteDialog,
eClosePremiumDialog,
eCloseSimpleDialog,
eOnLoadNote,
eCloseLoginDialog, eClosePremiumDialog, eOnLoadNote,
eOpenActionSheet,
eOpenAddNotebookDialog,
eOpenExportDialog,
eOpenLoginDialog,
eOpenMoveNoteDialog,
eOpenPremiumDialog,
eOpenSimpleDialog,
eShowGetPremium,
eThemeUpdated,
eOpenLoginDialog, eOpenPremiumDialog, eShowGetPremium,
eThemeUpdated
} from '../../utils/Events';
import {sleep} from '../../utils/TimeUtils';
import {EditorSettings} from '../../views/Editor/EditorSettings';
import {ActionSheetComponent} from '../ActionSheetComponent';
import { EditorSettings } from '../../views/Editor/EditorSettings';
import { ActionSheetComponent } from '../ActionSheetComponent';
import ActionSheetWrapper from '../ActionSheetComponent/ActionSheetWrapper';
import {AddNotebookDialog} from '../AddNotebookDialog';
import {AddTopicDialog} from '../AddTopicDialog';
import {Dialog} from '../Dialog';
import { AddNotebookDialog } from '../AddNotebookDialog';
import { AddTopicDialog } from '../AddTopicDialog';
import { Dialog } from '../Dialog';
import ExportDialog from '../ExportDialog';
import ImagePreview from '../ImagePreview';
import JumpToDialog from '../JumpToDialog';
import LoginDialog from '../LoginDialog';
import MergeEditor from '../MergeEditor';
import MoveNoteDialog from '../MoveNoteDialog';
@@ -47,9 +37,8 @@ import RecoveryKeyDialog from '../RecoveryKeyDialog';
import RestoreDialog from '../RestoreDialog';
import ResultDialog from '../ResultDialog';
import SortDialog from '../SortDialog';
import {UpdateDialog} from '../UpdateDialog';
import {VaultDialog} from '../VaultDialog';
import {TEMPLATE_DELETE, TEMPLATE_PERMANANT_DELETE} from './Templates';
import { UpdateDialog } from '../UpdateDialog';
import { VaultDialog } from '../VaultDialog';
export class DialogManager extends Component {
constructor(props) {
@@ -101,15 +90,6 @@ export class DialogManager extends Component {
this.actionSheet.current?.setModalVisible(false);
};
_showMoveNote = () => {
///this.moveNoteDialog.open();
};
_hideMoveNote = () => {
//eSendEvent(eCloseMoveNoteDialog)
// this.moveNoteDialog.close();
};
loadNote = i => {
if (i && i.type === 'new') {
this.setState({
@@ -147,18 +127,9 @@ export class DialogManager extends Component {
eSubscribeEvent(eOpenActionSheet, this._showActionSheet);
eSubscribeEvent(eCloseActionSheet, this._hideActionSheet);
eSubscribeEvent(eOpenSimpleDialog, this._showSimpleDialog);
eSubscribeEvent(eCloseSimpleDialog, this._hideSimpleDialog);
eSubscribeEvent(eOpenMoveNoteDialog, this._showMoveNote);
eSubscribeEvent(eCloseMoveNoteDialog, this._hideMoveNote);
eSubscribeEvent(eOpenAddNotebookDialog, this.showAddNotebook);
eSubscribeEvent(eCloseAddNotebookDialog, this.hideAddNotebook);
eSubscribeEvent(eOpenLoginDialog, this.showLoginDialog);
eSubscribeEvent(eCloseLoginDialog, this.hideLoginDialog);
eSubscribeEvent(eOpenPremiumDialog, this.showPremiumDialog);
eSubscribeEvent(eClosePremiumDialog, this.hidePremiumDialog);
}
@@ -170,12 +141,6 @@ export class DialogManager extends Component {
eUnSubscribeEvent(eOpenActionSheet, this._showActionSheet);
eUnSubscribeEvent(eCloseActionSheet, this._hideActionSheet);
eUnSubscribeEvent(eOpenSimpleDialog, this._showSimpleDialog);
eUnSubscribeEvent(eCloseSimpleDialog, this._hideSimpleDialog);
eUnSubscribeEvent(eOpenMoveNoteDialog, this._showMoveNote);
eUnSubscribeEvent(eCloseMoveNoteDialog, this._hideMoveNote);
eUnSubscribeEvent(eOpenAddNotebookDialog, this.showAddNotebook);
eUnSubscribeEvent(eCloseAddNotebookDialog, this.hideAddNotebook);
@@ -194,14 +159,6 @@ export class DialogManager extends Component {
this.premiumDialog.close();
};
showLoginDialog = () => {
//this.loginDialog.open();
};
hideLoginDialog = () => {
//this.loginDialog.close();
};
showAddNotebook = data => {
this.setState(
{
@@ -216,42 +173,9 @@ export class DialogManager extends Component {
this.addNotebooksDialog.close();
};
_showSimpleDialog = data => {
this.setState(
{
simpleDialog: data,
},
() => {
this.simpleDialog?.show();
},
);
};
_hideSimpleDialog = data => {
this.simpleDialog?.hide();
};
onActionSheetHide = () => {
if (this.show) {
switch (this.show) {
case 'delete': {
if (this.state.item.locked) {
openVault({
item: this.state.item,
novault: true,
locked: true,
deleteNote: true,
title: 'Delete note',
description: 'Unlock to delete note.',
});
} else {
this._showSimpleDialog(TEMPLATE_DELETE(this.state.item.type));
}
break;
}
case 'permanant_delete': {
this._showSimpleDialog(TEMPLATE_PERMANANT_DELETE);
break;
}
case 'novault': {
openVault({
item: this.state.item,
@@ -290,10 +214,6 @@ export class DialogManager extends Component {
this.showAddTopic();
break;
}
case 'movenote': {
// this._showMoveNote();
break;
}
case 'premium': {
eSendEvent(eOpenPremiumDialog);
break;
@@ -344,12 +264,7 @@ export class DialogManager extends Component {
</ActionSheetWrapper>
)}
<Dialog
ref={ref => (this.simpleDialog = ref)}
item={item}
colors={colors}
template={simpleDialog}
/>
<Dialog />
<AddTopicDialog
ref={ref => (this.addTopicsDialog = ref)}
close={() => {
@@ -383,9 +298,9 @@ export class DialogManager extends Component {
<UpdateDialog />
<RateDialog />
<ImagePreview/>
<EditorSettings/>
<PublishNoteDialog/>
<ImagePreview />
<EditorSettings />
<PublishNoteDialog />
</>
);
}

View File

@@ -1,15 +1,15 @@
import React from 'react';
import NoteItem from '.';
import { notesnook } from '../../../e2e/test.ids';
import { useSelectionStore } from '../../provider/stores';
import { useSelectionStore, useTrashStore } from '../../provider/stores';
import { DDS } from '../../services/DeviceDetection';
import { eSendEvent, openVault } from '../../services/EventManager';
import { eSendEvent, openVault, ToastEvent } from '../../services/EventManager';
import Navigation from '../../services/Navigation';
import { history } from '../../utils';
import { db } from '../../utils/DB';
import { eOnLoadNote, eShowMergeDialog } from '../../utils/Events';
import { tabBarRef } from '../../utils/Refs';
import { simpleDialogEvent } from '../DialogManager/recievers';
import { TEMPLATE_TRASH } from '../DialogManager/Templates';
import { presentDialog } from '../Dialog/functions';
import SelectionWrapper from '../SelectionWrapper';
export const NoteWrapper = React.memo(({item, index}) => {
@@ -17,7 +17,11 @@ export const NoteWrapper = React.memo(({item, index}) => {
const setSelectedItem = useSelectionStore(state => state.setSelectedItem);
const onPress = async () => {
let _note = db.notes.note(item.id).data;
let _note = item;
if (!isTrash) {
_note = db.notes.note(item.id).data;
}
if (history.selectedItemsList.length > 0 && history.selectionMode) {
setSelectedItem(_note);
@@ -43,13 +47,45 @@ export const NoteWrapper = React.memo(({item, index}) => {
return;
}
if (isTrash) {
simpleDialogEvent(TEMPLATE_TRASH(_note.type));
presentDialog({
title: `Restore ${item.itemType}`,
paragraph: `Restore or delete ${item.itemType} forever`,
positiveText: 'Restore',
negativeText: 'Delete',
positivePress: async () => {
await db.trash.restore(item.id);
Navigation.setRoutesToUpdate([
Navigation.routeNames.Tags,
Navigation.routeNames.Notes,
Navigation.routeNames.Notebooks,
Navigation.routeNames.NotesPage,
Navigation.routeNames.Favorites,
Navigation.routeNames.Trash,
]);
useSelectionStore.getState().setSelectionMode(false);
ToastEvent.show({
heading: 'Restore successful',
type: 'success',
});
},
onClose: async () => {
await db.trash.delete(item.id);
useTrashStore.getState().setTrash();
useSelectionStore.getState().setSelectionMode(false);
ToastEvent.show({
heading: 'Permanantly deleted items',
type: 'success',
context: 'local',
});
},
});
} else {
eSendEvent(eOnLoadNote, _note);
}
if (!DDS.isTab) {
tabBarRef.current?.goToPage(1);
}
}
};
return (
@@ -59,10 +95,7 @@ export const NoteWrapper = React.memo(({item, index}) => {
testID={notesnook.ids.note.get(index)}
onPress={onPress}
item={item}>
<NoteItem
item={item}
isTrash={isTrash}
/>
<NoteItem item={item} isTrash={isTrash} />
</SelectionWrapper>
);
});

View File

@@ -1,22 +1,19 @@
import React, {useEffect} from 'react';
import {BackHandler} from 'react-native';
import {View} from 'react-native';
import {useSafeAreaInsets} from 'react-native-safe-area-context';
import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions';
import React, { useEffect } from 'react';
import { BackHandler, View } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { useTracked } from '../../provider';
import { useSelectionStore } from '../../provider/stores';
import {eSendEvent, ToastEvent} from '../../services/EventManager';
import { eSendEvent, ToastEvent } from '../../services/EventManager';
import Navigation from '../../services/Navigation';
import {db} from '../../utils/DB';
import { db } from '../../utils/DB';
import {
eOpenMoveNoteDialog,
eOpenSimpleDialog,
refreshNotesPage,
eOpenMoveNoteDialog, refreshNotesPage
} from '../../utils/Events';
import {SIZE} from '../../utils/SizeUtils';
import {sleep} from '../../utils/TimeUtils';
import {ActionIcon} from '../ActionIcon';
import {TEMPLATE_DELETE} from '../DialogManager/Templates';
import { deleteItems } from '../../utils/functions';
import { SIZE } from '../../utils/SizeUtils';
import { sleep } from '../../utils/TimeUtils';
import { ActionIcon } from '../ActionIcon';
import { presentDialog } from '../Dialog/functions';
import Heading from '../Typography/Heading';
export const SelectionHeader = React.memo(({screen, type, extras}) => {
@@ -26,7 +23,7 @@ export const SelectionHeader = React.memo(({screen, type, extras}) => {
const selectionMode = useSelectionStore(state => state.selectionMode);
const selectedItemsList = useSelectionStore(state => state.selectedItemsList);
const setSelectionMode = useSelectionStore(state => state.setSelectionMode);
const clearSelection = useSelectionStore(state => state.clearSelection)
const clearSelection = useSelectionStore(state => state.clearSelection);
const insets = useSafeAreaInsets();
@@ -116,7 +113,7 @@ export const SelectionHeader = React.memo(({screen, type, extras}) => {
marginRight: 25,
}}
onPress={() => {
setSelectionMode(!selectionMode)
setSelectionMode(!selectionMode);
clearSelection();
}}
color={colors.light}
@@ -213,7 +210,21 @@ export const SelectionHeader = React.memo(({screen, type, extras}) => {
marginLeft: 10,
}}
onPress={async () => {
eSendEvent(eOpenSimpleDialog, TEMPLATE_DELETE('item'));
presentDialog({
title: `Delete ${
selectedItemsList.length > 1 ? 'items' : 'item'
}`,
paragraph: `Are you sure you want to delete ${
selectedItemsList.length > 1 ? 'these items?' : 'this item?'
}`,
positiveText: 'Delete',
negativeText: 'Cancel',
positivePress: () => {
deleteItems();
},
positiveType:"errorShade"
});
return;
}}
color={colors.light}

View File

@@ -2,7 +2,11 @@ import React, { useEffect, useState } from 'react';
import { Clipboard, View } from 'react-native';
import Animated, { useValue } from 'react-native-reanimated';
import { useTracked } from '../../provider';
import { useMenuStore, useNotebookStore, useSelectionStore } from '../../provider/stores';
import {
useMenuStore,
useNotebookStore,
useSelectionStore
} from '../../provider/stores';
import { openVault, ToastEvent } from '../../services/EventManager';
import Navigation from '../../services/Navigation';
import { dWidth, getElevation, toTXT } from '../../utils';
@@ -10,8 +14,7 @@ import { db } from '../../utils/DB';
import { deleteItems } from '../../utils/functions';
import { ActionIcon } from '../ActionIcon';
import { Button } from '../Button';
import { simpleDialogEvent } from '../DialogManager/recievers';
import { TEMPLATE_PERMANANT_DELETE } from '../DialogManager/Templates';
import { presentDialog } from '../Dialog/functions';
export const ActionStrip = ({note, setActionStrip}) => {
const [state, dispatch] = useTracked();
@@ -124,7 +127,7 @@ export const ActionStrip = ({note, setActionStrip}) => {
});
}
setIsPinnedToMenu(db.settings.isPinned(note.id));
setMenuPins()
setMenuPins();
setActionStrip(false);
} catch (e) {}
@@ -188,7 +191,23 @@ export const ActionStrip = ({note, setActionStrip}) => {
icon: 'delete',
visible: note.type === 'trash',
onPress: () => {
simpleDialogEvent(TEMPLATE_PERMANANT_DELETE);
presentDialog({
title: `Permanent delete`,
paragraph: `Are you sure you want to delete this ${note.itemType} permanantly from trash?`,
positiveText: 'Delete',
negativeText: 'Cancel',
positivePress: async () => {
await db.trash.delete(note.id);
useTrashStore.getState().setTrash();
useSelectionStore.getState().setSelectionMode(false);
ToastEvent.show({
heading: 'Permanantly deleted items',
type: 'success',
context: 'local',
});
},
positiveType: 'errorShade',
});
setActionStrip(false);
},
},

View File

@@ -1,7 +1,5 @@
import React, { useEffect } from 'react';
import { BackHandler, InteractionManager, Keyboard } from 'react-native';
import { simpleDialogEvent } from '../../components/DialogManager/recievers';
import { TEMPLATE_EXIT_FULLSCREEN } from '../../components/DialogManager/Templates';
import { useSettingStore } from '../../provider/stores';
import { DDS } from '../../services/DeviceDetection';
import {

View File

@@ -1,8 +1,7 @@
import React, { useCallback, useEffect } from 'react';
import { ContainerBottomButton } from '../../components/Container/ContainerBottomButton';
import { ContainerTopSection } from '../../components/Container/ContainerTopSection';
import { simpleDialogEvent } from '../../components/DialogManager/recievers';
import { TEMPLATE_EMPTY_TRASH } from '../../components/DialogManager/Templates';
import { presentDialog } from '../../components/Dialog/functions';
import { Header } from '../../components/Header';
import { Placeholder } from '../../components/ListPlaceholders';
import SelectionHeader from '../../components/SelectionHeader';
@@ -14,7 +13,6 @@ import SearchService from '../../services/SearchService';
import { InteractionManager } from '../../utils';
import { eScrollEvent } from '../../utils/Events';
export const Trash = ({route, navigation}) => {
const trash = useTrashStore(state => state.trash);
const setTrash = useTrashStore(state => state.setTrash);
@@ -83,7 +81,27 @@ export const Trash = ({route, navigation}) => {
});
};
const _onPressBottomButton = () => simpleDialogEvent(TEMPLATE_EMPTY_TRASH);
const _onPressBottomButton = () => {
presentDialog({
title: 'Clear trash',
paragraph: 'Are you sure you want to clear the trash?',
positiveText: 'Clear',
negativeText: 'Cancel',
positivePress: async () => {
await db.trash.clear();
useTrashStore.getState().setTrash();
useSelectionStore.getState().clearSelection();
ToastEvent.show({
heading: 'Trash cleared',
message:
'All notes and notebooks in the trash have been removed permanantly.',
type: 'success',
context: 'local',
});
},
positiveType: 'errorShade',
});
};
return (
<>