utilise db premium user checking events

This commit is contained in:
ammarahm-ed
2020-12-06 09:53:50 +05:00
parent ca00cbc161
commit f138c754d1
8 changed files with 63 additions and 129 deletions

View File

@@ -1,7 +1,7 @@
import React, {useState} from 'react'; import React, {useState} from 'react';
import {View} from 'react-native'; import {View} from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import { notesnook } from '../../../e2e/test.ids'; import {notesnook} from '../../../e2e/test.ids';
import {useTracked} from '../../provider'; import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions'; import {Actions} from '../../provider/Actions';
import {DDS} from '../../services/DeviceDetection'; import {DDS} from '../../services/DeviceDetection';
@@ -11,12 +11,12 @@ import {dWidth} from '../../utils';
import {COLORS_NOTE} from '../../utils/Colors'; import {COLORS_NOTE} from '../../utils/Colors';
import {hexToRGBA, RGB_Linear_Shade} from '../../utils/ColorUtils'; import {hexToRGBA, RGB_Linear_Shade} from '../../utils/ColorUtils';
import {db} from '../../utils/DB'; import {db} from '../../utils/DB';
import { eShowGetPremium } from '../../utils/Events'; import {eShowGetPremium} from '../../utils/Events';
import {SIZE} from '../../utils/SizeUtils'; import {SIZE} from '../../utils/SizeUtils';
import { sleep } from '../../utils/TimeUtils'; import {sleep} from '../../utils/TimeUtils';
import {PressableButton} from '../PressableButton'; import {PressableButton} from '../PressableButton';
export const ActionSheetColorsSection = ({item,close}) => { export const ActionSheetColorsSection = ({item, close}) => {
const [state, dispatch] = useTracked(); const [state, dispatch] = useTracked();
const {colors} = state; const {colors} = state;
const [note, setNote] = useState(item); const [note, setNote] = useState(item);
@@ -49,23 +49,15 @@ export const ActionSheetColorsSection = ({item,close}) => {
testID={notesnook.ids.dialogs.actionsheet.color(c)} testID={notesnook.ids.dialogs.actionsheet.color(c)}
key={color.value} key={color.value}
onPress={async () => { onPress={async () => {
await PremiumService.verify(async () => { let noteColors = note.colors;
let noteColors = note.colors; if (noteColors.includes(color.name)) {
if (noteColors.includes(color.name)) { await db.notes.note(note.id).uncolor(color.name);
await db.notes.note(note.id).uncolor(color.name); } else {
} else { await db.notes.note(note.id).color(color.name);
await db.notes.note(note.id).color(color.name); }
} dispatch({type: Actions.COLORS});
dispatch({type: Actions.COLORS}); sendNoteEditedEvent(note.id, false, true);
sendNoteEditedEvent(note.id, false, true); localRefresh();
localRefresh();
},() => {
eSendEvent(eShowGetPremium,{
context:'sheet',
title:'Get Notesnook Pro',
desc:'To assign color to a note get Notesnook Pro today.'
})
});
}} }}
customStyle={{ customStyle={{
width: DDS.isTab ? 400 / 10 : dWidth / 10, width: DDS.isTab ? 400 / 10 : dWidth / 10,

View File

@@ -73,22 +73,7 @@ export const ActionSheetTagsSection = ({item, close}) => {
ToastEvent.show(e.message, 'error', 'local'); ToastEvent.show(e.message, 'error', 'local');
} }
} }
if (
tags.length >= 5 &&
tags.findIndex((t) => t.title === tagToAdd) === -1
) {
await PremiumService.verify(add, () => {
eSendEvent(eShowGetPremium, {
context: 'sheet',
title: 'Get Notesnook Pro',
desc: 'To create more tags for your notes become a Pro user today.',
});
});
return;
}
await add(); await add();
}); });

View File

