mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 15:09:33 +01:00
add ResultDialog
This commit is contained in:
@@ -77,21 +77,17 @@ const App = () => {
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
let message = 'Internet connection restored';
|
||||
let type = 'success';
|
||||
if (!netInfo.isConnected || !netInfo.isInternetReachable) {
|
||||
message = 'No internet connection';
|
||||
type = 'error';
|
||||
}
|
||||
db.user?.get().then((user) => {
|
||||
if (user) {
|
||||
ToastEvent.show('No internet connection', 'error');
|
||||
} else {
|
||||
ToastEvent.show(message, type);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
db.user?.get().then((user) => {
|
||||
if (user) {
|
||||
ToastEvent.show('Internet connection restored', 'success');
|
||||
} else {
|
||||
}
|
||||
});
|
||||
}
|
||||
}, [netInfo]);
|
||||
|
||||
const syncChanges = async () => {
|
||||
@@ -156,7 +152,7 @@ const App = () => {
|
||||
}
|
||||
} catch (e) {
|
||||
error = e;
|
||||
console.log(e)
|
||||
console.log(e);
|
||||
}
|
||||
if (!user || !user.id) {
|
||||
setLoginMessage(dispatch);
|
||||
@@ -170,12 +166,11 @@ const App = () => {
|
||||
ToastEvent.show(error.message);
|
||||
}, 500);
|
||||
}
|
||||
|
||||
});
|
||||
}, []);
|
||||
|
||||
async function backupData() {
|
||||
await sleep(1000)
|
||||
await sleep(1000);
|
||||
settings = await MMKV.getStringAsync('settings');
|
||||
settings = JSON.parse(settings);
|
||||
if (await Backup.checkBackupRequired(settings.reminder)) {
|
||||
@@ -201,7 +196,7 @@ const App = () => {
|
||||
firstLoad = false;
|
||||
}
|
||||
settings = await MMKV.getStringAsync('settings');
|
||||
console.log('settings',settings)
|
||||
console.log('settings', settings);
|
||||
if (!settings) {
|
||||
settings = defaultState.settings;
|
||||
await MMKV.setStringAsync('settings', JSON.stringify(settings));
|
||||
@@ -214,7 +209,6 @@ const App = () => {
|
||||
dispatch({type: Actions.SETTINGS, settings: {...settings}});
|
||||
updateSize();
|
||||
await updateTheme();
|
||||
|
||||
}
|
||||
|
||||
if (!init) {
|
||||
|
||||
@@ -43,6 +43,7 @@ import {VaultDialog} from '../VaultDialog';
|
||||
import {TEMPLATE_DELETE, TEMPLATE_PERMANANT_DELETE} from './Templates';
|
||||
import {hexToRGBA} from "../../utils/ColorUtils";
|
||||
import {DDS} from "../../services/DeviceDetection";
|
||||
import ResultDialog from '../ResultDialog';
|
||||
|
||||
export class DialogManager extends Component {
|
||||
constructor(props) {
|
||||
@@ -376,6 +377,8 @@ export class DialogManager extends Component {
|
||||
<ProgressDialog />
|
||||
|
||||
<RestoreDialog/>
|
||||
|
||||
<ResultDialog/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import {DDS} from "../../services/DeviceDetection";
|
||||
|
||||
const ProgressDialog = () => {
|
||||
const [state, dispatch] = useTracked();
|
||||
const {colors, tags, premiumUser} = state;
|
||||
const {colors,} = state;
|
||||
const [visible, setVisible] = useState(false);
|
||||
const [dialogData, setDialogData] = useState({
|
||||
title: 'Loading',
|
||||
|
||||
@@ -5,11 +5,12 @@ import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
|
||||
import RNFetchBlob from 'rn-fetch-blob';
|
||||
import {LOGO_BASE64} from '../../assets/images/assets';
|
||||
import {
|
||||
eSendEvent,
|
||||
eSubscribeEvent,
|
||||
eUnSubscribeEvent,
|
||||
ToastEvent,
|
||||
} from '../../services/EventManager';
|
||||
import {eOpenRecoveryKeyDialog} from '../../utils/Events';
|
||||
import {eOpenRecoveryKeyDialog, eOpenResultDialog} from '../../utils/Events';
|
||||
import {dWidth} from '../../utils';
|
||||
import ActionSheet from '../ActionSheet';
|
||||
import {Button} from '../Button';
|
||||
@@ -27,14 +28,28 @@ class RecoveryKeyDialog extends React.Component {
|
||||
this.actionSheetRef = createRef();
|
||||
this.svg = createRef();
|
||||
this.user;
|
||||
this.signup = false;
|
||||
}
|
||||
|
||||
open = () => {
|
||||
open = (signup) => {
|
||||
if (signup) {
|
||||
this.signup = true;
|
||||
}
|
||||
this.actionSheetRef.current?._setModalVisible(true);
|
||||
};
|
||||
|
||||
close = () => {
|
||||
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() {
|
||||
eSubscribeEvent(eOpenRecoveryKeyDialog, this.open);
|
||||
@@ -113,6 +128,7 @@ class RecoveryKeyDialog extends React.Component {
|
||||
alignSelf: 'center',
|
||||
borderRadius: 10,
|
||||
}}
|
||||
closeOnTouchBackdrop={false}
|
||||
onOpen={this.onOpen}
|
||||
ref={this.actionSheetRef}
|
||||
initialOffsetFromBottom={1}>
|
||||
@@ -233,7 +249,13 @@ class RecoveryKeyDialog extends React.Component {
|
||||
data or reset your password using this recovery key.
|
||||
</Text>
|
||||
</View>
|
||||
|
||||
<Seperator />
|
||||
<Button
|
||||
title="I have saved the key."
|
||||
width="100%"
|
||||
height={50}
|
||||
onPress={this.close}
|
||||
/>
|
||||
<Toast context="local" />
|
||||
</View>
|
||||
</ActionSheet>
|
||||
|
||||
85
apps/mobile/src/components/ResultDialog/index.js
Normal file
85
apps/mobile/src/components/ResultDialog/index.js
Normal 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;
|
||||
@@ -111,3 +111,6 @@ export const eCloseRestoreDialog = '554';
|
||||
export const eOnNoteEdited = '555';
|
||||
|
||||
export const eUpdateSearchState = '556';
|
||||
|
||||
export const eOpenResultDialog = '557';
|
||||
export const eCloseResultDialog = '558';
|
||||
@@ -96,9 +96,6 @@ async function requestPermission() {
|
||||
}
|
||||
return granted;
|
||||
}
|
||||
|
||||
|
||||
|
||||
async function checkAndCreateDir(path) {
|
||||
let dir = Platform.OS === "ios"? IOS_PATH + path : ANDROID_PATH + path;
|
||||
try {
|
||||
|
||||
@@ -6,9 +6,14 @@ import {NoteItemWrapper} from '../../components/SimpleList/NoteItemWrapper';
|
||||
import {useTracked} from '../../provider';
|
||||
import {Actions} from '../../provider/Actions';
|
||||
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 {DDS} from "../../services/DeviceDetection";
|
||||
import {DDS} from '../../services/DeviceDetection';
|
||||
import ResultDialog from '../../components/ResultDialog';
|
||||
|
||||
export const Home = ({navigation}) => {
|
||||
const [state, dispatch] = useTracked();
|
||||
@@ -17,12 +22,13 @@ export const Home = ({navigation}) => {
|
||||
const onFocus = useCallback(() => {
|
||||
dispatch({
|
||||
type: Actions.HEADER_VERTICAL_MENU,
|
||||
state: true,
|
||||
state: notes.length > 0,
|
||||
});
|
||||
|
||||
dispatch({
|
||||
type: Actions.HEADER_TEXT_STATE,
|
||||
state: {
|
||||
heading: "Home",
|
||||
heading: 'Home',
|
||||
},
|
||||
});
|
||||
dispatch({
|
||||
@@ -39,14 +45,13 @@ export const Home = ({navigation}) => {
|
||||
noSearch: false,
|
||||
type: 'notes',
|
||||
color: null,
|
||||
})
|
||||
});
|
||||
eSendEvent(eScrollEvent, 0);
|
||||
dispatch({type: Actions.COLORS});
|
||||
dispatch({type: Actions.NOTES});
|
||||
}, [notes]);
|
||||
|
||||
const onBlur = useCallback(() => {
|
||||
}, []);
|
||||
const onBlur = useCallback(() => {}, []);
|
||||
|
||||
useEffect(() => {
|
||||
navigation.addListener('focus', onFocus);
|
||||
@@ -59,18 +64,22 @@ export const Home = ({navigation}) => {
|
||||
|
||||
useEffect(() => {
|
||||
if (navigation.isFocused()) {
|
||||
dispatch({
|
||||
type: Actions.HEADER_VERTICAL_MENU,
|
||||
state: notes.length > 0,
|
||||
});
|
||||
|
||||
eSendEvent(eUpdateSearchState, {
|
||||
placeholder: 'Search all notes',
|
||||
data: notes,
|
||||
noSearch: false,
|
||||
type: 'notes',
|
||||
color: null,
|
||||
})
|
||||
});
|
||||
}
|
||||
}, [notes]);
|
||||
|
||||
const _onPressBottomButton = async () => {
|
||||
|
||||
eSendEvent(eOnLoadNote, {type: 'new'});
|
||||
|
||||
if (DDS.isPhone || DDS.isSmallTab) {
|
||||
@@ -98,7 +107,6 @@ export const Home = ({navigation}) => {
|
||||
title="Create a new note"
|
||||
onPress={_onPressBottomButton}
|
||||
/>
|
||||
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -45,8 +45,6 @@ import {DDS} from '../../services/DeviceDetection';
|
||||
import {MMKV} from '../../utils/mmkv';
|
||||
import Backup from '../../services/Backup';
|
||||
|
||||
|
||||
|
||||
export const Settings = ({navigation}) => {
|
||||
const [state, dispatch] = useTracked();
|
||||
const {colors, user, settings} = state;
|
||||
@@ -128,8 +126,9 @@ export const Settings = ({navigation}) => {
|
||||
"All your backups are stored in 'Phone Storage/Notesnook/backups/' folder",
|
||||
});
|
||||
await Backup.run();
|
||||
await sleep(2000);
|
||||
await sleep(1000);
|
||||
eSendEvent(eCloseProgressDialog);
|
||||
|
||||
},
|
||||
desc: 'Backup all your data to phone storage',
|
||||
},
|
||||
@@ -305,9 +304,6 @@ export const Settings = ({navigation}) => {
|
||||
height={40}
|
||||
/>
|
||||
</View>
|
||||
{
|
||||
// Ad code here
|
||||
}
|
||||
</View>
|
||||
</View>
|
||||
{[
|
||||
@@ -317,7 +313,7 @@ export const Settings = ({navigation}) => {
|
||||
eSendEvent(eOpenRecoveryKeyDialog);
|
||||
},
|
||||
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',
|
||||
|
||||
Reference in New Issue
Block a user