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
fix dialogs
ammarahm-edcc3fc9c2c0e9
diff --git a/apps/mobile/src/components/Dialog/index.js b/apps/mobile/src/components/Dialog/index.jsindex 5c283d085..b0904513d 100644--- a/apps/mobile/src/components/Dialog/index.js+++ b/apps/mobile/src/components/Dialog/index.js@@ -13,7 +13,6 @@ import {} from '../../common/common';import Icon from 'react-native-vector-icons/Feather';import {getElevation, ToastEvent} from '../../utils/utils';-import {useTracked} from '../../provider';import {dialogActions, updateEvent} from '../DialogManager';import {db} from '../../../App';@@ -32,13 +31,19 @@ export class Dialog extends Component {case dialogActions.ACTION_DELETE: {await db.deleteNotes([item]);ToastEvent.show('Note moved to trash', 'success', 3000);+ updateEvent({type: item.type});+this.setState({visible: false,});- updateEvent({type: item.type});break;}case dialogActions.ACTION_EXIT: {+ this.setState({+ visible: false,+ });+ NavigationService.goBack();+break;}}diff --git a/apps/mobile/src/components/DialogManager/index.js b/apps/mobile/src/components/DialogManager/index.jsindex c795ee82d..d7356be2b 100644--- a/apps/mobile/src/components/DialogManager/index.js+++ b/apps/mobile/src/components/DialogManager/index.js@@ -3,6 +3,7 @@ import {DeviceEventEmitter} from 'react-native';import {ActionSheetComponent} from '../ActionSheetComponent';import ActionSheet from '../ActionSheet';import {Dialog} from '../Dialog';+import {VaultDialog} from '../VaultDialog';export const ActionSheetEvent = (item, colors, tags, rowItems, columnItems) => {DeviceEventEmitter.emit('ActionSheetEvent', {item,@@ -47,6 +48,17 @@ export const TEMPLATE_DELETE = type => {};};+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: 'x',+ };+};+export const dialogActions = {ACTION_DELETE: 511,ACTION_EXIT: 512,@@ -56,6 +68,7 @@ export class DialogManager extends Component {constructor(props) {super(props);this.actionSheet;+ this.opened = false;this.state = {item: {},actionSheetData: {@@ -72,9 +85,17 @@ export class DialogManager extends Component {action: 0,icon: '',},+ isPerm: false,};}+ shouldComponentUpdate(nextProps, nextState) {+ return (+ JSON.stringify(nextProps) !== JSON.stringify(this.props) ||+ nextState !== this.state+ );+ }+_showActionSheet = data => {this.setState({@@ -120,6 +141,13 @@ export class DialogManager extends Component {this.simpleDialog.hide();};+ _showVaultDialog = () => {+ this.vaultDialogRef.open();+ };+ _hideVaultDialog = () => {+ this.vaultDialogRef.close();+ };+onActionSheetHide = () => {if (this.show) {if (this.show === 'delete') {@@ -127,16 +155,13 @@ export class DialogManager extends Component {this.show = null;} else if (this.show == 'lock') {- this.setState({- vaultDialog: true,- });+ this._showVaultDialog();this.show = null;} else if (this.show == 'unlock') {this.setState({- unlock: true,isPerm: true,- vaultDialog: true,});+ this._showVaultDialog();this.show = null;}}@@ -144,8 +169,15 @@ export class DialogManager extends Component {};render() {- let {colors, update} = this.props;- let {actionSheetData, item, simpleDialog} = this.state;+ let {colors} = this.props;+ let {+ actionSheetData,+ item,+ simpleDialog,+ isPerm,+ vaultDialog,+ unlock,+ } = this.state;return (<><ActionSheet@@ -187,6 +219,15 @@ export class DialogManager extends Component {colors={colors}template={simpleDialog}/>++ <VaultDialog+ ref={ref => (this.vaultDialogRef = ref)}+ colors={colors}+ note={item}+ perm={isPerm}+ openedToUnlock={false}+ visible={vaultDialog}+ /></>);}diff --git a/apps/mobile/src/components/VaultDialog/index.js b/apps/mobile/src/components/VaultDialog/index.jsindex 49dacf948..6094e420a 100644--- a/apps/mobile/src/components/VaultDialog/index.js+++ b/apps/mobile/src/components/VaultDialog/index.js@@ -1,113 +1,126 @@-import React, {useState} from 'react';+import React, {Component} from 'react';import {View, Text, TouchableOpacity, Modal} from 'react-native';import {SIZE, ph, pv, opacity, WEIGHT} from '../../common/common';import Icon from 'react-native-vector-icons/Feather';-import {FlatList, TextInput} from 'react-native-gesture-handler';-import {useForceUpdate} from '../../views/ListsEditor';+import {TextInput} from 'react-native-gesture-handler';import {db} from '../../../App';-import {useAppContext} from '../../provider/useAppContext';import {getElevation} from '../../utils/utils';import NavigationService from '../../services/NavigationService';-import {useTracked} from '../../provider';-let refs = [];+import {updateEvent} from '../DialogManager';-export const VaultDialog = ({- openedToUnlock = false,- visible,- hasPassword = false,- note,- close = () => {},- perm = false,- timestamp = null,-}) => {- const [state, dispatch] = useTracked();- const {colors} = state;+export class VaultDialog extends Component {+ constructor(props) {+ super(props);+ this.state = {+ visible: false,+ };+ this.password = null;+ }- const [hidden, setHidden] = useState(false);- let password = null;- return (- <Modal- visible={visible}- transparent={true}- onRequestClose={() => (refs = [])}>- <View- style={{- width: '100%',- height: '100%',- backgroundColor: colors.night- ? 'rgba(255,255,255,0.3)'- : 'rgba(0,0,0,0.3)',- justifyContent: 'center',- alignItems: 'center',- }}>+ open = () => {+ this.setState({+ visible: true,+ });+ };+ close = () => {+ this.setState(+ {+ visible: false,+ },+ () => {+ updateEvent({type: this.props.note.type});+ },+ );+ };++ onPress = async () => {+ if (this.props.note.locked) {+ let n = db.getNote(this.props.note.dateCreated);+ let item;+ if (n.content.cipher) {+ try {+ item = await db.unlockNote(n.dateCreated, password, this.props.perm);+ } catch (error) {+ console.log(error);+ }+ } else {+ item = n;+ }+ if (!this.props.perm) {+ NavigationService.navigate('Editor', {+ note: item,+ });+ }++ this.close();+ } else {+ await db.lockNote(this.props.note.dateCreated, 'password');+ this.close();+ }+ };++ render() {+ const {hasPassword, note, colors} = this.props;+ const {visible} = this.state;++ return (+ <Modal visible={visible} transparent={true} onRequestClose={this.close}><Viewstyle={{- ...getElevation(5),- width: '80%',- maxHeight: 350,- borderRadius: 5,- backgroundColor: colors.bg,- paddingHorizontal: ph,- paddingVertical: pv,+ width: '100%',+ height: '100%',+ backgroundColor: colors.night+ ? 'rgba(255,255,255,0.3)'+ : 'rgba(0,0,0,0.3)',+ justifyContent: 'center',+ alignItems: 'center',}}><Viewstyle={{- flexDirection: 'row',- justifyContent: 'center',- alignItems: 'center',+ ...getElevation(5),+ width: '80%',+ maxHeight: 350,+ borderRadius: 5,+ backgroundColor: colors.bg,+ paddingHorizontal: ph,+ paddingVertical: pv,}}>- <Icon name="shield" color={colors.accent} size={SIZE.lg} />- <Text+ <Viewstyle={{- color: colors.accent,- fontFamily: WEIGHT.bold,- marginLeft: 5,- fontSize: SIZE.md,+ flexDirection: 'row',+ justifyContent: 'center',+ alignItems: 'center',}}>- {openedToUnlock ? 'Unlock Note' : 'Lock Note'}- </Text>- </View>-- <Text- style={{- color: colors.icon,- fontFamily: WEIGHT.regular,- textAlign: 'center',- fontSize: SIZE.sm - 1,- marginTop: 10,- marginBottom: hidden ? 20 : 0,- }}>- {hasPassword- ? 'Set password for all your locked notes.'- : openedToUnlock- ? 'Enter vault password to unlock note.'- : 'Do you want to lock this note?'}- </Text>+ <Icon name="shield" color={colors.accent} size={SIZE.lg} />+ <Text+ style={{+ color: colors.accent,+ fontFamily: WEIGHT.bold,+ marginLeft: 5,+ fontSize: SIZE.md,+ }}>+ {note.locked ? 'Unlock Note' : 'Lock Note'}+ </Text>+ </View>- {openedToUnlock ? (- <TextInput+ <Textstyle={{- padding: pv - 5,- borderWidth: 1.5,- borderColor: colors.nav,- paddingHorizontal: ph,- borderRadius: 5,- marginTop: 10,- fontSize: SIZE.sm,+ color: colors.icon,fontFamily: WEIGHT.regular,- }}- onChangeText={value => {- password = value;- }}- secureTextEntry- placeholder="Password"- placeholderTextColor={colors.icon}- />- ) : null}+ textAlign: 'center',+ fontSize: SIZE.sm - 1,+ marginTop: 10,+ //marginBottom: hidden ? 20 : 0,+ }}>+ {hasPassword+ ? 'Set password for all your locked notes.'+ : note.locked+ ? 'Enter vault password to unlock note.'+ : 'Do you want to lock this note?'}+ </Text>- {!hasPassword ? null : (- <View>+ {note.locked ? (<TextInputstyle={{padding: pv - 5,@@ -115,130 +128,125 @@ export const VaultDialog = ({borderColor: colors.nav,paddingHorizontal: ph,borderRadius: 5,+ marginTop: 10,fontSize: SIZE.sm,fontFamily: WEIGHT.regular,}}- onChangeText={value => {}}+ onChangeText={value => {+ password = value;+ }}+ secureTextEntryplaceholder="Password"placeholderTextColor={colors.icon}/>+ ) : null}- <TextInput- style={{- padding: pv - 5,- borderWidth: 1.5,- borderColor: colors.nav,- paddingHorizontal: ph,- borderRadius: 5,- fontSize: SIZE.sm,- fontFamily: WEIGHT.regular,- marginTop: 10,- }}- onChangeText={value => {}}- placeholder="Confirm password"- placeholderTextColor={colors.icon}- />- <TextInput- style={{- padding: pv - 5,- borderWidth: 1.5,- borderColor: colors.nav,- paddingHorizontal: ph,- borderRadius: 5,- fontSize: SIZE.sm,- fontFamily: WEIGHT.regular,- marginTop: 10,- }}- onChangeText={value => {}}- placeholder="Hint"- placeholderTextColor={colors.icon}- />- </View>- )}+ {!hasPassword ? null : (+ <View>+ <TextInput+ style={{+ padding: pv - 5,+ borderWidth: 1.5,+ borderColor: colors.nav,+ paddingHorizontal: ph,+ borderRadius: 5,+ fontSize: SIZE.sm,+ fontFamily: WEIGHT.regular,+ }}+ onChangeText={value => {}}+ placeholder="Password"+ placeholderTextColor={colors.icon}+ />- <View- style={{- justifyContent: 'space-around',- alignItems: 'center',- flexDirection: 'row',- marginTop: 20,- }}>- <TouchableOpacity- activeOpacity={opacity}- onPress={async () => {- if (openedToUnlock) {- let n = db.getNote(note.dateCreated);- let item;- if (n.content.cipher) {- try {- item = await db.unlockNote(n.dateCreated, password, perm);- } catch (error) {- console.log(error);- }- } else {- item = n;- }- if (!perm) {- NavigationService.navigate('Editor', {- note: item,- });- }- close(item, false);- } else {- try {- await db.lockNote(note.dateCreated, 'password');- } catch (error) {}+ <TextInput+ style={{+ padding: pv - 5,+ borderWidth: 1.5,+ borderColor: colors.nav,+ paddingHorizontal: ph,+ borderRadius: 5,+ fontSize: SIZE.sm,+ fontFamily: WEIGHT.regular,+ marginTop: 10,+ }}+ onChangeText={value => {}}+ placeholder="Confirm password"+ placeholderTextColor={colors.icon}+ />+ <TextInput+ style={{+ padding: pv - 5,+ borderWidth: 1.5,+ borderColor: colors.nav,+ paddingHorizontal: ph,+ borderRadius: 5,+ fontSize: SIZE.sm,+ fontFamily: WEIGHT.regular,+ marginTop: 10,+ }}+ onChangeText={value => {}}+ placeholder="Hint"+ placeholderTextColor={colors.icon}+ />+ </View>+ )}- close(null, true);- }- }}+ <Viewstyle={{- paddingVertical: pv,- paddingHorizontal: ph,- borderRadius: 5,- width: '45%',- justifyContent: 'center',+ justifyContent: 'space-around',alignItems: 'center',- borderColor: colors.accent,- backgroundColor: colors.accent,- borderWidth: 1,+ flexDirection: 'row',+ marginTop: 20,}}>- <Text+ <TouchableOpacity+ activeOpacity={opacity}+ onPress={this.onPress}style={{- fontFamily: WEIGHT.medium,- color: 'white',- fontSize: SIZE.sm,+ paddingVertical: pv,+ paddingHorizontal: ph,+ borderRadius: 5,+ width: '45%',+ justifyContent: 'center',+ alignItems: 'center',+ borderColor: colors.accent,+ backgroundColor: colors.accent,+ borderWidth: 1,}}>- {openedToUnlock ? 'Unlock' : 'Lock'}- </Text>- </TouchableOpacity>+ <Text+ style={{+ fontFamily: WEIGHT.medium,+ color: 'white',+ fontSize: SIZE.sm,+ }}>+ {note.locked ? 'Unlock' : 'Lock'}+ </Text>+ </TouchableOpacity>- <TouchableOpacity- activeOpacity={opacity}- onPress={() => {- close();- }}- style={{- paddingVertical: pv,- paddingHorizontal: ph,- borderRadius: 5,- width: '45%',- justifyContent: 'center',- alignItems: 'center',- backgroundColor: colors.nav,- }}>- <Text+ <TouchableOpacity+ activeOpacity={opacity}+ onPress={this.close}style={{- fontFamily: WEIGHT.medium,- color: colors.icon,- fontSize: SIZE.sm,+ paddingVertical: pv,+ paddingHorizontal: ph,+ borderRadius: 5,+ width: '45%',+ justifyContent: 'center',+ alignItems: 'center',+ backgroundColor: colors.nav,}}>- Cancel- </Text>- </TouchableOpacity>+ <Text+ style={{+ fontFamily: WEIGHT.medium,+ color: colors.icon,+ fontSize: SIZE.sm,+ }}>+ Cancel+ </Text>+ </TouchableOpacity>+ </View></View></View>- </View>- </Modal>- );-};+ </Modal>+ );+ }+}