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
add RestoreDialog
ammarahm-edda3f0d2379ea
diff --git a/apps/mobile/src/components/DialogManager/index.js b/apps/mobile/src/components/DialogManager/index.jsindex 2d919ce72..fe7f92071 100644--- a/apps/mobile/src/components/DialogManager/index.js+++ b/apps/mobile/src/components/DialogManager/index.js@@ -1,10 +1,10 @@import React, {Component} from 'react';import {Platform} from 'react-native';import {+ eSendEvent,eSubscribeEvent,eUnSubscribeEvent,openVault,- eSendEvent,} from '../../services/eventManager';import {eCloseActionSheet,@@ -12,17 +12,17 @@ import {eCloseAddTopicDialog,eCloseLoginDialog,eCloseMoveNoteDialog,+ eClosePremiumDialog,eCloseSimpleDialog,eOnLoadNote,eOpenActionSheet,eOpenAddNotebookDialog,eOpenAddTopicDialog,+ eOpenExportDialog,eOpenLoginDialog,eOpenMoveNoteDialog,- eOpenSimpleDialog,eOpenPremiumDialog,- eClosePremiumDialog,- eOpenExportDialog,+ eOpenSimpleDialog,} from '../../services/events';import {DDS, hexToRGBA} from '../../utils/utils';import ActionSheet from '../ActionSheet';@@ -30,17 +30,18 @@ import {ActionSheetComponent} from '../ActionSheetComponent';import {AddNotebookDialog} from '../AddNotebookDialog';import {AddTopicDialog} from '../AddTopicDialog';import {Dialog} from '../Dialog';+import ExportDialog from '../ExportDialog';+import LoginDialog from '../LoginDialog';import MergeEditor from '../MergeEditor';-import {VaultDialog} from '../VaultDialog';-import {moveNoteEvent} from './recievers';-import {TEMPLATE_DELETE, TEMPLATE_PERMANANT_DELETE} from './templates';import MoveNoteDialog from '../MoveNoteDialog';-import LoginDialog from '../LoginDialog';-import PremiumDialog from '../Premium/PremiumDialog';-import ExportDialog from '../ExportDialog';-import RecoveryKeyDialog from '../RecoveryKeyDialog';import PendingDialog from '../Premium/PendingDialog';+import PremiumDialog from '../Premium/PremiumDialog';import PremiumStatusDialog from '../Premium/PremiumStatusDialog';+import ProgressDialog from '../ProgressDialog';+import RecoveryKeyDialog from '../RecoveryKeyDialog';+import RestoreDialog from '../RestoreDialog';+import {VaultDialog} from '../VaultDialog';+import {TEMPLATE_DELETE, TEMPLATE_PERMANANT_DELETE} from './templates';export class DialogManager extends Component {constructor(props) {@@ -372,6 +373,9 @@ export class DialogManager extends Component {<PendingDialog colors={colors} /><PremiumStatusDialog />+ <ProgressDialog />++ <RestoreDialog/></>);}diff --git a/apps/mobile/src/components/RestoreDialog/index.js b/apps/mobile/src/components/RestoreDialog/index.jsnew file mode 100644index 000000000..7e12a1cb6--- /dev/null+++ b/apps/mobile/src/components/RestoreDialog/index.js@@ -0,0 +1,245 @@+import React, {useEffect, useState} from 'react';+import {Dimensions, Text, View, FlatList} from 'react-native';+import {ph, SIZE, WEIGHT} from '../../common/common';+import {useTracked} from '../../provider';+import {eSubscribeEvent, eUnSubscribeEvent} from '../../services/eventManager';+import {+ eCloseProgressDialog,+ eCloseRestoreDialog,+ eOpenProgressDialog,+ eOpenRestoreDialog,+} from '../../services/events';+import {+ db,+ getElevation,+ requestStoragePermission,+ sleep,+ ToastEvent,+} from '../../utils/utils';+import BaseDialog from '../Dialog/base-dialog';+import Icon from 'react-native-vector-icons/MaterialCommunityIcons';+import {useSafeAreaInsets} from 'react-native-safe-area-context';+import RNFetchBlob from 'rn-fetch-blob';+import storage from '../../utils/storage';+import {PressableButton} from '../PressableButton';+import {Button} from '../Button';+import {Loading} from '../Loading';+import {ACTIONS} from '../../provider/actions';++const RestoreDialog = () => {+ const [state, dispatch] = useTracked();+ const {colors, tags, premiumUser} = state;+ const [visible, setVisible] = useState(true);+ const [files, setFiles] = useState([]);+ const [restoring, setRestoring] = useState(false);+ const insets = useSafeAreaInsets();+ useEffect(() => {+ eSubscribeEvent(eOpenRestoreDialog, open);+ eSubscribeEvent(eCloseRestoreDialog, close);+ return () => {+ eUnSubscribeEvent(eOpenRestoreDialog, open);+ eUnSubscribeEvent(eCloseRestoreDialog, close);+ };+ }, []);++ const open = (data) => {+ setVisible(true);+ };++ const close = () => {+ setVisible(false);+ };++ return (+ <BaseDialog+ animation="slide"+ visible={visible}+ onShow={async () => {+ await storage.checkAndCreateDir(+ RNFetchBlob.fs.dirs.SDCardDir + '/Notesnook/backups',+ );+ let files = await RNFetchBlob.fs.lstat(+ RNFetchBlob.fs.dirs.SDCardDir + '/Notesnook/backups',+ );+ console.log(files);+ setFiles(files);+ }}+ onRequestClose={close}>+ <View+ style={{+ ...getElevation(5),+ width: '100%',+ height: '100%',+ borderRadius: 5,+ backgroundColor: colors.bg,+ paddingHorizontal: 12,+ paddingVertical: 20,+ paddingTop: insets.top,+ }}>+ <BaseDialog visible={restoring}>+ <View+ style={{+ ...getElevation(5),+ width: '80%',+ maxHeight: 350,+ borderRadius: 5,+ backgroundColor: colors.bg,+ paddingHorizontal: ph,+ paddingVertical: 20,+ }}>+ <Loading height={40} tagline="Resoring your data" />+ <Text+ style={{+ fontFamily: WEIGHT.regular,+ alignSelf: 'center',+ textAlign: 'center',+ color: colors.icon,+ fontSize: SIZE.xs,+ }}>+ Your data is being restored+ </Text>+ </View>+ </BaseDialog>++ <View+ style={{+ flexDirection: 'row',+ justifyContent: 'center',+ alignItems: 'center',+ height: 50,+ }}>+ <Icon+ name="close"+ size={SIZE.xxl}+ onPress={close}+ style={{+ width: 50,+ height: 50,+ position: 'absolute',+ textAlignVertical: 'center',+ left: 0,+ marginBottom: 15,+ }}+ color={colors.heading}+ />+ <Text+ style={{+ color: colors.accent,+ fontFamily: WEIGHT.bold,+ fontSize: SIZE.xl,+ }}>+ Choose a Backup+ </Text>+ </View>+ <Text+ style={{+ color: colors.icon,+ fontFamily: WEIGHT.regular,+ fontSize: SIZE.xs + 1,+ textAlign: 'center',+ }}>+ Phone Storage/Notesnook/backups/+ </Text>++ <FlatList+ data={files}+ style={{+ height: '100%',+ }}+ contentContainerStyle={{+ height: '100%',+ }}+ ListEmptyComponent={+ <View+ style={{+ width: '90%',+ height: '100%',+ justifyContent: 'center',+ alignItems: 'center',+ alignSelf: 'center',+ }}>+ <Text+ style={{+ color: colors.pri,+ fontFamily: WEIGHT.regular,+ fontSize: SIZE.sm,+ textAlign: 'center',+ marginBottom: 10,+ }}>+ No Backups Found+ </Text>+ <Text+ style={{+ color: colors.icon,+ fontFamily: WEIGHT.regular,+ fontSize: SIZE.xs + 1,+ textAlign: 'center',+ }}>+ All backups are stored in 'Phone Storage/Notesnook/backups'+ folder. If you have migrated to a new device, move your backups+ to{' '}+ <Text style={{color: colors.accent}}>+ 'Phone Storage/Notesnook/backups'+ </Text>{' '}+ so they can be restored.+ </Text>+ </View>+ }+ renderItem={({item, index}) => (+ <View+ key={item.filename}+ style={{+ minHeight: 50,+ justifyContent: 'space-between',+ alignItems: 'center',+ width: '100%',+ borderRadius: 0,+ flexDirection: 'row',+ borderBottomWidth: 0.5,+ borderBottomColor: colors.nav,+ }}>+ <Text+ style={{+ fontFamily: WEIGHT.regular,+ fontSize: SIZE.xs + 1,+ }}>+ {item.filename+ .replace('notesnook_backup_', '')+ .replace('.nnbackup', '')}+ </Text>++ <Button+ title="Restore"+ width={80}+ height={30}+ onPress={async () => {+ let granted = await requestStoragePermission();+ if (!granted) {+ ToastEvent.show(+ 'Restore Failed! Storage access denied',+ 'error',+ );+ return;+ }+ setRestoring(true);+ let backup = await RNFetchBlob.fs.readFile(+ 'file:/' + item.path,+ 'utf8',+ );+ await db.backup.import(backup);+ await sleep(2000);+ setRestoring(false);+ dispatch({type: ACTIONS.ALL});+ ToastEvent.show('Restore Complete!', 'success');+ setVisible(false);+ }}+ />+ </View>+ )}+ />+ </View>+ </BaseDialog>+ );+};++export default RestoreDialog;diff --git a/apps/mobile/src/services/events.js b/apps/mobile/src/services/events.jsindex 36d08b933..dc5a061b1 100644--- a/apps/mobile/src/services/events.js+++ b/apps/mobile/src/services/events.js@@ -98,4 +98,12 @@ export const eClosePendingDialog = '548';export const eOpenPremiumStatusDialog = '549';-export const eClosePremiumStatusDialog = '550';\ No newline at end of file+export const eClosePremiumStatusDialog = '550';++export const eOpenProgressDialog = '551';++export const eCloseProgressDialog = '552';++export const eOpenRestoreDialog = '553';++export const eCloseRestoreDialog = '554';