launch login dialog after session expired from AppLoader

This commit is contained in:
ammarahm-ed
2021-07-24 11:03:50 +05:00
parent 5bd97e1315
commit ced4be7bc7
4 changed files with 65 additions and 67 deletions

View File

@@ -1,10 +1,10 @@
import NetInfo from '@react-native-community/netinfo';
import { EV, EVENTS } from 'notes-core/common';
import React, { useEffect } from 'react';
import { Appearance, AppState, Linking, Platform } from 'react-native';
import {EV, EVENTS} from 'notes-core/common';
import React, {useEffect} from 'react';
import {Appearance, AppState, Linking, Platform} from 'react-native';
import RNExitApp from 'react-native-exit-app';
import * as RNIap from 'react-native-iap';
import { enabled } from 'react-native-privacy-snapshot';
import {enabled} from 'react-native-privacy-snapshot';
import SplashScreen from 'react-native-splash-screen';
import {
clearAllStores,
@@ -29,9 +29,9 @@ import Navigation from './src/services/Navigation';
import PremiumService from './src/services/PremiumService';
import SettingsService from './src/services/SettingsService';
import Sync from './src/services/Sync';
import { APP_VERSION, doInBackground, editing } from './src/utils';
import { updateStatusBarColor } from './src/utils/Colors';
import { db } from './src/utils/DB';
import {APP_VERSION, doInBackground, editing} from './src/utils';
import {updateStatusBarColor} from './src/utils/Colors';
import {db} from './src/utils/DB';
import {
eClearEditor,
eCloseProgressDialog,
@@ -39,10 +39,14 @@ import {
eOpenProgressDialog,
refreshNotesPage
} from './src/utils/Events';
import { MMKV } from './src/utils/mmkv';
import {MMKV} from './src/utils/mmkv';
import Storage from './src/utils/storage';
import { sleep } from './src/utils/TimeUtils';
import { getNote, getWebviewInit, updateNoteInEditor } from './src/views/Editor/Functions';
import {sleep} from './src/utils/TimeUtils';
import {
getNote,
getWebviewInit,
updateNoteInEditor
} from './src/views/Editor/Functions';
let prevTransactionId = null;
let subsriptionSuccessListener;
@@ -55,7 +59,7 @@ async function storeAppState() {
editing: editing.currentlyEditing,
note: getNote(),
movedAway: editing.movedAway,
timestamp: Date.now(),
timestamp: Date.now()
});
await MMKV.setItem('appState', state);
}
@@ -128,7 +132,7 @@ export const AppRootEvents = React.memo(
EV.subscribe(EVENTS.noteRemoved, onNoteRemoved);
eSubscribeEvent('userLoggedIn', setCurrentUser);
removeInternetStateListener = NetInfo.addEventListener(
onInternetStateChanged,
onInternetStateChanged
);
return () => {
eUnSubscribeEvent('userLoggedIn', setCurrentUser);
@@ -140,7 +144,7 @@ export const AppRootEvents = React.memo(
EV.unsubscribe(EVENTS.noteRemoved, onNoteRemoved);
EV.unsubscribe(
EVENTS.userCheckStatus,
PremiumService.onUserStatusCheck,
PremiumService.onUserStatusCheck
);
EV.unsubscribe(EVENTS.userSubscriptionUpdated, onAccountStatusChange);
@@ -162,7 +166,7 @@ export const AppRootEvents = React.memo(
Navigation.routeNames.Notes,
Navigation.routeNames.NotesPage,
Navigation.routeNames.Trash,
Navigation.routeNames.Notebook,
Navigation.routeNames.Notebook
]);
eSendEvent(eClearEditor);
} catch (e) {}
@@ -230,7 +234,7 @@ export const AppRootEvents = React.memo(
eSendEvent(eOpenProgressDialog, {
title: 'Email confirmed!',
paragraph: message,
noProgress: true,
noProgress: true
});
if (user?.isEmailConfirmed) {
@@ -245,10 +249,10 @@ export const AppRootEvents = React.memo(
})
.then(async () => {
subsriptionSuccessListener = RNIap.purchaseUpdatedListener(
onSuccessfulSubscription,
onSuccessfulSubscription
);
subsriptionErrorListener = RNIap.purchaseErrorListener(
onSubscriptionError,
onSubscriptionError
);
});
};
@@ -264,7 +268,7 @@ export const AppRootEvents = React.memo(
},
icon: 'check',
actionText: 'Continue',
noProgress: true,
noProgress: true
});
}
await PremiumService.setPremiumStatus();
@@ -290,7 +294,7 @@ export const AppRootEvents = React.memo(
ToastEvent.show({
heading: 'Sync failed',
message: e.message,
context: 'global',
context: 'global'
});
}
} finally {
@@ -316,7 +320,7 @@ export const AppRootEvents = React.memo(
},
icon: 'logout',
actionText: 'Login',
noProgress: true,
noProgress: true
});
};
@@ -352,7 +356,7 @@ export const AppRootEvents = React.memo(
});
if (res !== true) throw new Error(res);
if (!user.isEmailConfirmed) {
if (!user?.isEmailConfirmed) {
setEmailVerifyMessage();
return;
}
@@ -362,7 +366,7 @@ export const AppRootEvents = React.memo(
}
} catch (e) {
let user = await db.user.getUser();
if (user && !user.isEmailConfirmed) {
if (user && !user?.isEmailConfirmed) {
setEmailVerifyMessage();
} else if (!user) {
setLoginMessage();
@@ -388,7 +392,7 @@ export const AppRootEvents = React.memo(
heading: 'Failed to subscribe',
type: 'error',
message: error.message,
context: 'local',
context: 'local'
});
};
@@ -413,7 +417,7 @@ export const AppRootEvents = React.memo(
}
let result = await BiometricService.validateUser(
'Unlock to access your notes',
'Unlock to access your notes'
);
if (result) {
showingDialog = false;
@@ -435,10 +439,10 @@ export const AppRootEvents = React.memo(
await MMKV.removeItem('appState');
}
let user = await db.user.getUser();
if (user && !user.isEmailConfirmed) {
if (user && !user?.isEmailConfirmed) {
try {
let user = await db.user.fetchUser();
if (user.isEmailConfirmed) {
if (user?.isEmailConfirmed) {
onEmailVerified();
}
} catch (e) {}
@@ -463,5 +467,5 @@ export const AppRootEvents = React.memo(
return <></>;
},
() => true,
() => true
);

View File

@@ -6,21 +6,22 @@ import {useTracked} from '../../provider';
import {
useFavoriteStore,
useNoteStore,
useUserStore,
useUserStore
} from '../../provider/stores';
import BiometricService from '../../services/BiometricService';
import {DDS} from '../../services/DeviceDetection';
import {
eSendEvent,
eSubscribeEvent,
eUnSubscribeEvent,
eUnSubscribeEvent
} from '../../services/EventManager';
import {editing} from '../../utils';
import {db} from '../../utils/DB';
import {eOpenRateDialog} from '../../utils/Events';
import {eOpenLoginDialog, eOpenRateDialog} from '../../utils/Events';
import {MMKV} from '../../utils/mmkv';
import {tabBarRef} from '../../utils/Refs';
import {SIZE} from '../../utils/SizeUtils';
import {sleep} from '../../utils/TimeUtils';
import {Button} from '../Button';
import Input from '../Input';
import Seperator from '../Seperator';
@@ -76,13 +77,18 @@ const AppLoader = ({onLoad}) => {
Animated.timing(opacityV, {
toValue: 0,
duration: 100,
easing: Easing.out(Easing.ease),
easing: Easing.out(Easing.ease)
}).start();
setLoading(false);
await db.notes.init();
setNotes();
setFavorites();
_setLoading(false);
await sleep(1000);
if ((await MMKV.getItem('loginSessionHasExpired')) === 'expired') {
eSendEvent(eOpenLoginDialog, 4);
return;
}
let askForRating = await MMKV.getItem('askForRating');
if (askForRating !== 'never' || askForRating !== 'completed') {
askForRating = JSON.parse(askForRating);
@@ -112,7 +118,7 @@ const AppLoader = ({onLoad}) => {
const onUnlockBiometrics = async () => {
let verified = await BiometricService.validateUser(
'Unlock to access your notes',
'',
''
);
if (verified) {
didVerifyUser = true;
@@ -141,7 +147,7 @@ const AppLoader = ({onLoad}) => {
height: '100%',
position: 'absolute',
zIndex: 999,
borderRadius: 10,
borderRadius: 10
}}>
<Animated.View
style={{
@@ -151,7 +157,7 @@ const AppLoader = ({onLoad}) => {
justifyContent: 'center',
alignItems: 'center',
borderRadius: 10,
opacity: opacityV,
opacity: opacityV
}}>
{verifyUser ? (
<SafeAreaView
@@ -159,7 +165,7 @@ const AppLoader = ({onLoad}) => {
flex: 1,
justifyContent: 'center',
width: '100%',
paddingHorizontal: 12,
paddingHorizontal: 12
}}>
<Heading>Verify your identity</Heading>
{user ? (
@@ -209,7 +215,7 @@ const AppLoader = ({onLoad}) => {
style={{
height: 10,
flexDirection: 'row',
width: 100,
width: 100
}}>
<AnimatedProgress fill={colors.accent} current={4} total={4} />
</View>

View File

@@ -1,4 +1,4 @@
import React, { useEffect, useRef, useState } from 'react';
import React, {useEffect, useRef, useState} from 'react';
import {
ActivityIndicator,
ScrollView,
@@ -7,39 +7,39 @@ import {
View
} from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import { Button } from '../../components/Button';
import {Button} from '../../components/Button';
import Seperator from '../../components/Seperator';
import { useTracked } from '../../provider/index';
import { useUserStore } from '../../provider/stores';
import {useTracked} from '../../provider/index';
import {useUserStore} from '../../provider/stores';
import BiometricService from '../../services/BiometricService';
import { DDS } from '../../services/DeviceDetection';
import {DDS} from '../../services/DeviceDetection';
import {
eSendEvent,
eSubscribeEvent,
eUnSubscribeEvent,
ToastEvent
} from '../../services/EventManager';
import { clearMessage, setEmailVerifyMessage } from '../../services/Message';
import {clearMessage, setEmailVerifyMessage} from '../../services/Message';
import PremiumService from '../../services/PremiumService';
import { hexToRGBA } from '../../utils/ColorUtils';
import { db } from '../../utils/DB';
import {hexToRGBA} from '../../utils/ColorUtils';
import {db} from '../../utils/DB';
import {
eOpenLoginDialog,
eOpenProgressDialog,
eOpenRecoveryKeyDialog
} from '../../utils/Events';
import { openLinkInBrowser } from '../../utils/functions';
import { MMKV } from '../../utils/mmkv';
import { SIZE } from '../../utils/SizeUtils';
import {openLinkInBrowser} from '../../utils/functions';
import {MMKV} from '../../utils/mmkv';
import {SIZE} from '../../utils/SizeUtils';
import Storage from '../../utils/storage';
import { sleep } from '../../utils/TimeUtils';
import {sleep} from '../../utils/TimeUtils';
import ActionSheetWrapper from '../ActionSheetComponent/ActionSheetWrapper';
import BaseDialog from '../Dialog/base-dialog';
import DialogButtons from '../Dialog/dialog-buttons';
import DialogContainer from '../Dialog/dialog-container';
import DialogHeader from '../Dialog/dialog-header';
import Input from '../Input';
import { Header } from '../SimpleList/header';
import {Header} from '../SimpleList/header';
import Heading from '../Typography/Heading';
import Paragraph from '../Typography/Paragraph';
@@ -57,6 +57,7 @@ let confirmPassword;
let oldPassword;
function getEmail() {
if (!email) return null;
return email.replace(/(.{2})(.*)(?=@)/, function (gp1, gp2, gp3) {
for (let i = 0; i < gp3.length; i++) {
gp2 += '*';
@@ -64,7 +65,6 @@ function getEmail() {
return gp2;
});
}
let offsetY = 0;
const LoginDialog = () => {
const [state, dispatch] = useTracked();
const colors = state.colors;
@@ -84,7 +84,6 @@ const LoginDialog = () => {
const actionSheetRef = useRef();
const _email = useRef();
const _pass = useRef();
const _username = useRef();
const _oPass = useRef();
const _passConfirm = useRef();
@@ -177,11 +176,6 @@ const LoginDialog = () => {
const current = MODE_DATA[mode];
useEffect(() => {
MMKV.getItem('loginSessionHasExpired').then(r => {
if (r === 'expired') {
open(MODES.sessionExpired);
}
});
eSubscribeEvent(eOpenLoginDialog, open);
return () => {
eUnSubscribeEvent(eOpenLoginDialog, open);
@@ -473,15 +467,14 @@ const LoginDialog = () => {
onMomentumScrollEnd={() => {
actionSheetRef.current.handleChildScrollEnd();
}}
bounces={false}
overScrollMode="never"
scrollToOverflowEnabled="false"
style={{
maxHeight: DDS.isTab ? '90%' : '100%',
width: DDS.isTab ? 500 : '100%',
minHeight: !DDS.isTab ? '90%' : null,
height: MODES.sessionExpired === mode ? '100%' : null,
borderRadius: DDS.isTab ? 5 : 0,
backgroundColor: colors.bg,
zIndex: 10,
paddingBottom: DDS.isTab ? 20 : 0
zIndex: 10
}}>
<Header
color="transparent"
@@ -748,7 +741,7 @@ const LoginDialog = () => {
justifyContent: 'space-between',
backgroundColor: colors.bg,
alignSelf: 'center',
paddingVertical:20
paddingVertical: 20
}}>
<View
style={{

View File

@@ -47,11 +47,6 @@ const Editor = React.memo(
};
useEffect(()=>{
setTimeout(async () => {
if ((await MMKV.getItem('loginSessionHasExpired')) === 'expired')
eSendEvent(eOpenLoginDialog, 4);
}, 1000);
if (premiumUser) {
tiny.call(EditorWebView,tiny.setMarkdown,true)
}