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

View File

@@ -73,22 +73,7 @@ export const ActionSheetTagsSection = ({item, close}) => {
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();
});

View File

@@ -8,7 +8,7 @@ import {
} from 'react-native';
import Share from 'react-native-share';
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 {Actions} from '../../provider/Actions';
import {DDS} from '../../services/DeviceDetection';
@@ -254,7 +254,7 @@ export const ActionSheetComponent = ({
on: colors.night ? true : false,
close: false,
nopremium: true,
id:notesnook.ids.dialogs.actionsheet.night
id: notesnook.ids.dialogs.actionsheet.night,
},
{
name: 'Pin',
@@ -296,7 +296,7 @@ export const ActionSheetComponent = ({
close: false,
check: true,
on: note.pinned,
id:notesnook.ids.dialogs.actionsheet.pin
id: notesnook.ids.dialogs.actionsheet.pin,
},
{
name: 'Favorite',
@@ -315,7 +315,7 @@ export const ActionSheetComponent = ({
close: false,
check: true,
on: note.favorite,
id:notesnook.ids.dialogs.actionsheet.favorite
id: notesnook.ids.dialogs.actionsheet.favorite,
},
{
name: isPinnedToMenu ? 'Unpin from Menu' : 'Pin to Menu',
@@ -341,7 +341,7 @@ export const ActionSheetComponent = ({
close: false,
check: true,
on: isPinnedToMenu,
id:notesnook.ids.dialogs.actionsheet.pinMenu
id: notesnook.ids.dialogs.actionsheet.pinMenu,
},
];
@@ -476,43 +476,32 @@ export const ActionSheetComponent = ({
};
const onPressVaultButton = async () => {
await PremiumService.verify(
() => {
if (!note.id) return;
if (note.locked) {
close('unlock');
} else {
db.vault
.add(note.id)
.then(() => {
sendNoteEditedEvent(note.id, false, true);
if (!note.id) return;
if (note.locked) {
close('unlock');
} else {
db.vault
.add(note.id)
.then(() => {
sendNoteEditedEvent(note.id, false, true);
if (note.locked && PremiumService.get()) {
close();
}
})
.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();
})
.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.',
break;
}
});
},
);
}
};
return (

View File

@@ -11,13 +11,15 @@ import {
} from 'react-native';
import {FlatList, TextInput} from 'react-native-gesture-handler';
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 {DDS} from '../../services/DeviceDetection';
import {ToastEvent} from '../../services/EventManager';
import {eSendEvent, ToastEvent} from '../../services/EventManager';
import {db} from '../../utils/DB';
import {eShowGetPremium} from '../../utils/Events';
import {ph, pv, SIZE, WEIGHT} from '../../utils/SizeUtils';
import {ActionIcon} from '../ActionIcon';
import {GetPremium} from '../ActionSheetComponent/GetPremium';
import DialogButtons from '../Dialog/dialog-buttons';
import DialogHeader from '../Dialog/dialog-header';
import {updateEvent} from '../DialogManager/recievers';
@@ -185,8 +187,6 @@ export class AddNotebookDialog extends React.Component {
this.close();
updateEvent({type: Actions.NOTEBOOKS});
updateEvent({type: Actions.PINNED});
//ToastEvent.show('New notebook added', 'success', 'local');
};
onSubmit = (forward = true) => {
@@ -441,7 +441,6 @@ export class AddNotebookDialog extends React.Component {
<DialogButtons
negativeTitle="Cancel"
positiveTitle={toEdit && toEdit.dateCreated ? 'Save' : 'Add'}
onPressPositive={this.addNewNotebook}
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 {exp} from 'react-native-reanimated';
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 {DDS} from '../../services/DeviceDetection';
import {eSendEvent, ToastEvent} from '../../services/EventManager';
@@ -91,44 +91,20 @@ const ExportDialog = () => {
{
title: 'PDF',
func: async () => {
await PremiumService.verify(
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!',
});
},
);
await save(Exporter.saveToPDF, 'PDF');
},
icon: 'file-pdf-box',
desc: 'Most commonly used, opens on any device.',
id:notesnook.ids.dialogs.export.pdf
id: notesnook.ids.dialogs.export.pdf,
},
{
title: 'Markdown',
func: async () => {
await PremiumService.verify(
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!',
});
},
);
await save(Exporter.saveToMarkdown, 'Markdown');
},
icon: 'language-markdown',
desc: 'Most commonly used, opens on any device.',
id:notesnook.ids.dialogs.export.md
id: notesnook.ids.dialogs.export.md,
},
{
title: 'Plain Text',
@@ -137,28 +113,16 @@ const ExportDialog = () => {
},
icon: 'card-text',
desc: 'A plain text file with no formatting.',
id:notesnook.ids.dialogs.export.text
id: notesnook.ids.dialogs.export.text,
},
{
title: 'HTML',
func: async () => {
await PremiumService.verify(
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!',
});
},
);
await save(Exporter.saveToHTML, 'Html');
},
icon: 'language-html5',
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 : (
<Modal
animated={true}
animationType={DDS.isTab ? 'fade' : 'slide'}
animationType={DDS.isLargeTablet() ? 'fade' : 'slide'}
statusBarTranslucent={true}
onRequestClose={close}
visible={true}

View File

@@ -10,7 +10,7 @@ function getIntent() {
try {
if (isIos) {
initialUrlIOS = await Linking.getInitialURL();
if (res && res.startsWith('ShareMedia://dataUrl')) {
if (initialUrlIOS && initialUrlIOS.startsWith('ShareMedia://dataUrl')) {
_data = await ReceiveSharingIntent.getFileNames(initialUrlIOS.url);
} else {
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) {
try {
let user = await db.user.get();
@@ -40,5 +44,6 @@ async function verify(callback,error) {
export default {
verify,
setPremiumStatus
setPremiumStatus,
get
};