refactoring

This commit is contained in:
ammarahm-ed
2021-02-16 16:11:10 +05:00
parent 97c79ad26c
commit 06f139901b
38 changed files with 312 additions and 232 deletions

View File

@@ -15,6 +15,7 @@ import {
eSubscribeEvent,
eUnSubscribeEvent,
} from './src/services/EventManager';
import Navigation from './src/services/Navigation';
import SettingsService from './src/services/SettingsService';
import {changeAppScale} from './src/utils/Animations';
import {db} from './src/utils/DB';
@@ -96,11 +97,8 @@ const Overlay = ({onLoad}) => {
const load = async () => {
db.notes.init().then(() => {
init = true;
if (SettingsService.get().homepage === 'Notes') {
dispatch({type: Actions.NOTES});
} else {
dispatch({type: Actions.FAVORITES});
}
dispatch({type: Actions.NOTES});
dispatch({type: Actions.FAVORITES});
// if (!animation) {
dispatch({type: Actions.LOADING, loading: false});
// }

View File

@@ -14,6 +14,7 @@ import {
setEmailVerifyMessage,
setLoginMessage,
} from './src/services/Message';
import Navigation from './src/services/Navigation';
import PremiumService from './src/services/PremiumService';
import SettingsService from './src/services/SettingsService';
import Sync from './src/services/Sync';
@@ -21,6 +22,7 @@ import {APP_VERSION, editing} from './src/utils';
import {COLOR_SCHEME} from './src/utils/Colors';
import {db} from './src/utils/DB';
import {
eClearEditor,
eCloseProgressDialog,
eOpenLoginDialog,
eOpenProgressDialog,
@@ -120,12 +122,14 @@ export const AppRootEvents = React.memo(
EV.subscribe(EVENTS.userEmailConfirmed, onEmailVerified);
EV.subscribe(EVENTS.userCheckStatus, PremiumService.onUserStatusCheck);
EV.subscribe(EVENTS.userSubscriptionUpdated, onAccountStatusChange);
EV.subscribe(EVENTS.noteRemoved, onNoteRemoved);
return () => {
EV.unsubscribe(EVENTS.appRefreshRequested, onSyncComplete);
EV.unsubscribe(EVENTS.databaseSyncRequested, partialSync);
EV.unsubscribe(EVENTS.userLoggedOut, onLogout);
EV.unsubscribe(EVENTS.userEmailConfirmed, onEmailVerified);
EV.unsubscribe(EVENTS.noteRemoved, onNoteRemoved);
EV.unsubscribe(
EVENTS.userCheckStatus,
PremiumService.onUserStatusCheck,
@@ -137,6 +141,21 @@ export const AppRootEvents = React.memo(
};
}, []);
const onNoteRemoved = async (id) => {
try {
console.log("removing note");
await db.notes.remove(id);
Navigation.setRoutesToUpdate([
Navigation.routeNames.Favorites,
Navigation.routeNames.Notes,
Navigation.routeNames.NotesPage,
Navigation.routeNames.Trash,
Navigation.routeNames.Notebook,
]);
eSendEvent(eClearEditor);
} catch (e) {}
};
useEffect(() => {
let unsubscribe;
if (!loading) {
@@ -208,7 +227,7 @@ export const AppRootEvents = React.memo(
? 'Thank you for signing up for Notesnook Beta Program. Enjoy all premium features for free for the next 3 months.'
: 'Your Notesnook Pro Trial has been activated. Enjoy all premium features for free for the next 14 days!';
eSendEvent(eOpenProgressDialog, {
title: 'Email Confirmed!',
title: 'Email confirmed!',
paragraph: message,
noProgress: true,
});
@@ -270,7 +289,7 @@ export const AppRootEvents = React.memo(
setLoginMessage(dispatch);
await PremiumService.setPremiumStatus();
eSendEvent(eOpenProgressDialog, {
title: reason ? reason : 'User Logged Out',
title: reason ? reason : 'User logged out',
paragraph: `You have been logged out of your account.`,
action: async () => {
eSendEvent(eCloseProgressDialog);

View File

@@ -260,7 +260,7 @@ export default class NotesnookShare extends Component {
this.textInputRef.current?.focus();
}}
blurOnSubmit={false}
placeholder="Note Title"
placeholder="Note title"
/>
<TouchableOpacity
@@ -398,7 +398,7 @@ export default class NotesnookShare extends Component {
this.textInputRef.current?.focus();
}}
blurOnSubmit={false}
placeholder="Note Title"
placeholder="Note title"
/>
<TouchableOpacity

View File

@@ -1,6 +1,6 @@
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: [
//"transform-remove-console"
"transform-remove-console"
]
};

View File

@@ -20,7 +20,8 @@ export const ActionIcon = ({
testID,
disabled,
onLongPress,
tooltipText
tooltipText,
type="gray"
}) => {
const [state, dispatch] = useTracked();
const {colors} = state;
@@ -40,7 +41,7 @@ export const ActionIcon = ({
}
}}
disabled={disabled}
type="gray"
type={type}
customStyle={{
width: 40,
height: 40,

View File

@@ -9,6 +9,7 @@ import {
sendNoteEditedEvent,
ToastEvent,
} from '../../services/EventManager';
import Navigation from '../../services/Navigation';
import {db} from '../../utils/DB';
import {refreshNotesPage} from '../../utils/Events';
import {SIZE} from '../../utils/SizeUtils';
@@ -23,16 +24,18 @@ let backPressCount = 0;
export const ActionSheetTagsSection = ({item, close}) => {
const [state, dispatch] = useTracked();
const {colors, tags, premiumUser} = state;
const {colors, } = state;
const [suggestions, setSuggestions] = useState([]);
const [focused, setFocused] = useState(false);
const [note, setNote] = useState(item);
const localRefresh = () => {
toAdd = db.notes.note(note.id).data;
dispatch({type: Actions.NOTES});
dispatch({type: Actions.TAGS});
eSendEvent(refreshNotesPage);
Navigation.setRoutesToUpdate([
Navigation.routeNames.Tags,
Navigation.routeNames.Notes,
Navigation.routeNames.NotesPage
])
setNote({...toAdd});
if (prevQuery) {
getSuggestions(prevQuery, toAdd);
@@ -61,7 +64,9 @@ export const ActionSheetTagsSection = ({item, close}) => {
}
try {
await db.notes.note(note.id).tag(tag);
dispatch({type: Actions.TAGS});
Navigation.setRoutesToUpdate([
Navigation.routeNames.Tags,
])
localRefresh(note.type);
prevQuery = null;
tagsInputRef.current?.setNativeProps({

View File

@@ -20,6 +20,7 @@ import {
sendNoteEditedEvent,
ToastEvent,
} from '../../services/EventManager';
import Navigation from '../../services/Navigation';
import PremiumService from '../../services/PremiumService';
import Sync from '../../services/Sync';
import {editing, toTXT} from '../../utils';
@@ -123,9 +124,11 @@ export const ActionSheetComponent = ({
if (!nodispatch) {
dispatch({type: type});
if (type === 'note') {
eSendEvent(refreshNotesPage);
Navigation.setRoutesToUpdate([
Navigation.routeNames.NotesPage,
Navigation.routeNames.Favorites,
])
}
dispatch({type: Actions.FAVORITES});
}
setNote({...toAdd});
};
@@ -153,6 +156,8 @@ export const ActionSheetComponent = ({
novault: true,
locked: true,
share: true,
title:'Share note',
description:"Unlock note to share it."
});
} else {
let text = await db.notes.note(note.id).export('txt');
@@ -184,6 +189,8 @@ export const ActionSheetComponent = ({
novault: true,
locked: true,
item: note,
title:'Delete note',
description:"Unlock note to delete it."
});
} else {
try {
@@ -219,6 +226,8 @@ export const ActionSheetComponent = ({
novault: true,
locked: true,
item: note,
title:'Copy note',
description:"Unlock note to copy to clipboard."
});
} else {
let text = await db.notes.note(note.id).content();
@@ -234,10 +243,14 @@ export const ActionSheetComponent = ({
icon: 'delete-restore',
func: async () => {
await db.trash.restore(note.id);
dispatch({type: Actions.TRASH});
dispatch({type: note.itemType});
dispatch({type: Actions.FAVORITES});
eSendEvent(refreshNotesPage);
Navigation.setRoutesToUpdate([
Navigation.routeNames.Tags,
Navigation.routeNames.Notes,
Navigation.routeNames.Notebooks,
Navigation.routeNames.NotesPage,
Navigation.routeNames.Favorites,
Navigation.routeNames.Trash
])
type = note.type === 'trash' ? note.itemType : note.type;
ToastEvent.show(
type === 'note' ? 'Note restored' : 'Notebook restored',
@@ -717,11 +730,12 @@ export const ActionSheetComponent = ({
.notebook(editing.actionAfterFirstSave.notebook)
.topics.topic(editing.actionAfterFirstSave.id)
.delete(note.id);
eSendEvent(refreshNotesPage);
eSendEvent(eOnNewTopicAdded);
dispatch({type: Actions.NOTEBOOKS});
dispatch({type: Actions.NOTES});
Navigation.setRoutesToUpdate([
Navigation.routeNames.Notebooks,
Navigation.routeNames.Notes,
Navigation.routeNames.NotesPage,
Navigation.routeNames.Notebook,
]);
setNote(db.notes.note(note.id).data);
close();
}}

View File

@@ -192,8 +192,7 @@ export class AddNotebookDialog extends React.Component {
});
}
this.close();
updateEvent({type: Actions.NOTEBOOKS});
updateEvent({type: Actions.PINNED});
Navigation.setRoutesToUpdate([Navigation.routeNames.Notebooks]);
};
onSubmit = (forward = true) => {
@@ -303,7 +302,7 @@ export class AddNotebookDialog extends React.Component {
onChangeText={(value) => {
this.title = value;
}}
placeholder="Enter a Title"
placeholder="Enter a title"
onSubmit={() => {
this.descriptionRef.focus();
}}

View File

@@ -1,24 +1,21 @@
import React, {createRef} from 'react';
import {Actions} from '../../provider/Actions';
import React, { createRef } from 'react';
import {
eSendEvent,
eSubscribeEvent,
eUnSubscribeEvent,
ToastEvent,
ToastEvent
} from '../../services/EventManager';
import {db} from '../../utils/DB';
import { db } from '../../utils/DB';
import {
eCloseAddTopicDialog,
eOnNewTopicAdded,
eOpenAddTopicDialog,
eOpenAddTopicDialog
} from '../../utils/Events';
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 {updateEvent} from '../DialogManager/recievers';
import Input from '../Input';
import {Toast} from '../Toast';
import { Toast } from '../Toast';
export class AddTopicDialog extends React.Component {
constructor(props) {
@@ -26,7 +23,7 @@ export class AddTopicDialog extends React.Component {
this.state = {
visible: false,
titleFocused: false,
loading:false
loading: false,
};
this.title;
@@ -35,7 +32,7 @@ export class AddTopicDialog extends React.Component {
}
addNewTopic = async () => {
this.setState({loading:true})
this.setState({loading: true});
if (!this.title)
return ToastEvent.show('Title is required', 'error', 'local');
@@ -48,8 +45,10 @@ export class AddTopicDialog extends React.Component {
await db.notebooks.notebook(topic.notebookId).topics.add(topic);
}
this.close();
updateEvent({type: Actions.NOTEBOOKS});
eSendEvent(eOnNewTopicAdded);
Navigation.setRoutesToUpdate([
Navigation.routeNames.Notebooks,
Navigation.routeNames.Notebook,
]);
};
componentDidMount() {

View File

@@ -239,6 +239,8 @@ export class DialogManager extends Component {
novault: true,
locked: true,
deleteNote: true,
title:'Delete note',
description:"Unlock to delete note."
});
} else {
this._showSimpleDialog(TEMPLATE_DELETE(this.state.item.type));
@@ -253,8 +255,8 @@ export class DialogManager extends Component {
openVault({
item: this.state.item,
novault: false,
locked: true,
deleteNote: true,
title:'Create vault',
description:"Set a password to create a vault and lock note."
});
break;
}
@@ -263,6 +265,8 @@ export class DialogManager extends Component {
item: this.state.item,
novault: true,
locked: true,
title:'Open note',
description:"Unlock note to open in editor"
});
break;
}
@@ -272,6 +276,8 @@ export class DialogManager extends Component {
novault: true,
locked: true,
permanant: true,
title:'Unlock note',
description:"Remove note from the vault."
});
break;
}

View File

@@ -196,7 +196,7 @@ const ExportDialog = () => {
<DialogButtons
onPressNegative={close}
negativeTitle="Cancel"
positiveTitle={complete && 'Open File'}
positiveTitle={complete && 'Open file'}
onPressPositive={
complete
? async () => {

View File

@@ -41,7 +41,7 @@ export const HeaderLeftMenu = () => {
return (
<>
{deviceMode === 'mobile' ||
currentScreen === 'search' ||
currentScreen === 'Search' ||
!headerMenuState ? (
<ActionIcon
testID={notesnook.ids.default.header.buttons.left}

View File

@@ -34,7 +34,7 @@ export const HeaderRightMenu = () => {
<View style={styles.rightBtnContainer}>
{syncing && <ActivityIndicator size={SIZE.xl} color={colors.accent} />}
{currentScreen !== 'settings' && (
{currentScreen !== 'Settings' && (
<ActionIcon
onPress={async () => {
Navigation.navigate('Search', {
@@ -55,7 +55,7 @@ export const HeaderRightMenu = () => {
containerBottomButton.onPress();
}}
testID={notesnook.ids.default.addBtn}
icon={currentScreen === 'trash' ? 'delete' : 'plus'}
icon={currentScreen === 'Trash' ? 'delete' : 'plus'}
iconSize={SIZE.xl}
type="shade"
style={{

View File

@@ -73,17 +73,17 @@ export const Header = ({root}) => {
<HeaderLeftMenu />
{(Platform.OS === 'android' ||
Platform.isPad) && currentScreen !== 'search' ? (
Platform.isPad) && currentScreen !== 'Search' ? (
<HeaderTitle root={root} />
) : null}
</View>
{Platform.OS !== 'android' &&
!Platform.isPad &&
currentScreen !== 'search' ? (
currentScreen !== 'Search' ? (
<HeaderTitle root={root} />
) : null}
{currentScreen === 'search' ? (
{currentScreen === 'Search' ? (
<View
style={{
width: '80%',
@@ -92,7 +92,7 @@ export const Header = ({root}) => {
</View>
) : null}
{currentScreen === 'search' ? (
{currentScreen === 'Search' ? (
<View style={[styles.rightBtnContainer, {right: 6}]}>
<ActionIcon
onPress={() => {

View File

@@ -32,7 +32,7 @@ export const Loading = ({
{doneText}
</Paragraph>
<Button onPress={onDone} title="Open File" />
<Button onPress={onDone} title="Open file" />
</>
) : (
<>

View File

@@ -502,7 +502,7 @@ const LoginDialog = () => {
}}
secureTextEntry
autoCapitalize="none"
placeholder="Current Password"
placeholder="Current password"
onSubmit={() => {
if (mode === MODES.signup) {
_pass.current?.focus();
@@ -569,7 +569,7 @@ const LoginDialog = () => {
autoCapitalize="none"
customValidator={() => password}
secureTextEntry
placeholder="Confirm Password"
placeholder="Confirm password"
errorMessage="Passwords do not match"
onSubmit={() => {
current.buttonFunc();

View File

@@ -55,7 +55,7 @@ export const UserSection = ({noTextMode}) => {
<View>
<Heading size={SIZE.sm} color={colors.heading}>
{!user ? 'Not Logged in' : 'Logged in'}
{!user ? 'Not logged in' : 'Logged in'}
</Heading>
<Paragraph

View File

@@ -445,7 +445,7 @@ const MergeEditor = () => {
<Button
width={null}
onPress={onPressSaveCopyFromPrimaryWebView}
title="Save Copy"
title="Save copy"
/>
) : null}
<View style={{width: 10}} />
@@ -590,7 +590,7 @@ const MergeEditor = () => {
width={null}
height={40}
onPress={onPressSaveCopyFromSecondaryWebView}
title="Save Copy"
title="Save copy"
/>
) : null}
<View style={{width: 10}} />

View File

@@ -74,6 +74,8 @@ export const NoteWrapper = ({item, index, isTrash = false}) => {
novault: true,
locked: true,
goToEditor: true,
title:'Open note',
description:"Unlock note to open it in editor."
});
return;
}

View File

@@ -25,7 +25,7 @@ class PremiumDialog extends React.Component {
products: null,
scrollEnabled: false,
product: null,
visible: true,
visible: false,
};
this.routeIndex = 0;
this.count = 0;
@@ -64,9 +64,6 @@ class PremiumDialog extends React.Component {
} catch (e) {}
}
componentDidMount() {
this.actionSheetRef.current?.setModalVisible(true);
}
features = [
{

View File

@@ -167,7 +167,7 @@ class RecoveryKeyDialog extends React.Component {
paddingTop: 10,
}}>
<DialogHeader
title="Your Data Recovery Key"
title="Your data recovery key"
paragraph="If you forget your password, you can recover your
data and reset your password using your data recovery key."
/>
@@ -197,7 +197,7 @@ class RecoveryKeyDialog extends React.Component {
ToastEvent.show('Copied!', 'success', 'local');
}}
icon="content-copy"
title="Copy to Clipboard"
title="Copy to clipboard"
width="100%"
type="gray"
fontSize={SIZE.md}
@@ -228,7 +228,7 @@ class RecoveryKeyDialog extends React.Component {
</View>
<Button
title="Save QR-Code to Gallery"
title="Save QR-Code to gallery"
onPress={this.saveQRCODE}
width="100%"
type="accent"
@@ -238,7 +238,7 @@ class RecoveryKeyDialog extends React.Component {
<Seperator />
<Button
onPress={this.saveToTextFile}
title="Save to Text File"
title="Save to text file"
width="100%"
type="accent"
fontSize={SIZE.md}
@@ -246,7 +246,7 @@ class RecoveryKeyDialog extends React.Component {
/>
<Seperator />
<Button
title="I Have Saved the Key."
title="I have saved the key."
width="100%"
height={50}
type="error"

View File

@@ -12,11 +12,7 @@ import {
} from '../../services/EventManager';
import Navigation from '../../services/Navigation';
import {db} from '../../utils/DB';
import {
eOpenMoveNoteDialog,
eOpenSimpleDialog,
refreshNotesPage,
} from '../../utils/Events';
import {eOpenMoveNoteDialog, eOpenSimpleDialog} from '../../utils/Events';
import {SIZE} from '../../utils/SizeUtils';
import {sleep} from '../../utils/TimeUtils';
import {ActionIcon} from '../ActionIcon';
@@ -57,6 +53,42 @@ export const SelectionHeader = () => {
}).start();
}, [selectionMode]);
const addToFavorite = async () => {
if (selectedItemsList.length > 0) {
selectedItemsList.forEach((item) => {
db.notes.note(item.id).favorite();
});
Navigation.setRoutesToUpdate([
Navigation.routeNames.Notes,
Navigation.routeNames.NotesPage,
Navigation.routeNames.Favorites,
]);
dispatch({type: Actions.SELECTION_MODE, enabled: false});
dispatch({type: Actions.CLEAR_SELECTION});
}
};
const restoreItem = async () => {
if (selectedItemsList.length > 0) {
let noteIds = [];
selectedItemsList.forEach((item) => {
noteIds.push(item.id);
});
await db.trash.restore(...noteIds);
Navigation.setRoutesToUpdate([
Navigation.routeNames.Tags,
Navigation.routeNames.Notes,
Navigation.routeNames.Notebooks,
Navigation.routeNames.NotesPage,
Navigation.routeNames.Favorites,
Navigation.routeNames.Trash,
]);
dispatch({type: Actions.SELECTION_MODE, enabled: false});
dispatch({type: Actions.CLEAR_SELECTION});
ToastEvent.show('Restore complete', 'success');
}
};
return (
<Animated.View
style={{
@@ -64,7 +96,7 @@ export const SelectionHeader = () => {
position: 'absolute',
height: 50 + insets.top,
paddingTop: insets.top,
backgroundColor: colors.bg,
backgroundColor: colors.accent,
justifyContent: 'center',
alignItems: 'center',
flexDirection: 'row',
@@ -100,18 +132,22 @@ export const SelectionHeader = () => {
dispatch({type: Actions.SELECTION_MODE, enabled: !selectionMode});
dispatch({type: Actions.CLEAR_SELECTION});
}}
color={colors.heading}
name="arrow-left"
color={colors.light}
name="close"
size={SIZE.xxxl}
/>
{Platform.OS === 'android' ? (
<Heading>{selectedItemsList.length + ' Selected'}</Heading>
<Heading color={colors.light}>
{selectedItemsList.length + ' Selected'}
</Heading>
) : null}
</View>
{Platform.OS !== 'android' ? (
<Heading>{selectedItemsList.length + ' Selected'}</Heading>
<Heading color={colors.light}>
{selectedItemsList.length + ' Selected'}
</Heading>
) : null}
<View
@@ -123,48 +159,37 @@ export const SelectionHeader = () => {
right: 12,
paddingTop: insets.top,
}}>
{currentScreen === 'trash' ||
currentScreen === 'notebooks' ||
currentScreen === 'notebook' ? null : (
{currentScreen === 'Trash' ||
currentScreen === 'Notebooks' ||
currentScreen === 'Notebook' ? null : (
<ActionIcon
onPress={async () => {
dispatch({type: Actions.SELECTION_MODE, enabled: false});
//dispatch({type: Actions.SELECTION_MODE, enabled: false});
await sleep(100);
eSendEvent(eOpenMoveNoteDialog);
}}
customStyle={{
marginLeft: 10,
}}
color={colors.heading}
color={colors.light}
name="plus"
size={SIZE.xl}
/>
)}
{currentScreen === 'favorites' ? (
{currentScreen === 'Favorites' ? (
<ActionIcon
onPress={async () => {
if (selectedItemsList.length > 0) {
selectedItemsList.forEach((item) => {
db.notes.note(item.id).favorite();
});
dispatch({type: Actions.FAVORITES});
eSendEvent(refreshNotesPage);
dispatch({type: Actions.NOTES});
dispatch({type: Actions.SELECTION_MODE, enabled: false});
dispatch({type: Actions.CLEAR_SELECTION});
}
}}
onPress={addToFavorite}
customStyle={{
marginLeft: 10,
}}
color={colors.heading}
color={colors.light}
name="star-off"
size={SIZE.xl}
/>
) : null}
{currentScreen === 'trash' ? null : (
{currentScreen === 'Trash' ? null : (
<ActionIcon
customStyle={{
marginLeft: 10,
@@ -173,33 +198,19 @@ export const SelectionHeader = () => {
eSendEvent(eOpenSimpleDialog, TEMPLATE_DELETE('item'));
return;
}}
color={colors.heading}
color={colors.light}
name="delete"
size={SIZE.xl}
/>
)}
{currentScreen === 'trash' ? (
{currentScreen === 'Trash' ? (
<ActionIcon
customStyle={{
marginLeft: 10,
}}
color={colors.heading}
onPress={async () => {
if (selectedItemsList.length > 0) {
let noteIds = [];
selectedItemsList.forEach((item) => {
noteIds.push(item.id);
});
await db.trash.restore(...noteIds);
dispatch({type: Actions.NOTEBOOKS});
dispatch({type: Actions.NOTES});
dispatch({type: Actions.TRASH});
dispatch({type: Actions.SELECTION_MODE, enabled: false});
dispatch({type: Actions.CLEAR_SELECTION});
ToastEvent.show('Restore complete', 'success');
}
}}
color={colors.light}
onPress={restoreItem}
name="delete-restore"
size={SIZE.xl - 3}
/>

View File

@@ -8,6 +8,7 @@ import {
sendNoteEditedEvent,
ToastEvent,
} from '../../services/EventManager';
import Navigation from '../../services/Navigation';
import {dWidth, getElevation, toTXT} from '../../utils';
import {db} from '../../utils/DB';
import {refreshNotesPage} from '../../utils/Events';
@@ -28,10 +29,12 @@ export const ActionStrip = ({note, setActionStrip}) => {
}, []);
const updateNotes = () => {
dispatch({type: Actions.NOTES});
Navigation.setRoutesToUpdate([
Navigation.routeNames.NotesPage,
Navigation.routeNames.Favorites,
Navigation.routeNames.Notes,
]);
sendNoteEditedEvent({id: note.id, forced: true});
dispatch({type: Actions.FAVORITES});
eSendEvent(refreshNotesPage);
};
const actions = [
@@ -118,6 +121,8 @@ export const ActionStrip = ({note, setActionStrip}) => {
novault: true,
locked: true,
item: note,
title:'Copy note',
description:"Unlock note to copy to clipboard."
});
} else {
let delta = await db.notes.note(note.id).content();
@@ -134,10 +139,14 @@ export const ActionStrip = ({note, setActionStrip}) => {
icon: 'delete-restore',
onPress: async () => {
await db.trash.restore(note.id);
dispatch({type: Actions.TRASH});
dispatch({type: note.itemType});
dispatch({type: Actions.FAVORITES});
eSendEvent(refreshNotesPage);
Navigation.setRoutesToUpdate([
Navigation.routeNames.Notes,
Navigation.routeNames.Notebooks,
Navigation.routeNames.NotesPage,
Navigation.routeNames.Favorites,
Navigation.routeNames.Trash,
]);
ToastEvent.show(
item.type === 'note' ? 'Note restored' : 'Notebook restored',
'success',

View File

@@ -68,6 +68,8 @@ const SelectionWrapper = ({
};
}, []);
return (
<PressableButton
customColor="transparent"

View File

@@ -69,6 +69,7 @@ const SplashScreen = () => {
];
useEffect(() => {
return;
Storage.read('introCompleted').then(async (r) => {
setVisible(true);
await sleep(500);
@@ -266,7 +267,7 @@ const SplashScreen = () => {
}}
style={{paddingHorizontal: 24}}
type="accent"
title={isNext ? 'Next' : 'Sign Up'}
title={isNext ? 'Next' : 'Sign up'}
/>
</View>
</Animated.View>

View File

@@ -30,7 +30,9 @@ const Paragraph = ({color, size = SIZE.sm, style, ...restProps}) => {
fontWeight: '400',
},
style,
]}></Text>
]}>
</Text>
);
};

View File

@@ -54,7 +54,7 @@ export const UpdateDialog = () => {
justifyContent: 'center',
alignItems: 'center',
}}>
<Heading>New Update Available!</Heading>
<Heading>New update available!</Heading>
<Paragraph
style={{
textAlign: 'center',
@@ -109,7 +109,7 @@ export const UpdateDialog = () => {
<Seperator />
<Button
title="Update Now"
title="Update now"
onPress={async () => {
let url_android =
'https://play.google.com/store/apps/details?id=com.streetwriters.notesnook';

View File

@@ -1,10 +1,8 @@
import React, {Component, createRef} from 'react';
import {InteractionManager, TouchableOpacity, View} from 'react-native';
import Share from 'react-native-share';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import {notesnook} from '../../../e2e/test.ids';
import {Actions} from '../../provider/Actions';
import BiometricService from '../../services/BiometricService';
import {DDS} from '../../services/DeviceDetection';
import {
@@ -21,16 +19,14 @@ import {
eCloseVaultDialog,
eOnLoadNote,
eOpenVaultDialog,
refreshNotesPage,
} from '../../utils/Events';
import {deleteItems} from '../../utils/functions';
import {tabBarRef} from '../../utils/Refs';
import {ph, SIZE} from '../../utils/SizeUtils';
import {sleep} from '../../utils/TimeUtils';
import {Button} from '../Button';
import BaseDialog from '../Dialog/base-dialog';
import DialogButtons from '../Dialog/dialog-buttons';
import DialogHeader from '../Dialog/dialog-header';
import {updateEvent} from '../DialogManager/recievers';
import Input from '../Input';
import {Toast} from '../Toast';
import Paragraph from '../Typography/Paragraph';
@@ -62,10 +58,52 @@ export class VaultDialog extends Component {
changePassword: false,
copyNote: false,
revokeFingerprintAccess: false,
title: 'Unlock Note',
description: null,
};
this.password = null;
this.confirmPassword = null;
this.newPassword = null;
(this.title = !this.state.novault
? 'Create Vault'
: this.state.fingerprintAccess
? 'Vault Fingerprint Unlock'
: this.state.revokeFingerprintAccess
? 'Revoke Vault Fingerprint Unlock'
: this.state.changePassword
? 'Change Vault Password'
: this.state.note.locked
? this.state.deleteNote
? 'Delete note'
: this.state.share
? 'Share note'
: this.state.copyNote
? 'Copy note'
: this.state.goToEditor
? 'Unlock note'
: 'Unlock note'
: 'Lock note'),
(this.description = !this.state.novault
? 'Set a password to create vault'
: this.state.fingerprintAccess
? 'Enter vault password to enable fingerprint unlocking'
: this.state.revokeFingerprintAccess
? 'Disable vault fingerprint unlock '
: this.state.changePassword
? 'Setup a new password for the vault.'
: this.state.permanant
? 'Enter password to remove note from vault.'
: this.state.note.locked
? this.state.deleteNote
? 'Unlock note to delete it.'
: this.state.share
? 'Unlock note to share it.'
: this.state.copyNote
? 'Unlock note to copy it.'
: this.state.goToEditor
? 'Unlock note to open it in editor'
: 'Enter vault password to unlock note.'
: 'Enter vault password to lock note.');
}
componentDidMount() {
@@ -93,7 +131,6 @@ export class VaultDialog extends Component {
if (biometry) {
available = true;
}
console.log('fingerprint', fingerprint, 'biometry', biometry);
this.setState({
note: data.item,
novault: data.novault,
@@ -109,6 +146,8 @@ export class VaultDialog extends Component {
fingerprintAccess: data.fingerprintAccess,
changePassword: data.changePassword,
revokeFingerprintAccess: data.revokeFingerprintAccess,
title: data.title,
description: data.description,
});
if (
@@ -117,7 +156,7 @@ export class VaultDialog extends Component {
!data.fingerprintAccess &&
!data.revokeFingerprintAccess
) {
await this._onPressFingerprintAuth();
await this._onPressFingerprintAuth(data.title, data.description);
} else {
this.setState({
visible: true,
@@ -280,17 +319,13 @@ export class VaultDialog extends Component {
}
};
async _deleteNote() {
this.close();
await db.notes.delete(this.state.note.id);
Navigation.setRoutesToUpdate([
Navigation.routeNames.Notes,
Navigation.routeNames.Favorites,
Navigation.routeNames.NotesPage,
Navigation.routeNames.Notebook,
]);
ToastEvent.show('Note deleted', 'success');
try {
await db.vault.remove(this.state.note.id, this.password);
await deleteItems(this.state.note);
this.close();
} catch (e) {
this._takeErrorAction(e);
}
}
async _enrollFingerprint(password) {
@@ -365,7 +400,7 @@ export class VaultDialog extends Component {
_copyNote(note) {
let text = toTXT(note.content.data);
let m = `${note.title}\n \n ${text}`;
text = `${note.title}\n \n ${text}`;
Clipboard.setString(text);
ToastEvent.show('Note copied to clipboard', 'success', 'local');
this.close();
@@ -374,12 +409,12 @@ export class VaultDialog extends Component {
async _shareNote(note) {
this.close();
let text = toTXT(note.content.data);
let m = `${note.title}\n \n ${text}`;
text = `${note.title}\n \n ${text}`;
try {
await Share.open({
title: 'Share note to',
failOnCancel: false,
message: m,
message: text,
});
} catch (e) {}
}
@@ -405,9 +440,12 @@ export class VaultDialog extends Component {
}
};
_onPressFingerprintAuth = async () => {
_onPressFingerprintAuth = async (title, description) => {
try {
let credentials = await BiometricService.getCredentials();
let credentials = await BiometricService.getCredentials(
title || this.state.title,
description || this.state.description,
);
if (credentials?.password) {
this.password = credentials.password;
@@ -460,46 +498,8 @@ export class VaultDialog extends Component {
paddingVertical: 15,
}}>
<DialogHeader
title={
!novault
? 'Create Vault'
: fingerprintAccess
? 'Vault Fingerprint Unlock'
: this.state.revokeFingerprintAccess
? 'Revoke Vault Fingerprint Unlock'
: changePassword
? 'Change Vault Password'
: note.locked
? deleteNote
? 'Delete note'
: share
? 'Share note'
: goToEditor
? 'Unlock note'
: 'Unlock note'
: 'Lock note'
}
paragraph={
!novault
? 'Set a password to create vault'
: fingerprintAccess
? 'Enter vault password to enable fingerprint unlocking'
: this.state.revokeFingerprintAccess
? 'Disable vault fingerprint unlock '
: changePassword
? 'Setup a new password for the vault.'
: permanant
? 'Enter password to remove note from vault.'
: note.locked
? deleteNote
? 'Unlock note to delete it.'
: share
? 'Unlock note to share it.'
: goToEditor
? 'Unlock note to open it in editor'
: 'Enter vault password to unlock note.'
: 'Enter vault password to lock note.'
}
title={this.state.title}
paragraph={this.state.description}
icon="shield"
/>
@@ -523,7 +523,7 @@ export class VaultDialog extends Component {
: 10
}
secureTextEntry
placeholder={changePassword ? 'Current Password' : 'Password'}
placeholder={changePassword ? 'Current password' : 'Password'}
/>
{!this.state.biometricUnlock ||
@@ -533,11 +533,7 @@ export class VaultDialog extends Component {
<Button
onPress={this._onPressFingerprintAuth}
width="100%"
title={
!note.locked
? 'Lock with Fingerprint'
: 'Unlock with Fingerprint'
}
title={'Biometric unlock'}
type="shade"
/>
)}
@@ -555,7 +551,7 @@ export class VaultDialog extends Component {
this.newPassword = value;
}}
secureTextEntry
placeholder={'New Password'}
placeholder={'New password'}
/>
</>
) : null}

View File

@@ -32,18 +32,18 @@ export const defaultState = {
screenshotMode: true,
privacyScreen: false,
},
currentScreen: 'notes',
currentScreen: 'Notes',
deviceMode:null,
colors: {
night: false,
bg: 'white',
fg: '#0560FF',
fg: '#00c853',
navbg: '#f6fbfc',
nav: '#f0f0f0',
pri: 'black',
sec: 'white',
accent: '#0560FF',
shade: '#0560FF12',
accent: '#00c853',
shade: '#00c85312',
normal: 'black',
icon: 'gray',
errorBg: '#FFD2D2',

View File

@@ -43,7 +43,7 @@ async function run() {
ToastEvent.show('Backup complete!', 'success');
eSendEvent(eOpenProgressDialog, {
title: 'Backup Complete',
title: 'Backup complete',
icon: 'cloud-upload',
paragraph:
'Share your backup to your cloud storage such as Dropbox or Google Drive.',
@@ -80,19 +80,22 @@ async function getLastBackupDate() {
}
async function checkBackupRequired(type) {
if (type === "off") return;
let now = Date.now();
let lastBackupDate = await getLastBackupDate();
if (!lastBackupDate) return false;
if (lastBackupDate === 'never') {
if (!lastBackupDate || lastBackupDate === 'never') {
return true;
}
lastBackupDate = parseInt(lastBackupDate);
if (type === 'daily' && lastBackupDate + MS_DAY < now) {
console.log("daily")
return true;
} else if (type === 'weekly' && lastBackupDate + MS_WEEK < now) {
console.log("weekly")
return true;
} else {
console.log("no need",lastBackupDate);
return false;
}
}

View File

@@ -23,6 +23,8 @@ export const eSendEvent = (eventName, data) => {
* @typedef {Object} vaultType
* @property {Object} item
* @property {boolean} novault
* @property {string} title
* @property {string} description
* @property {boolean} locked
* @property {boolean} permanant
* @property {boolean} goToEditor

View File

@@ -40,7 +40,7 @@ function get() {
async function verify(callback, error) {
try {
if (!premiumStatus) {
if (premiumStatus) {
if (error) {
error();
return;
@@ -96,6 +96,10 @@ const onUserStatusCheck = async (type) => {
'With Notesnook Pro you can add notes to your vault and do so much more! Get it now.',
};
break;
case CHECK_IDS.databaseSync:
message = null;
break;
}
if (message) {
eSendEvent(eShowGetPremium, message);

View File

@@ -25,12 +25,12 @@ const getDpi = (pd) => {
const correction = (size, multiplier) => {
let dSize = getDeviceSize();
if (dSize >= 4 && dSize <= 5.3 && pixelDensity <= 3) {
return size * 0.92;
return size * 0.90;
} else if (dSize > 5.3 && dSize < 7 && pixelDensity < 3 && !DDS.isTab) {
if (Platform.OS === 'ios') {
return size;
}
return size * 0.93;
return size * 0.90;
} else if (dSize <= 7 && pixelDensity >= 3 && !DDS.isTab) {
return size * 0.98;
} else if (dSize >= 6.5 && dSize <= 7.2 && DDS.isTab) {
@@ -64,7 +64,7 @@ export const normalize = (size) => {
export const SIZE = {
xxs: normalize(9) * scale.fontScale,
xs: normalize(10.5) * scale.fontScale,
sm: normalize(12.5) * scale.fontScale,
sm: normalize(13.5) * scale.fontScale,
md: normalize(15) * scale.fontScale,
lg: normalize(21) * scale.fontScale,
xl: normalize(24) * scale.fontScale,
@@ -75,7 +75,7 @@ export const SIZE = {
export function updateSize() {
SIZE.xxs = normalize(9) * scale.fontScale;
SIZE.xs = normalize(10.5) * scale.fontScale;
SIZE.sm = normalize(12.5) * scale.fontScale;
SIZE.sm = normalize(13.5) * scale.fontScale;
SIZE.md = normalize(15) * scale.fontScale;
SIZE.lg = normalize(21) * scale.fontScale;
SIZE.xl = normalize(24) * scale.fontScale;

View File

@@ -1,11 +1,12 @@
import {Linking} from 'react-native';
import {InAppBrowser} from 'react-native-inappbrowser-reborn';
import {history} from '.';
import {updateEvent} from '../components/DialogManager/recievers';
import {Actions} from '../provider/Actions';
import {eSendEvent, ToastEvent} from '../services/EventManager';
import Navigation from '../services/Navigation';
import {db} from './DB';
import {eClearEditor, eOnNewTopicAdded, refreshNotesPage} from './Events';
import {Linking} from 'react-native';
import {InAppBrowser} from 'react-native-inappbrowser-reborn';
import {eClearEditor} from './Events';
export const deleteItems = async (item) => {
if (item && item.id && history.selectedItemsList.length === 0) {
@@ -22,26 +23,32 @@ export const deleteItems = async (item) => {
if (notes?.length > 0) {
let ids = notes.map((i) => i.id);
await db.notes.delete(...ids);
updateEvent({type: Actions.NOTES});
Navigation.setRoutesToUpdate([
Navigation.routeNames.Notes,
Navigation.routeNames.NotesPage,
]);
eSendEvent(eClearEditor);
eSendEvent(refreshNotesPage);
}
if (topics?.length > 0) {
for (var i = 0; i < topics.length; i++) {
let it = topics[i];
await db.notebooks.notebook(it.notebookId).topics.delete(it.id);
}
updateEvent({type: Actions.NOTEBOOKS});
Navigation.setRoutesToUpdate([
Navigation.routeNames.Notebooks,
Navigation.routeNames.Notebook,
]);
updateEvent({type: Actions.MENU_PINS});
eSendEvent(eOnNewTopicAdded);
ToastEvent.show('Topics deleted', 'success');
}
if (notebooks?.length > 0) {
let ids = notebooks.map((i) => i.id);
await db.notebooks.delete(...ids);
updateEvent({type: Actions.NOTEBOOKS});
updateEvent({type: Actions.NOTES});
Navigation.setRoutesToUpdate([
Navigation.routeNames.Notebooks,
Navigation.routeNames.Notes,
]);
updateEvent({type: Actions.MENU_PINS});
}
@@ -52,7 +59,7 @@ export const deleteItems = async (item) => {
if (topics.length === 0 && (notes.length > 0 || notebooks.length > 0)) {
ToastEvent.show(
message,
'error',
'success',
'global',
6000,
async () => {
@@ -64,9 +71,14 @@ export const deleteItems = async (item) => {
ids.push(trashItem.id);
}
await db.trash.restore(...ids);
updateEvent({type: Actions.NOTEBOOKS});
updateEvent({type: Actions.NOTES});
updateEvent({type: Actions.TRASH});
Navigation.setRoutesToUpdate([
Navigation.routeNames.Notebooks,
Navigation.routeNames.Notes,
Navigation.routeNames.Trash,
Navigation.routeNames.NotesPage,
Navigation.routeNames.Notebook,
Navigation.routeNames.Trash,
]);
updateEvent({type: Actions.COLORS});
updateEvent({type: Actions.MENU_PINS});
ToastEvent.hide();
@@ -74,13 +86,12 @@ export const deleteItems = async (item) => {
'Undo',
);
}
updateEvent({type: Actions.TRASH});
Navigation.setRoutesToUpdate([Navigation.routeNames.Trash]);
updateEvent({type: Actions.CLEAR_SELECTION});
updateEvent({type: Actions.COLORS});
updateEvent({type: Actions.SELECTION_MODE, enabled: false});
};
export const openLinkInBrowser = async (link, colors) => {
try {
const url = link;
@@ -103,10 +114,9 @@ export const openLinkInBrowser = async (link, colors) => {
enableUrlBarHiding: true,
enableDefaultShare: true,
forceCloseOnRedirection: false,
});
} else Linking.openURL(url);
} catch (error) {
console.log(error.message);
}
}
};

View File

@@ -190,7 +190,7 @@ export const BUTTON_TYPES = {
gray: {
primary: 'transparent',
text: 'icon',
selected: 'nav',
selected: 'transGray',
},
grayBg: {
primary: 'nav',

View File

@@ -126,7 +126,7 @@ const EditorOverlay = () => {
setError(false);
eSendEvent('webviewreset');
}}
title="Taking too long? Reload Editor"
title="Taking too long? Reload editor"
/>
<Paragraph
textBreakStrategy="balanced"

View File

@@ -65,7 +65,7 @@ export const EditorSettings = () => {
<BaseDialog visible={true}>
<DialogContainer>
<DialogHeader
title="Save Preset"
title="Save preset"
paragraph="Give this preset a name."
/>
<Input placeholder="Preset name" />
@@ -79,7 +79,7 @@ export const EditorSettings = () => {
)}
<DialogHeader
title="Editor Settings"
title="Editor settings"
paragraph="Modify editor settings based on personal preference."
button={{
title: 'Save as Preset',

View File

@@ -66,7 +66,7 @@ export const EditorTitle = () => {
maxWidth: '100%',
padding: 0,
}}
placeholder="Title Here"
placeholder="Note title"
onChangeText={(text) => {
setTitle(text);
_onMessage({