@@ -8,7 +8,7 @@ import {
} from 'react-native'; } from 'react-native';
import Share from 'react-native-share'; import Share from 'react-native-share';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import { notesnook } from '../../../e2e/test.ids'; import {notesnook} from '../../../e2e/test.ids';
import {useTracked} from '../../provider'; import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions'; import {Actions} from '../../provider/Actions';
import {DDS} from '../../services/DeviceDetection'; import {DDS} from '../../services/DeviceDetection';
@@ -254,7 +254,7 @@ export const ActionSheetComponent = ({
on: colors.night ? true : false, on: colors.night ? true : false,
close: false, close: false,
nopremium: true, nopremium: true,
id:notesnook.ids.dialogs.actionsheet.night id: notesnook.ids.dialogs.actionsheet.night,
}, },
{ {
name: 'Pin', name: 'Pin',
@@ -296,7 +296,7 @@ export const ActionSheetComponent = ({
close: false, close: false,
check: true, check: true,
on: note.pinned, on: note.pinned,
id:notesnook.ids.dialogs.actionsheet.pin id: notesnook.ids.dialogs.actionsheet.pin,
}, },
{ {
name: 'Favorite', name: 'Favorite',
@@ -315,7 +315,7 @@ export const ActionSheetComponent = ({
close: false, close: false,
check: true, check: true,
on: note.favorite, on: note.favorite,
id:notesnook.ids.dialogs.actionsheet.favorite id: notesnook.ids.dialogs.actionsheet.favorite,
}, },
{ {
name: isPinnedToMenu ? 'Unpin from Menu' : 'Pin to Menu', name: isPinnedToMenu ? 'Unpin from Menu' : 'Pin to Menu',
@@ -341,7 +341,7 @@ export const ActionSheetComponent = ({
close: false, close: false,
check: true, check: true,
on: isPinnedToMenu, on: isPinnedToMenu,
id:notesnook.ids.dialogs.actionsheet.pinMenu id: notesnook.ids.dialogs.actionsheet.pinMenu,
}, },
]; ];
@@ -476,43 +476,32 @@ export const ActionSheetComponent = ({
}; };
const onPressVaultButton = async () => { const onPressVaultButton = async () => {
await PremiumService.verify( if (!note.id) return;
() => { if (note.locked) {
if (!note.id) return; close('unlock');
} else {
if (note.locked) { db.vault
close('unlock'); .add(note.id)
} else { .then(() => {
db.vault sendNoteEditedEvent(note.id, false, true);
.add(note.id) if (note.locked && PremiumService.get()) {
.then(() => { close();
sendNoteEditedEvent(note.id, false, true); }
})
.catch(async (e) => {
switch (e.message) {
case db.vault.ERRORS.noVault:
close('novault');
break;
case db.vault.ERRORS.vaultLocked:
close('locked');
break;
case db.vault.ERRORS.wrongPassword:
close(); close();
}) break;
.catch(async (e) => { }
switch (e.message) {
case db.vault.ERRORS.noVault:
close('novault');
break;
case db.vault.ERRORS.vaultLocked:
close('locked');
break;
case db.vault.ERRORS.wrongPassword:
close();
break;
}
});
}
},
() => {
eSendEvent(eShowGetPremium, {
context: 'sheet',
title: 'Add Notes to Vault',
desc:
'With Notesnook Pro you can add notes to your vault and do so much more! Get it now.',
}); });
}, }
);
}; };
return ( return (

View File

@@ -11,13 +11,15 @@ import {
} from 'react-native'; } from 'react-native';
import {FlatList, TextInput} from 'react-native-gesture-handler'; import {FlatList, TextInput} from 'react-native-gesture-handler';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import { notesnook } from '../../../e2e/test.ids'; import {notesnook} from '../../../e2e/test.ids';
import {Actions} from '../../provider/Actions'; import {Actions} from '../../provider/Actions';
import {DDS} from '../../services/DeviceDetection'; import {DDS} from '../../services/DeviceDetection';
import {ToastEvent} from '../../services/EventManager'; import {eSendEvent, ToastEvent} from '../../services/EventManager';
import {db} from '../../utils/DB'; import {db} from '../../utils/DB';
import {eShowGetPremium} from '../../utils/Events';
import {ph, pv, SIZE, WEIGHT} from '../../utils/SizeUtils'; import {ph, pv, SIZE, WEIGHT} from '../../utils/SizeUtils';
import {ActionIcon} from '../ActionIcon'; import {ActionIcon} from '../ActionIcon';
import {GetPremium} from '../ActionSheetComponent/GetPremium';
import DialogButtons from '../Dialog/dialog-buttons'; import DialogButtons from '../Dialog/dialog-buttons';
import DialogHeader from '../Dialog/dialog-header'; import DialogHeader from '../Dialog/dialog-header';
import {updateEvent} from '../DialogManager/recievers'; import {updateEvent} from '../DialogManager/recievers';
@@ -185,8 +187,6 @@ export class AddNotebookDialog extends React.Component {
this.close(); this.close();
updateEvent({type: Actions.NOTEBOOKS}); updateEvent({type: Actions.NOTEBOOKS});
updateEvent({type: Actions.PINNED}); updateEvent({type: Actions.PINNED});
//ToastEvent.show('New notebook added', 'success', 'local');
}; };
onSubmit = (forward = true) => { onSubmit = (forward = true) => {
@@ -441,7 +441,6 @@ export class AddNotebookDialog extends React.Component {
<DialogButtons <DialogButtons
negativeTitle="Cancel" negativeTitle="Cancel"
positiveTitle={toEdit && toEdit.dateCreated ? 'Save' : 'Add'} positiveTitle={toEdit && toEdit.dateCreated ? 'Save' : 'Add'}
onPressPositive={this.addNewNotebook} onPressPositive={this.addNewNotebook}
onPressNegative={this.close} onPressNegative={this.close}
/> />

View File

@@ -3,7 +3,7 @@ import {Platform, StyleSheet, TouchableOpacity, View} from 'react-native';
import FileViewer from 'react-native-file-viewer'; import FileViewer from 'react-native-file-viewer';
import {exp} from 'react-native-reanimated'; import {exp} from 'react-native-reanimated';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import { notesnook } from '../../../e2e/test.ids'; import {notesnook} from '../../../e2e/test.ids';
import {useTracked} from '../../provider'; import {useTracked} from '../../provider';
import {DDS} from '../../services/DeviceDetection'; import {DDS} from '../../services/DeviceDetection';
import {eSendEvent, ToastEvent} from '../../services/EventManager'; import {eSendEvent, ToastEvent} from '../../services/EventManager';
@@ -91,44 +91,20 @@ const ExportDialog = () => {
{ {
title: 'PDF', title: 'PDF',
func: async () => { func: async () => {
await PremiumService.verify( await save(Exporter.saveToPDF, 'PDF');
async () => {
await save(Exporter.saveToPDF, 'PDF');
},
() => {
eSendEvent(eShowGetPremium, {
context: 'export',
title: 'Export in PDF, MD & HTML',
desc:
'Get Notesnook Pro to export your notes in PDF, Markdown and HTML formats!',
});
},
);
}, },
icon: 'file-pdf-box', icon: 'file-pdf-box',
desc: 'Most commonly used, opens on any device.', desc: 'Most commonly used, opens on any device.',
id:notesnook.ids.dialogs.export.pdf id: notesnook.ids.dialogs.export.pdf,
}, },
{ {
title: 'Markdown', title: 'Markdown',
func: async () => { func: async () => {
await PremiumService.verify( await save(Exporter.saveToMarkdown, 'Markdown');
async () => {
await save(Exporter.saveToMarkdown, 'Markdown');
},
() => {
eSendEvent(eShowGetPremium, {
context: 'export',
title: 'Export in PDF, MD & HTML',
desc:
'Get Notesnook Pro to export your notes in PDF, Markdown and HTML formats!',
});
},
);
}, },
icon: 'language-markdown', icon: 'language-markdown',
desc: 'Most commonly used, opens on any device.', desc: 'Most commonly used, opens on any device.',
id:notesnook.ids.dialogs.export.md id: notesnook.ids.dialogs.export.md,
}, },
{ {
title: 'Plain Text', title: 'Plain Text',
@@ -137,28 +113,16 @@ const ExportDialog = () => {
}, },
icon: 'card-text', icon: 'card-text',
desc: 'A plain text file with no formatting.', desc: 'A plain text file with no formatting.',
id:notesnook.ids.dialogs.export.text id: notesnook.ids.dialogs.export.text,
}, },
{ {
title: 'HTML', title: 'HTML',
func: async () => { func: async () => {
await PremiumService.verify( await save(Exporter.saveToHTML, 'Html');
async () => {
await save(Exporter.saveToHTML, 'Html');
},
() => {
eSendEvent(eShowGetPremium, {
context: 'export',
title: 'Export in PDF, MD & HTML',
desc:
'Get Notesnook Pro to export your notes in PDF, Markdown and HTML formats!',
});
},
);
}, },
icon: 'language-html5', icon: 'language-html5',
desc: 'A file that can be opened in a browser.', desc: 'A file that can be opened in a browser.',
id:notesnook.ids.dialogs.export.html id: notesnook.ids.dialogs.export.html,
}, },
]; ];

View File

@@ -204,7 +204,7 @@ const LoginDialog = () => {
return !visible ? null : ( return !visible ? null : (
<Modal <Modal
animated={true} animated={true}
animationType={DDS.isTab ? 'fade' : 'slide'} animationType={DDS.isLargeTablet() ? 'fade' : 'slide'}
statusBarTranslucent={true} statusBarTranslucent={true}
onRequestClose={close} onRequestClose={close}
visible={true} visible={true}

View File

@@ -10,7 +10,7 @@ function getIntent() {
try { try {
if (isIos) { if (isIos) {
initialUrlIOS = await Linking.getInitialURL(); initialUrlIOS = await Linking.getInitialURL();
if (res && res.startsWith('ShareMedia://dataUrl')) { if (initialUrlIOS && initialUrlIOS.startsWith('ShareMedia://dataUrl')) {
_data = await ReceiveSharingIntent.getFileNames(initialUrlIOS.url); _data = await ReceiveSharingIntent.getFileNames(initialUrlIOS.url);
} else { } else {
reject('unsupported url'); reject('unsupported url');

View File

@@ -17,6 +17,10 @@ async function setPremiumStatus(status) {
} }
} }
function get() {
return premiumStatus && premiumStatus !== 0 && premiumStatus !== 4
}
async function verify(callback,error) { async function verify(callback,error) {
try { try {
let user = await db.user.get(); let user = await db.user.get();
@@ -40,5 +44,6 @@ async function verify(callback,error) {
export default { export default {
verify, verify,
setPremiumStatus setPremiumStatus,
get
}; };