A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
add delete dialog in dialog manager
ammarahm-ed85d669ac7abd
diff --git a/apps/mobile/App.js b/apps/mobile/App.jsindex 6906028b4..5e1e082b0 100644--- a/apps/mobile/App.js+++ b/apps/mobile/App.js@@ -147,7 +147,7 @@ const App = () => {<DialogManagercolors={colors}update={type => {- dispatch({type: type});+ dispatch({type: 'updateNotes'});}}/></View>diff --git a/apps/mobile/src/components/ActionSheetComponent/index.js b/apps/mobile/src/components/ActionSheetComponent/index.jsindex 15fe26cfa..00a4d20c3 100644--- a/apps/mobile/src/components/ActionSheetComponent/index.js+++ b/apps/mobile/src/components/ActionSheetComponent/index.js@@ -154,7 +154,7 @@ export const ActionSheetComponent = ({}}- dispatch({type: 'updateNotes'});+ dispatch({type: type});setNote({...toAdd});};diff --git a/apps/mobile/src/components/Dialog/index.js b/apps/mobile/src/components/Dialog/index.jsindex 24f9fae69..5c283d085 100644--- a/apps/mobile/src/components/Dialog/index.js+++ b/apps/mobile/src/components/Dialog/index.js@@ -1,7 +1,6 @@-import React, {useEffect, useState, createRef} from 'react';+import React, {useEffect, useState, createRef, Component} from 'react';import {View, Text, TouchableOpacity, Modal} from 'react-native';import NavigationService from '../../services/NavigationService';-import {COLOR_SCHEME,SIZE,@@ -13,145 +12,182 @@ import {WEIGHT,} from '../../common/common';import Icon from 'react-native-vector-icons/Feather';-import {getElevation} from '../../utils/utils';-import {useAppContext} from '../../provider/useAppContext';+import {getElevation, ToastEvent} from '../../utils/utils';import {useTracked} from '../../provider';+import {dialogActions, updateEvent} from '../DialogManager';+import {db} from '../../../App';++export class Dialog extends Component {+ constructor(props) {+ super(props);+ this.state = {+ visible: false,+ };+ }++ _onPress = async () => {+ let {template, item} = this.props;++ switch (template.action) {+ case dialogActions.ACTION_DELETE: {+ await db.deleteNotes([item]);+ ToastEvent.show('Note moved to trash', 'success', 3000);+ this.setState({+ visible: false,+ });+ updateEvent({type: item.type});+ break;+ }+ case dialogActions.ACTION_EXIT: {+ break;+ }+ }+ };++ _onClose = () => {+ this.setState({+ visible: false,+ });+ };-export const Dialog = ({- title,- paragraph = null,- positiveText = 'Ok',- negativeText = 'Cancel',- icon = null,- visible,- close = () => {},- positivePress = () => {},-}) => {- const [state, dispatch] = useTracked();- const {colors} = state;+ show = () => {+ this.setState({+ visible: true,+ });+ };+ hide = () => {+ this.setState({+ visible: false,+ });+ };- return (- <Modal- visible={visible}- transparent={true}- animated- animationType="fade"- onRequestClose={() => (refs = [])}>- <View- style={{- width: '100%',- height: '100%',- backgroundColor: 'rgba(0,0,0,0.3)',- justifyContent: 'center',- alignItems: 'center',- }}>- <TouchableOpacity- onPress={() => close()}+ render() {+ const {template, colors} = this.props;+ const {title, paragraph, positiveText, negativeText, icon} = template;+ const {visible} = this.state;+ return (+ <Modal+ visible={visible}+ transparent={true}+ animated+ animationType="fade"+ onRequestClose={() => this.setState({visible: false})}>+ <Viewstyle={{width: '100%',height: '100%',- position: 'absolute',- }}- />- <View- style={{- ...getElevation(5),- width: '80%',- maxHeight: 350,- borderRadius: 5,- backgroundColor: colors.bg,- paddingHorizontal: ph,- paddingVertical: pv,+ backgroundColor: 'rgba(0,0,0,0.3)',+ justifyContent: 'center',+ alignItems: 'center',}}>- <View+ <TouchableOpacity+ onPress={() => close()}style={{- flexDirection: 'row',- justifyContent: 'center',- alignItems: 'center',- }}>- {icon ? (- <Icon name={icon} color={colors.accent} size={SIZE.lg} />- ) : null}-- <Text- style={{- color: colors.accent,- fontFamily: WEIGHT.bold,- marginLeft: 5,- fontSize: SIZE.md,- }}>- {title}- </Text>- </View>-- {paragraph ? (- <Text- style={{- color: colors.icon,- fontFamily: WEIGHT.regular,- fontSize: SIZE.sm - 2,- textAlign: 'center',- marginTop: 10,- }}>- {paragraph}- </Text>- ) : null}-+ width: '100%',+ height: '100%',+ position: 'absolute',+ }}+ /><Viewstyle={{- justifyContent: 'space-between',- alignItems: 'center',- flexDirection: 'row',- marginTop: 20,+ ...getElevation(5),+ width: '80%',+ maxHeight: 350,+ borderRadius: 5,+ backgroundColor: colors.bg,+ paddingHorizontal: ph,+ paddingVertical: pv,}}>- <TouchableOpacity- activeOpacity={opacity}- onPress={() => positivePress()}+ <Viewstyle={{- paddingVertical: pv,- paddingHorizontal: ph,- borderRadius: 5,- width: '48%',+ flexDirection: 'row',justifyContent: 'center',alignItems: 'center',- borderColor: colors.accent,- backgroundColor: colors.accent,- borderWidth: 1,}}>+ {icon ? (+ <Icon name={icon} color={colors.accent} size={SIZE.lg} />+ ) : null}+<Textstyle={{- fontFamily: WEIGHT.medium,- color: 'white',- fontSize: SIZE.sm,+ color: colors.accent,+ fontFamily: WEIGHT.bold,+ marginLeft: 5,+ fontSize: SIZE.md,}}>- {positiveText}+ {title}</Text>- </TouchableOpacity>+ </View>- <TouchableOpacity- activeOpacity={opacity}- onPress={() => close()}- style={{- paddingVertical: pv,- paddingHorizontal: ph,- borderRadius: 5,- width: '48%',- justifyContent: 'center',- alignItems: 'center',- backgroundColor: colors.nav,- }}>+ {paragraph ? (<Textstyle={{- fontFamily: WEIGHT.medium,color: colors.icon,- fontSize: SIZE.sm,+ fontFamily: WEIGHT.regular,+ fontSize: SIZE.sm - 2,+ textAlign: 'center',+ marginTop: 10,}}>- {negativeText}+ {paragraph}</Text>- </TouchableOpacity>+ ) : null}++ <View+ style={{+ justifyContent: 'space-between',+ alignItems: 'center',+ flexDirection: 'row',+ marginTop: 20,+ }}>+ <TouchableOpacity+ activeOpacity={opacity}+ onPress={this._onPress}+ style={{+ paddingVertical: pv,+ paddingHorizontal: ph,+ borderRadius: 5,+ width: '48%',+ justifyContent: 'center',+ alignItems: 'center',+ borderColor: colors.accent,+ backgroundColor: colors.accent,+ borderWidth: 1,+ }}>+ <Text+ style={{+ fontFamily: WEIGHT.medium,+ color: 'white',+ fontSize: SIZE.sm,+ }}>+ {positiveText}+ </Text>+ </TouchableOpacity>++ <TouchableOpacity+ activeOpacity={opacity}+ onPress={this._onClose}+ style={{+ paddingVertical: pv,+ paddingHorizontal: ph,+ borderRadius: 5,+ width: '48%',+ justifyContent: 'center',+ alignItems: 'center',+ backgroundColor: colors.nav,+ }}>+ <Text+ style={{+ fontFamily: WEIGHT.medium,+ color: colors.icon,+ fontSize: SIZE.sm,+ }}>+ {negativeText}+ </Text>+ </TouchableOpacity>+ </View></View></View>- </View>- </Modal>- );-};+ </Modal>+ );+ }+}diff --git a/apps/mobile/src/components/DialogManager/index.js b/apps/mobile/src/components/DialogManager/index.jsindex d68d86332..c795ee82d 100644--- a/apps/mobile/src/components/DialogManager/index.js+++ b/apps/mobile/src/components/DialogManager/index.js@@ -2,6 +2,7 @@ import React, {Component} from 'react';import {DeviceEventEmitter} from 'react-native';import {ActionSheetComponent} from '../ActionSheetComponent';import ActionSheet from '../ActionSheet';+import {Dialog} from '../Dialog';export const ActionSheetEvent = (item, colors, tags, rowItems, columnItems) => {DeviceEventEmitter.emit('ActionSheetEvent', {item,@@ -15,6 +16,18 @@ export const ActionSheetHideEvent = () => {DeviceEventEmitter.emit('ActionSheetHideEvent');};+export const simpleDialogEvent = data => {+ DeviceEventEmitter.emit('simpleDialogEvent', data);+};++export const simpleDialogHideEvent = () => {+ DeviceEventEmitter.emit('simpleDialogHideEvent');+};++export const updateEvent = data => {+ DeviceEventEmitter.emit('updateEvent', data);+};+export const _recieveEvent = (eventName, action) => {DeviceEventEmitter.addListener(eventName, action);};@@ -23,6 +36,22 @@ export const _unSubscribeEvent = (eventName, action) => {DeviceEventEmitter.removeListener(eventName, action);};+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: 'trash',+ };+};++export const dialogActions = {+ ACTION_DELETE: 511,+ ACTION_EXIT: 512,+};+export class DialogManager extends Component {constructor(props) {super(props);@@ -35,6 +64,14 @@ export class DialogManager extends Component {rowItems: [],columnItems: [],},+ simpleDialog: {+ title: '',+ paragraph: '',+ positiveText: '',+ negativeText: '',+ action: 0,+ icon: '',+ },};}@@ -57,15 +94,58 @@ export class DialogManager extends Component {componentDidMount() {_recieveEvent('ActionSheetEvent', this._showActionSheet);_recieveEvent('ActionSheetHideEvent', this._hideActionSheet);++ _recieveEvent('simpleDialogEvent', this._showSimpleDialog);+ _recieveEvent('simpleDialogHideEvent', this._hideActionSheet);}componentWillUnmount() {_unSubscribeEvent('ActionSheetEvent', this._showActionSheet);- _unSubscribeEvent('ActionSheetHideEvent', this._hideActionSheet);+ _unSubscribeEvent('ActionSheetHideEvent', this._hideSimpleDialog);++ _unSubscribeEvent('simpleDialogEvent', this._showSimpleDialog);+ _unSubscribeEvent('simpleDialogHideEvent', this._hideSimpleDialog);}+ _showSimpleDialog = data => {+ this.setState(+ {+ simpleDialog: data,+ },+ () => {+ this.simpleDialog.show();+ },+ );+ };+ _hideSimpleDialog = data => {+ this.simpleDialog.hide();+ };++ onActionSheetHide = () => {+ if (this.show) {+ if (this.show === 'delete') {+ this._showSimpleDialog(TEMPLATE_DELETE(this.state.item.type));++ this.show = null;+ } else if (this.show == 'lock') {+ this.setState({+ vaultDialog: true,+ });+ this.show = null;+ } else if (this.show == 'unlock') {+ this.setState({+ unlock: true,+ isPerm: true,+ vaultDialog: true,+ });+ this.show = null;+ }+ }+ this.show = null;+ };+render() {let {colors, update} = this.props;- let {actionSheetData, item} = this.state;+ let {actionSheetData, item, simpleDialog} = this.state;return (<><ActionSheet@@ -78,10 +158,7 @@ export class DialogManager extends Component {bounceOnOpen={true}gestureEnabled={true}onClose={() => {- //this.onMenuHide();- if (this.willRefresh) {- update('updateNotes');- }+ this.onActionSheetHide();}}><ActionSheetComponentitem={item}@@ -103,6 +180,13 @@ export class DialogManager extends Component {}}/></ActionSheet>++ <Dialog+ ref={ref => (this.simpleDialog = ref)}+ item={item}+ colors={colors}+ template={simpleDialog}+ /></>);}diff --git a/apps/mobile/src/components/NoteItem/index.js b/apps/mobile/src/components/NoteItem/index.jsindex a6a82b2c7..20b90c47a 100644--- a/apps/mobile/src/components/NoteItem/index.js+++ b/apps/mobile/src/components/NoteItem/index.js@@ -22,7 +22,6 @@ export default class NoteItem extends React.Component {unlockNote: false,vaultDialog: false,isPerm: false,- visible: false,};this.actionSheet;this.show = null;@@ -37,35 +36,6 @@ export default class NoteItem extends React.Component {);}- onMenuHide = () => {- if (this.show) {- if (this.show === 'delete') {- this.setState({- visible: true,- });- this.show = null;- } else if (this.show == 'lock') {- this.setState({- vaultDialog: true,- });- this.show = null;- } else if (this.show == 'unlock') {- this.setState({- unlock: true,- isPerm: true,- vaultDialog: true,- });- this.show = null;- }- }- };-- deleteItem = async () => {- await db.deleteNotes([item]);- ToastEvent.show('Note moved to trash', 'success', 3000);- setVisible(false);- };-render() {let {unlock, vaultDialog, isPerm, visible} = this.state;let {@@ -99,19 +69,6 @@ export default class NoteItem extends React.Component {},customStyle ? customStyle : {},]}>- <Dialog- visible={visible}- title="Delete note"- icon="trash"- paragraph="Do you want to delete this note?"- positiveText="Delete"- positivePress={this.deleteItem}- close={() => {- this.setState({- visible: false,- });- }}- /><VaultDialogclose={() => {this.setState({diff --git a/apps/mobile/src/provider/index.js b/apps/mobile/src/provider/index.jsindex a4d1b85a6..1a34678fc 100644--- a/apps/mobile/src/provider/index.js+++ b/apps/mobile/src/provider/index.js@@ -34,11 +34,14 @@ const defaultState = {},};+export const ACTIONS = {+ NOTES: 'note',+};+const reducer = (state, action) => {switch (action.type) {- case 'updateNotes':+ case 'note':let notes = db.groupNotes();- console.log('updating notes');return {...state,notes: notes,diff --git a/apps/mobile/src/views/Home/index.js b/apps/mobile/src/views/Home/index.jsindex 70fce7cff..1fda5fcbf 100755--- a/apps/mobile/src/views/Home/index.js+++ b/apps/mobile/src/views/Home/index.js@@ -12,7 +12,8 @@ import {DDS} from '../../../App';import Container from '../../components/Container';import SelectionHeader from '../../components/SelectionHeader';import {useIsFocused} from 'react-navigation-hooks';-import {useTracked} from '../../provider';+import {useTracked, ACTIONS} from '../../provider';+import {_recieveEvent, _unSubscribeEvent} from '../../components/DialogManager';export const AnimatedSafeAreaView = Animatable.createAnimatableComponent(SafeAreaView,@@ -47,9 +48,20 @@ export const Home = ({navigation}) => {// EffectsuseEffect(() => {- dispatch({type: 'updateNotes', boo: 'hoo'});+ dispatch({type: ACTIONS.NOTES});}, []);+ useEffect(() => {+ _recieveEvent('updateEvent', type => {+ dispatch(type);+ });+ return () => {+ _unSubscribeEvent('updateEvent', type => {+ dispatch(type);+ });+ };+ });+// Functionsconst onChangeText = value => {