update user

This commit is contained in:
ammarahm-ed
2020-12-16 14:57:58 +05:00
parent 6565b0d39b
commit b23cd26a29
17 changed files with 154 additions and 108 deletions

View File

@@ -1,33 +1,37 @@
import * as NetInfo from '@react-native-community/netinfo';
import { CHECK_IDS, EV } from 'notes-core/common';
import React, { useEffect, useState } from 'react';
import {CHECK_IDS, EV} from 'notes-core/common';
import React, {useEffect, useState} from 'react';
import {
Appearance,
AppState,
Linking,
NativeModules,
Platform,
StatusBar
StatusBar,
} from 'react-native';
import * as RNIap from 'react-native-iap';
import { enabled } from 'react-native-privacy-snapshot';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import {enabled} from 'react-native-privacy-snapshot';
import {SafeAreaProvider} from 'react-native-safe-area-context';
import SplashScreen from 'react-native-splash-screen';
import { useTracked } from './src/provider';
import { Actions } from './src/provider/Actions';
import { DDS } from './src/services/DeviceDetection';
import {useTracked} from './src/provider';
import {Actions} from './src/provider/Actions';
import {DDS} from './src/services/DeviceDetection';
import {
eSendEvent,
eSubscribeEvent,
eUnSubscribeEvent
eUnSubscribeEvent,
} from './src/services/EventManager';
import IntentService from './src/services/IntentService';
import { clearMessage, setLoginMessage } from './src/services/Message';
import {
clearMessage,
setEmailVerifyMessage,
setLoginMessage,
} from './src/services/Message';
import Navigation from './src/services/Navigation';
import PremiumService from './src/services/PremiumService';
import { editing } from './src/utils';
import { COLOR_SCHEME } from './src/utils/Colors';
import { db } from './src/utils/DB';
import {editing} from './src/utils';
import {COLOR_SCHEME} from './src/utils/Colors';
import {db} from './src/utils/DB';
import {
eClosePremiumDialog,
eDispatchAction,
@@ -36,12 +40,12 @@ import {
eOpenPremiumDialog,
eOpenSideMenu,
eShowGetPremium,
eStartSyncer
eStartSyncer,
} from './src/utils/Events';
import { MMKV } from './src/utils/mmkv';
import { tabBarRef } from './src/utils/Refs';
import { sleep } from './src/utils/TimeUtils';
import { getNote } from './src/views/Editor/Functions';
import {MMKV} from './src/utils/mmkv';
import {tabBarRef} from './src/utils/Refs';
import {sleep} from './src/utils/TimeUtils';
import {getNote} from './src/views/Editor/Functions';
const {ReceiveSharingIntent} = NativeModules;
let AppRootView = require('./initializer.root').RootView;
@@ -134,7 +138,7 @@ const App = () => {
};
const startSyncer = async () => {
try {
let user = await db.user.get();
let user = await db.user.getUser();
if (user) {
EV.subscribe('db:refresh', syncChanges);
}
@@ -152,11 +156,10 @@ const App = () => {
let url = res ? res.url : '';
try {
if (url.startsWith('ShareMedia://dataUrl')) {
console.log(url);
if (Platform.OS === 'ios' && url.startsWith('ShareMedia://dataUrl')) {
_data = await ReceiveSharingIntent.getFileNames(url);
_data = IntentService.iosSortedData(_data);
}
if (_data) {
IntentService.setIntent(_data);
IntentService.check((event) => {
@@ -165,6 +168,13 @@ const App = () => {
Navigation.closeDrawer();
});
}
} else if (url.startsWith('https://notesnook.com/verify')) {
let user = await db.user.fetchUser();
dispatch({type: Actions.USER, user: user});
if (user.isEmailConfirmed) {
clearMessage(dispatch);
}
}
} catch (e) {
console.log(e, 'ERROR HERE');
}
@@ -252,6 +262,7 @@ const App = () => {
try {
dispatch({type: Actions.SYNCING, syncing: true});
await db.sync(false);
dispatch({type: Actions.LAST_SYNC, lastSync: await db.lastSynced()});
} catch (e) {
} finally {
dispatch({type: Actions.SYNCING, syncing: false});
@@ -270,9 +281,7 @@ const App = () => {
eSubscribeEvent('nointent', loadMainApp);
Appearance.addChangeListener(onSystemThemeChanged);
let unsub = NetInfo.addEventListener(onNetworkStateChanged);
if (Platform.OS === 'ios') {
Linking.addEventListener('url', _handleIntent);
}
EV.subscribe('db:sync', dbSync);
EV.subscribe('user:checkStatus', handlePremiumAccess);
return () => {
@@ -285,9 +294,7 @@ const App = () => {
eUnSubscribeEvent('nointent', loadMainApp);
AppState.removeEventListener('change', onAppStateChanged);
Appearance.removeChangeListener(onSystemThemeChanged);
if (Platform.OS === 'ios') {
Linking.removeEventListener('url', _handleIntent);
}
unsub();
unsubIAP();
};
@@ -326,14 +333,19 @@ const App = () => {
const getUser = async () => {
try {
let user = await db.user.get();
let user = await db.user.fetchUser();
if (user) {
clearMessage(dispatch);
if (!user.isEmailConfirmed) {
setEmailVerifyMessage(dispatch);
}
dispatch({type: Actions.SYNCING, syncing: true});
dispatch({type: Actions.USER, user: user});
await db.sync();
dispatch({type: Actions.LAST_SYNC, lastSync: await db.lastSynced()});
dispatch({type: Actions.ALL});
await startSyncer();
clearMessage(dispatch);
} else {
setLoginMessage(dispatch);
}

View File

@@ -27,9 +27,18 @@
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:label="Notesnook">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https"
android:host="notesnook.com"
android:pathPrefix="/verify"></data>
</intent-filter>
</activity>
<activity
android:name=".IntentActivity"
@@ -38,16 +47,12 @@
android:noHistory="true">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.PROCESS_TEXT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/*" />
</intent-filter>
</activity>

View File

@@ -475,8 +475,7 @@ export const ActionSheetComponent = ({
ToastEvent.show(e.message, 'error', 'local', 5000);
}
} finally {
let user = await db.user.get();
dispatch({type: Actions.USER, user: user});
dispatch({type: Actions.LAST_SYNC,lastSync: await db.lastSynced()});
dispatch({type: Actions.ALL});
setRefreshing(false);
}

View File

@@ -1,19 +1,18 @@
import React, {useEffect, useState} from 'react';
import {Platform, StyleSheet, View} from 'react-native';
import Animated from 'react-native-reanimated';
import {useSafeAreaInsets} from 'react-native-safe-area-context';
import {useTracked} from '../../provider';
import {eSubscribeEvent, eUnSubscribeEvent} from '../../services/EventManager';
import React, { useEffect, useState } from 'react';
import { Platform, StyleSheet, View } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { useTracked } from '../../provider';
import { eSubscribeEvent, eUnSubscribeEvent } from '../../services/EventManager';
import Navigation from '../../services/Navigation';
import { dWidth } from '../../utils';
import { eScrollEvent } from '../../utils/Events';
import { SIZE } from '../../utils/SizeUtils';
import { ActionIcon } from '../ActionIcon';
import { SearchInput } from '../SearchInput';
import { HeaderLeftMenu } from './HeaderLeftMenu';
import { HeaderRightMenu } from './HeaderRightMenu';
import { HeaderTitle } from './HeaderTitle';
import {dWidth} from '../../utils';
import {eScrollEvent} from '../../utils/Events';
import {SIZE} from '../../utils/SizeUtils';
import {ActionIcon} from '../ActionIcon';
import {SearchInput} from '../SearchInput';
import {HeaderLeftMenu} from './HeaderLeftMenu';
import {HeaderRightMenu} from './HeaderRightMenu';
import {HeaderTitle} from './HeaderTitle';
export const Header = ({root}) => {
const [state] = useTracked();

View File

@@ -188,11 +188,12 @@ const LoginDialog = () => {
}
try {
let user = await db.user.get();
let user = await db.user.getUser()
if (!user) throw new Error('Email or passoword incorrect!');
setStatus('Syncing Data');
dispatch({type: Actions.USER, user: user});
await db.sync();
dispatch({type: Actions.LAST_SYNC,lastSync: await db.lastSynced()});
eSendEvent(eStartSyncer);
dispatch({type: Actions.ALL});
eSendEvent(refreshNotesPage);
@@ -257,9 +258,10 @@ const LoginDialog = () => {
let user;
try {
user = await db.user.get();
user = await db.user.getUser()
setStatus('Setting up crenditials');
dispatch({type: Actions.USER, user: user});
dispatch({type: Actions.LAST_SYNC,lastSync: await db.lastSynced()});
eSendEvent(eStartSyncer);
clearMessage(dispatch);
close();

View File

@@ -57,8 +57,7 @@ export const UserSection = ({noTextMode}) => {
} catch (e) {
ToastEvent.show(e.message, 'error');
} finally {
let user = await db.user.get();
dispatch({type: Actions.USER, user: user});
dispatch({type: Actions.LAST_SYNC,lastSync: await db.lastSynced()});
dispatch({type: Actions.ALL});
dispatch({
type: Actions.SYNCING,

View File

@@ -24,7 +24,7 @@ class PendingDialog extends React.Component {
async open() {
actionSheet.current?._setModalVisible(true);
let u = await db.user.get();
let u = await db.user.fetchUser();
this.setState({
user: u && u.Id ? u : null,
});

View File

@@ -48,7 +48,7 @@ class PremiumDialog extends React.Component {
async getSkus() {
try {
let u = await db.user.get();
let u = await db.user.getUser()
this.setState({
user: u,
});

View File

@@ -126,7 +126,7 @@ class RecoveryKeyDialog extends React.Component {
onOpen = async () => {
let k = await db.user.key();
this.user = await db.user.get();
this.user = await db.user.getUser();
if (k) {
this.setState({

View File

@@ -1,21 +1,20 @@
import React, {useEffect} from 'react';
import {TouchableOpacity, View} from 'react-native';
import Animated, {Easing, useValue} from 'react-native-reanimated';
import {useSafeAreaInsets} from 'react-native-safe-area-context';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions';
import {eSendEvent, ToastEvent} from '../../services/EventManager';
import {db} from '../../utils/DB';
import React, { useEffect } from 'react';
import { View } from 'react-native';
import Animated, { Easing, useValue } from 'react-native-reanimated';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { useTracked } from '../../provider';
import { Actions } from '../../provider/Actions';
import { eSendEvent, ToastEvent } from '../../services/EventManager';
import { db } from '../../utils/DB';
import {
eOpenMoveNoteDialog,
eOpenSimpleDialog,
refreshNotesPage,
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 { SIZE } from '../../utils/SizeUtils';
import { sleep } from '../../utils/TimeUtils';
import { ActionIcon } from '../ActionIcon';
import { TEMPLATE_DELETE } from '../DialogManager/Templates';
import Heading from '../Typography/Heading';
export const SelectionHeader = () => {

View File

@@ -156,8 +156,7 @@ const SimpleList = ({
if (refreshCallback) {
refreshCallback();
}
let user = await db.user.get();
dispatch({type: Actions.USER, user: user});
dispatch({type: Actions.LAST_SYNC,lastSync: await db.lastSynced()});
dispatch({type: Actions.ALL});
}
}, []);

View File

@@ -31,5 +31,6 @@ export const Actions = {
LOADING:"loading",
FULLSCREEN:"fullscreen",
DEVICE_MODE:"deviceMode",
MENU_PINS:"menuPins"
MENU_PINS:"menuPins",
LAST_SYNC:"lastSynced"
};

View File

@@ -81,5 +81,6 @@ export const defaultState = {
icon: 'account-outline',
},
keyword: [],
menuPins:[]
menuPins:[],
lastSynced:"Never"
};

View File

@@ -259,6 +259,13 @@ export const reducer = (state, action) => {
menuPins: db.settings.pins,
};
}
case Actions.LAST_SYNC: {
return {
...state,
menuPins: action.lastSync,
};
}
default:
throw new Error('unknown action type');
}

View File

@@ -1,27 +1,50 @@
import { Actions } from "../provider/Actions";
import { eOpenLoginDialog } from "../utils/Events";
import { eSendEvent } from "./EventManager";
import {Actions} from '../provider/Actions';
import {eOpenLoginDialog} from '../utils/Events';
import {eSendEvent} from './EventManager';
export function setLoginMessage(dispatch) {
dispatch({type:Actions.MESSAGE_BOARD_STATE,state:{
visible:true,
message:'You are not logged in',
actionText:"Login to sync your notes",
dispatch({
type: Actions.MESSAGE_BOARD_STATE,
state: {
visible: true,
message: 'You are not logged in',
actionText: 'Login to sync your notes',
onPress: () => {
eSendEvent(eOpenLoginDialog);
},
data:{},
icon:'account-outline'
}});
data: {},
icon: 'account-outline',
},
});
}
export function setEmailVerifyMessage(dispatch) {
dispatch({
type: Actions.MESSAGE_BOARD_STATE,
state: {
visible: true,
message: 'Email not verified',
actionText: 'Please verify your email to sync notes',
onPress: () => {
// Handle this
//eSendEvent(eOpen)
},
data: {},
icon: 'account-outline',
},
});
}
export function clearMessage(dispatch) {
dispatch({type:Actions.MESSAGE_BOARD_STATE,state:{
visible:false,
message:'',
actionText:"",
dispatch({
type: Actions.MESSAGE_BOARD_STATE,
state: {
visible: false,
message: '',
actionText: '',
onPress: null,
data:{},
icon:'account-outline'
}});
data: {},
icon: 'account-outline',
},
});
}

View File

@@ -7,7 +7,7 @@ let premiumStatus = true;
async function setPremiumStatus() {
try {
let user = await db.user.get();
let user = await db.user.getUser();
if (!user || !user.id) {
premiumStatus = null;
} else {
@@ -30,7 +30,7 @@ async function verify(callback,error) {
return; */
try {
let user = await db.user.get();
let user = await db.user.getUser();
if (!user || !user.id || premiumStatus) {
if (error) {

View File

@@ -31,6 +31,6 @@ export function validateUsername(username) {
}
export async function checkPremiumUser() {
let user = await db.user.get();
//let user = await db.user.get();
return false;
}