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 toasts
ammarahm-edb1a1692ab78f
diff --git a/apps/mobile/src/components/Toast/index.js b/apps/mobile/src/components/Toast/index.jsindex 61befb6d5..a28cac01e 100644--- a/apps/mobile/src/components/Toast/index.js+++ b/apps/mobile/src/components/Toast/index.js@@ -1,5 +1,5 @@import React, {useEffect, useState} from 'react';-import {Text, TouchableOpacity} from 'react-native';+import {Text, TouchableOpacity, Keyboard} from 'react-native';import * as Animatable from 'react-native-animatable';import {opacity, ph, SIZE, WEIGHT, normalize, pv} from '../../common/common';import {useTracked} from '../../provider';@@ -12,11 +12,11 @@ import {DDS} from '../../../App';const AnimatedTouchableOpacity = Animatable.createAnimatableComponent(TouchableOpacity,);-export const Toast = () => {+export const Toast = ({context = 'global'}) => {const [state, dispatch] = useTracked();const {colors} = state;-const [toast, setToast] = useState(false);+ const [keyboard, setKeyboard] = useState(false);const [message, setMessage] = useState([]);const [data, setData] = useState([]);const [toastStyle, setToastStyle] = useState({@@ -26,10 +26,14 @@ export const Toast = () => {const showToastFunc = data => {setData(data);- setToast(true);++ if (data.context === context) {+ setToast(true);+ }if (data.message) {setMessage(data.message);}+if (data.type === 'success') {setToastStyle({backgroundColor: colors.successBg,@@ -47,15 +51,27 @@ export const Toast = () => {}, data.duration);};- hideToastFunc = data => {+ const hideToastFunc = data => {setToast(false);};+ const _onKeyboardShow = () => {+ setKeyboard(true);+ };++ const _onKeyboardHide = () => {+ setKeyboard(false);+ };+useEffect(() => {+ Keyboard.addListener('keyboardDidShow', _onKeyboardShow);+ Keyboard.addListener('keyboardDidHide', _onKeyboardHide);eSubscribeEvent(eShowToast, showToastFunc);eSubscribeEvent(eHideToast, hideToastFunc);return () => {+ Keyboard.removeListener('keyboardDidShow', _onKeyboardShow);+ Keyboard.removeListener('keyboardDidHide', _onKeyboardHide);eUnSubscribeEvent('showToast', showToastFunc);eUnSubscribeEvent('hideToast', hideToastFunc);@@ -72,7 +88,7 @@ export const Toast = () => {width: '100%',alignItems: 'center',height: 60,- bottom: 100,+ bottom: keyboard ? 30 : 100,position: 'absolute',zIndex: 999,elevation: 15,diff --git a/apps/mobile/src/components/VaultDialog/index.js b/apps/mobile/src/components/VaultDialog/index.jsindex e3f62d1a1..41df8b038 100644--- a/apps/mobile/src/components/VaultDialog/index.js+++ b/apps/mobile/src/components/VaultDialog/index.js@@ -21,6 +21,7 @@ import {} from '../../services/events';import {openEditorAnimation} from '../../utils/animations';import {ACTIONS} from '../../provider/actions';+import {Toast} from '../Toast';const passInputRef = createRef();const confirmPassRef = createRef();@@ -114,7 +115,8 @@ export class VaultDialog extends Component {onPress = async () => {if (!this.state.novault) {if (this.password.length < 3) {- ToastAndroid.show('Password too short', 300);+ ToastEvent.show('Password too short', 'error', 'local');+return;}if (@@ -122,14 +124,15 @@ export class VaultDialog extends Component {this.password.trim() !== 0 &&this.state.passwordsDontMatch) {- ToastAndroid.show('Passwords do not match', 300);+ ToastEvent.show('Passwords do not match', 'error', 'local');+return;} else {this._createVault();}} else if (this.state.locked) {if (!this.password || this.password.trim() === 0) {- ToastAndroid.show('Please enter a valid password', 300);+ ToastEvent.show('Password is invalid', 'error', 'local');this.setState({wrongPassword: true,});@@ -156,7 +159,7 @@ export class VaultDialog extends Component {async _lockNote() {if (!this.password || this.password.trim() === 0) {- ToastAndroid.show('Please enter a valid password', 300);+ ToastEvent.show('Password is invalid', 'error', 'local');return;} else {db.vault.add(this.state.note.id).then(e => {@@ -167,7 +170,8 @@ export class VaultDialog extends Component {async _unlockNote() {if (!this.password || this.password.trim() === 0) {- ToastAndroid.show('Please enter a valid password', 300);+ ToastEvent.show('Password is invalid', 'error', 'local');+return;} else {if (this.state.permanant) {@@ -200,7 +204,7 @@ export class VaultDialog extends Component {updateEvent({type: ACTIONS.FAVORITES});eSendEvent(refreshNotesPage);this.close();- ToastEvent.show('Note deleted', 'success');+ ToastEvent.show('Note deleted', 'success', 'local');}async _createVault() {@@ -208,7 +212,7 @@ export class VaultDialog extends Component {if (this.state.note && this.state.note.id && !this.state.note.locked) {await db.vault.add(this.state.note.id);this.close();- ToastEvent.show('Note added to vault', 'success');+ ToastEvent.show('Note added to vault', 'success', 'local');}}@@ -244,7 +248,7 @@ export class VaultDialog extends Component {_takeErrorAction(e) {if (e.message === db.vault.ERRORS.wrongPassword) {- ToastAndroid.show('Password is incorrect', 300);+ ToastEvent.show('Password is incorrect', 'error', 'local');this.setState({wrongPassword: true,});@@ -347,7 +351,7 @@ export class VaultDialog extends Component {: this.state.goToEditor? 'Unlock note to open it in editor': 'Enter vault password to unlock note.'- : 'Do you want to lock this note?'}+ : 'Enter vault password to lock note.'}</Text>{note.locked || locked || permanant ? (@@ -493,6 +497,7 @@ export class VaultDialog extends Component {</View></View></View>+ <Toast context="local" /></Modal>);}diff --git a/apps/mobile/src/utils/utils.js b/apps/mobile/src/utils/utils.jsindex f0c7c9f36..192c9c267 100755--- a/apps/mobile/src/utils/utils.js+++ b/apps/mobile/src/utils/utils.js@@ -61,19 +61,35 @@ export const w = Dimensions.get('window').width;export const h = Dimensions.get('window').height;export const ToastEvent = {- show: (message, type, duration = 3000, func = null, actionText = '') => {+ show: (+ message,+ type,+ context = 'global',+ duration = 3000,+ func = null,+ actionText = '',+ ) => {eSendEvent(eShowToast, {message,type,+ context,duration,func,actionText,});},- hide: (message, type, duration = 3000, func = null, actionText = '') => {+ hide: (+ message,+ type,+ context = 'global',+ duration = 3000,+ func = null,+ actionText = '',+ ) => {eSendEvent(eHideToast, {message,type,+ context,duration,func,actionText,