add ResultDialog

This commit is contained in:
ammarahm-ed
2020-10-28 15:15:35 +05:00
parent fe44d4dd30
commit c0d76de46f
9 changed files with 198 additions and 90 deletions

View File

@@ -28,7 +28,7 @@ import {db} from './src/utils/DB';
import {DDS} from './src/services/DeviceDetection'; import {DDS} from './src/services/DeviceDetection';
import {MMKV} from './src/utils/mmkv'; import {MMKV} from './src/utils/mmkv';
import Backup from './src/services/Backup'; import Backup from './src/services/Backup';
import { setLoginMessage } from './src/services/Message'; import {setLoginMessage} from './src/services/Message';
let firstLoad = true; let firstLoad = true;
let note = null; let note = null;
@@ -66,32 +66,28 @@ const App = () => {
const updateTheme = async () => { const updateTheme = async () => {
let settings; let settings;
settings = await MMKV.getStringAsync('settings'); settings = await MMKV.getStringAsync('settings');
if (settings) { if (settings) {
settings = JSON.parse(settings); settings = JSON.parse(settings);
if (settings.useSystemTheme) { if (settings.useSystemTheme) {
let newColors = await getColorScheme(settings.useSystemTheme); let newColors = await getColorScheme(settings.useSystemTheme);
dispatch({type: Actions.THEME, colors: newColors}); dispatch({type: Actions.THEME, colors: newColors});
}
} }
}
}; };
useEffect(() => { useEffect(() => {
let message = 'Internet connection restored';
let type = 'success';
if (!netInfo.isConnected || !netInfo.isInternetReachable) { if (!netInfo.isConnected || !netInfo.isInternetReachable) {
db.user?.get().then((user) => { message = 'No internet connection';
if (user) { type = 'error';
ToastEvent.show('No internet connection', 'error');
} else {
}
});
} else {
db.user?.get().then((user) => {
if (user) {
ToastEvent.show('Internet connection restored', 'success');
} else {
}
});
} }
db.user?.get().then((user) => {
if (user) {
ToastEvent.show(message, type);
}
});
}, [netInfo]); }, [netInfo]);
const syncChanges = async () => { const syncChanges = async () => {
@@ -153,38 +149,37 @@ const App = () => {
if (user) { if (user) {
dispatch({type: Actions.USER, user: user}); dispatch({type: Actions.USER, user: user});
await startSyncer(); await startSyncer();
} }
} catch (e) { } catch (e) {
error = e; error = e;
console.log(e) console.log(e);
} }
if (!user || !user.id) { if (!user || !user.id) {
setLoginMessage(dispatch); setLoginMessage(dispatch);
} }
dispatch({type: Actions.ALL}); dispatch({type: Actions.ALL});
setInit(true); setInit(true);
backupData(); backupData();
if (error) { if (error) {
setTimeout(() => { setTimeout(() => {
ToastEvent.show(error.message); ToastEvent.show(error.message);
}, 500); }, 500);
} }
}); });
}, []); }, []);
async function backupData() { async function backupData() {
await sleep(1000) await sleep(1000);
settings = await MMKV.getStringAsync('settings'); settings = await MMKV.getStringAsync('settings');
settings = JSON.parse(settings); settings = JSON.parse(settings);
if (await Backup.checkBackupRequired(settings.reminder) ) { if (await Backup.checkBackupRequired(settings.reminder)) {
try { try {
await Backup.run(); await Backup.run();
} catch(e) { } catch (e) {
console.log(e); console.log(e);
}
} }
}
} }
async function Initialize() { async function Initialize() {
@@ -200,21 +195,20 @@ const App = () => {
} }
firstLoad = false; firstLoad = false;
} }
settings = await MMKV.getStringAsync('settings'); settings = await MMKV.getStringAsync('settings');
console.log('settings',settings) console.log('settings', settings);
if (!settings) { if (!settings) {
settings = defaultState.settings; settings = defaultState.settings;
await MMKV.setStringAsync('settings', JSON.stringify(settings)); await MMKV.setStringAsync('settings', JSON.stringify(settings));
} else { } else {
settings = JSON.parse(settings); settings = JSON.parse(settings);
} }
if (settings.fontScale) { if (settings.fontScale) {
scale.fontScale = settings.fontScale; scale.fontScale = settings.fontScale;
} }
dispatch({type: Actions.SETTINGS, settings: {...settings}}); dispatch({type: Actions.SETTINGS, settings: {...settings}});
updateSize(); updateSize();
await updateTheme(); await updateTheme();
} }
if (!init) { if (!init) {

View File

@@ -43,6 +43,7 @@ import {VaultDialog} from '../VaultDialog';
import {TEMPLATE_DELETE, TEMPLATE_PERMANANT_DELETE} from './Templates'; import {TEMPLATE_DELETE, TEMPLATE_PERMANANT_DELETE} from './Templates';
import {hexToRGBA} from "../../utils/ColorUtils"; import {hexToRGBA} from "../../utils/ColorUtils";
import {DDS} from "../../services/DeviceDetection"; import {DDS} from "../../services/DeviceDetection";
import ResultDialog from '../ResultDialog';
export class DialogManager extends Component { export class DialogManager extends Component {
constructor(props) { constructor(props) {
@@ -376,6 +377,8 @@ export class DialogManager extends Component {
<ProgressDialog /> <ProgressDialog />
<RestoreDialog/> <RestoreDialog/>
<ResultDialog/>
</> </>
); );
} }

View File

@@ -11,7 +11,7 @@ import {DDS} from "../../services/DeviceDetection";
const ProgressDialog = () => { const ProgressDialog = () => {
const [state, dispatch] = useTracked(); const [state, dispatch] = useTracked();
const {colors, tags, premiumUser} = state; const {colors,} = state;
const [visible, setVisible] = useState(false); const [visible, setVisible] = useState(false);
const [dialogData, setDialogData] = useState({ const [dialogData, setDialogData] = useState({
title: 'Loading', title: 'Loading',

View File

@@ -5,11 +5,12 @@ import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import RNFetchBlob from 'rn-fetch-blob'; import RNFetchBlob from 'rn-fetch-blob';
import {LOGO_BASE64} from '../../assets/images/assets'; import {LOGO_BASE64} from '../../assets/images/assets';
import { import {
eSendEvent,
eSubscribeEvent, eSubscribeEvent,
eUnSubscribeEvent, eUnSubscribeEvent,
ToastEvent, ToastEvent,
} from '../../services/EventManager'; } from '../../services/EventManager';
import {eOpenRecoveryKeyDialog} from '../../utils/Events'; import {eOpenRecoveryKeyDialog, eOpenResultDialog} from '../../utils/Events';
import {dWidth} from '../../utils'; import {dWidth} from '../../utils';
import ActionSheet from '../ActionSheet'; import ActionSheet from '../ActionSheet';
import {Button} from '../Button'; import {Button} from '../Button';
@@ -27,14 +28,28 @@ class RecoveryKeyDialog extends React.Component {
this.actionSheetRef = createRef(); this.actionSheetRef = createRef();
this.svg = createRef(); this.svg = createRef();
this.user; this.user;
this.signup = false;
} }
open = () => { open = (signup) => {
if (signup) {
this.signup = true;
}
this.actionSheetRef.current?._setModalVisible(true); this.actionSheetRef.current?._setModalVisible(true);
}; };
close = () => { close = () => {
this.actionSheetRef.current?._setModalVisible(false); this.actionSheetRef.current?._setModalVisible(false);
if (!this.signup) {
setTimeout(() => {
eSendEvent(eOpenResultDialog, {
title: 'Welcome!',
paragraph: 'Your 14 day trial for Notesnook Pro is activated',
icon: 'checkbox-marked-circle',
button: 'Thank You!',
});
}, 500);
}
}; };
async componentDidMount() { async componentDidMount() {
eSubscribeEvent(eOpenRecoveryKeyDialog, this.open); eSubscribeEvent(eOpenRecoveryKeyDialog, this.open);
@@ -113,6 +128,7 @@ class RecoveryKeyDialog extends React.Component {
alignSelf: 'center', alignSelf: 'center',
borderRadius: 10, borderRadius: 10,
}} }}
closeOnTouchBackdrop={false}
onOpen={this.onOpen} onOpen={this.onOpen}
ref={this.actionSheetRef} ref={this.actionSheetRef}
initialOffsetFromBottom={1}> initialOffsetFromBottom={1}>
@@ -233,7 +249,13 @@ class RecoveryKeyDialog extends React.Component {
data or reset your password using this recovery key. data or reset your password using this recovery key.
</Text> </Text>
</View> </View>
<Seperator />
<Button
title="I have saved the key."
width="100%"
height={50}
onPress={this.close}
/>
<Toast context="local" /> <Toast context="local" />
</View> </View>
</ActionSheet> </ActionSheet>

View File

@@ -0,0 +1,85 @@
import React, {useEffect, useState} from 'react';
import {Text, View} from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import {useTracked} from '../../provider';
import {DDS} from '../../services/DeviceDetection';
import {eSubscribeEvent, eUnSubscribeEvent} from '../../services/EventManager';
import {getElevation} from '../../utils';
import {eCloseResultDialog, eOpenResultDialog} from '../../utils/Events';
import {ph, SIZE, WEIGHT} from '../../utils/SizeUtils';
import {Button} from '../Button';
import BaseDialog from '../Dialog/base-dialog';
import Seperator from '../Seperator';
const ResultDialog = () => {
const [state, dispatch] = useTracked();
const {colors} = state;
const [visible, setVisible] = useState(false);
const [dialogData, setDialogData] = useState({
title: '',
paragraph: '',
icon: null,
button: null,
});
useEffect(() => {
eSubscribeEvent(eOpenResultDialog, open);
eSubscribeEvent(eCloseResultDialog, close);
return () => {
eUnSubscribeEvent(eOpenResultDialog, open);
eUnSubscribeEvent(eCloseResultDialog, close);
};
}, []);
const open = (data) => {
setDialogData(data);
setVisible(true);
};
const close = () => {
setVisible(false);
};
return (
<BaseDialog visible={visible} onRequestClose={close}>
<View
style={{
...getElevation(5),
width: DDS.isTab ? 350 : '80%',
maxHeight: 350,
borderRadius: 5,
backgroundColor: colors.bg,
paddingHorizontal: ph,
paddingVertical: 20,
justifyContent: 'center',
alignItems: 'center',
}}>
<Icon name={dialogData.icon} color={colors.accent} size={80} />
<Text
style={{
fontFamily: WEIGHT.bold,
alignSelf: 'center',
textAlign: 'center',
color: colors.heading,
fontSize: SIZE.lg,
marginTop: 10,
}}>
{dialogData.title}
</Text>
<Text
style={{
fontFamily: WEIGHT.regular,
alignSelf: 'center',
textAlign: 'center',
color: colors.icon,
fontSize: SIZE.sm,
}}>
{dialogData.paragraph}
</Text>
<Seperator />
<Button title={dialogData.button} width="100%" onPress={close} />
</View>
</BaseDialog>
);
};
export default ResultDialog;

View File

@@ -110,4 +110,7 @@ export const eCloseRestoreDialog = '554';
export const eOnNoteEdited = '555'; export const eOnNoteEdited = '555';
export const eUpdateSearchState = '556'; export const eUpdateSearchState = '556';
export const eOpenResultDialog = '557';
export const eCloseResultDialog = '558';

View File

@@ -96,9 +96,6 @@ async function requestPermission() {
} }
return granted; return granted;
} }
async function checkAndCreateDir(path) { async function checkAndCreateDir(path) {
let dir = Platform.OS === "ios"? IOS_PATH + path : ANDROID_PATH + path; let dir = Platform.OS === "ios"? IOS_PATH + path : ANDROID_PATH + path;
try { try {

View File

@@ -6,9 +6,14 @@ import {NoteItemWrapper} from '../../components/SimpleList/NoteItemWrapper';
import {useTracked} from '../../provider'; import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions'; import {Actions} from '../../provider/Actions';
import {eSendEvent} from '../../services/EventManager'; import {eSendEvent} from '../../services/EventManager';
import {eOnLoadNote, eScrollEvent, eUpdateSearchState} from '../../utils/Events'; import {
eOnLoadNote,
eScrollEvent,
eUpdateSearchState,
} from '../../utils/Events';
import {openEditorAnimation} from '../../utils/Animations'; import {openEditorAnimation} from '../../utils/Animations';
import {DDS} from "../../services/DeviceDetection"; import {DDS} from '../../services/DeviceDetection';
import ResultDialog from '../../components/ResultDialog';
export const Home = ({navigation}) => { export const Home = ({navigation}) => {
const [state, dispatch] = useTracked(); const [state, dispatch] = useTracked();
@@ -16,13 +21,14 @@ export const Home = ({navigation}) => {
const onFocus = useCallback(() => { const onFocus = useCallback(() => {
dispatch({ dispatch({
type: Actions.HEADER_VERTICAL_MENU, type: Actions.HEADER_VERTICAL_MENU,
state: true, state: notes.length > 0,
}); });
dispatch({ dispatch({
type: Actions.HEADER_TEXT_STATE, type: Actions.HEADER_TEXT_STATE,
state: { state: {
heading: "Home", heading: 'Home',
}, },
}); });
dispatch({ dispatch({
@@ -33,20 +39,19 @@ export const Home = ({navigation}) => {
type: Actions.HEADER_STATE, type: Actions.HEADER_STATE,
state: true, state: true,
}); });
eSendEvent(eUpdateSearchState,{ eSendEvent(eUpdateSearchState, {
placeholder: 'Search all notes', placeholder: 'Search all notes',
data: notes, data: notes,
noSearch: false, noSearch: false,
type: 'notes', type: 'notes',
color: null, color: null,
}) });
eSendEvent(eScrollEvent, 0); eSendEvent(eScrollEvent, 0);
dispatch({type: Actions.COLORS}); dispatch({type: Actions.COLORS});
dispatch({type: Actions.NOTES}); dispatch({type: Actions.NOTES});
}, [notes]); }, [notes]);
const onBlur = useCallback(() => { const onBlur = useCallback(() => {}, []);
}, []);
useEffect(() => { useEffect(() => {
navigation.addListener('focus', onFocus); navigation.addListener('focus', onFocus);
@@ -59,18 +64,22 @@ export const Home = ({navigation}) => {
useEffect(() => { useEffect(() => {
if (navigation.isFocused()) { if (navigation.isFocused()) {
eSendEvent(eUpdateSearchState,{ dispatch({
type: Actions.HEADER_VERTICAL_MENU,
state: notes.length > 0,
});
eSendEvent(eUpdateSearchState, {
placeholder: 'Search all notes', placeholder: 'Search all notes',
data: notes, data: notes,
noSearch: false, noSearch: false,
type: 'notes', type: 'notes',
color: null, color: null,
}) });
} }
}, [notes]); }, [notes]);
const _onPressBottomButton = async () => { const _onPressBottomButton = async () => {
eSendEvent(eOnLoadNote, {type: 'new'}); eSendEvent(eOnLoadNote, {type: 'new'});
if (DDS.isPhone || DDS.isSmallTab) { if (DDS.isPhone || DDS.isSmallTab) {
@@ -98,7 +107,6 @@ export const Home = ({navigation}) => {
title="Create a new note" title="Create a new note"
onPress={_onPressBottomButton} onPress={_onPressBottomButton}
/> />
</> </>
); );
}; };

View File

@@ -45,8 +45,6 @@ import {DDS} from '../../services/DeviceDetection';
import {MMKV} from '../../utils/mmkv'; import {MMKV} from '../../utils/mmkv';
import Backup from '../../services/Backup'; import Backup from '../../services/Backup';
export const Settings = ({navigation}) => { export const Settings = ({navigation}) => {
const [state, dispatch] = useTracked(); const [state, dispatch] = useTracked();
const {colors, user, settings} = state; const {colors, user, settings} = state;
@@ -127,9 +125,10 @@ export const Settings = ({navigation}) => {
paragraph: paragraph:
"All your backups are stored in 'Phone Storage/Notesnook/backups/' folder", "All your backups are stored in 'Phone Storage/Notesnook/backups/' folder",
}); });
await Backup.run(); await Backup.run();
await sleep(2000); await sleep(1000);
eSendEvent(eCloseProgressDialog); eSendEvent(eCloseProgressDialog);
}, },
desc: 'Backup all your data to phone storage', desc: 'Backup all your data to phone storage',
}, },
@@ -305,9 +304,6 @@ export const Settings = ({navigation}) => {
height={40} height={40}
/> />
</View> </View>
{
// Ad code here
}
</View> </View>
</View> </View>
{[ {[
@@ -317,7 +313,7 @@ export const Settings = ({navigation}) => {
eSendEvent(eOpenRecoveryKeyDialog); eSendEvent(eOpenRecoveryKeyDialog);
}, },
desc: desc:
'We recommend you to get your data recovery key and store it safely. If you lose your password, you can recover your data using your recovery key.', 'Save your recovery key. If you lose your password, you can recover your data using your recovery key.',
}, },
{ {
name: 'Logout', name: 'Logout',