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 premium handler to export dialog
ammarahm-ed7d3bb70e40ef
diff --git a/apps/mobile/src/components/ActionSheetComponent/GetPremium.js b/apps/mobile/src/components/ActionSheetComponent/GetPremium.jsindex 0584b55e8..d37536921 100644--- a/apps/mobile/src/components/ActionSheetComponent/GetPremium.js+++ b/apps/mobile/src/components/ActionSheetComponent/GetPremium.js@@ -8,7 +8,7 @@ import {} from '../../services/EventManager';import {getElevation} from '../../utils';import {eOpenPremiumDialog, eShowGetPremium} from '../../utils/Events';-import { SIZE } from '../../utils/SizeUtils';+import {SIZE} from '../../utils/SizeUtils';import {sleep} from '../../utils/TimeUtils';import {Button} from '../Button';import Heading from '../Typography/Heading';@@ -16,7 +16,7 @@ import Paragraph from '../Typography/Paragraph';const translate = new Animated.Value(-800);-export const GetPremium = ({close, context = 'global',offset=0}) => {+export const GetPremium = ({close, context = 'global', offset = 0}) => {const [state, dispatch] = useTracked();const {colors} = state;const [msg, setMsg] = useState({@@ -66,18 +66,23 @@ export const GetPremium = ({close, context = 'global',offset=0}) => {borderRadius: 5,flexDirection: 'row',alignSelf: 'center',- justifyContent: 'space-between',- top:offset,+ justifyContent: 'space-between',+ top: offset,transform: [{translateX: translate,},],}}>- <Heading size={SIZE.md} color="white" style={{maxWidth: '75%', paddingRight: 6}}>+ <Heading+ size={SIZE.md}+ color="white"+ style={{maxWidth: '75%', paddingRight: 6}}>{msg.title}{'\n'}- <Paragraph color="white">{msg.desc}</Paragraph>+ <Paragraph size={SIZE.sm} color="white">+ {msg.desc}+ </Paragraph></Heading><Buttondiff --git a/apps/mobile/src/components/ExportDialog/index.js b/apps/mobile/src/components/ExportDialog/index.jsindex f5285d2a6..8234f8cf6 100644--- a/apps/mobile/src/components/ExportDialog/index.js+++ b/apps/mobile/src/components/ExportDialog/index.js@@ -1,27 +1,21 @@import React, {Fragment, useEffect, useState} from 'react';-import {- Modal,- Platform,- StyleSheet,- Text,- TouchableOpacity,- View,-} from 'react-native';+import {Platform, StyleSheet, TouchableOpacity, View} from 'react-native';import FileViewer from 'react-native-file-viewer';import Icon from 'react-native-vector-icons/MaterialCommunityIcons';-import RNFetchBlob from 'rn-fetch-blob';import {useTracked} from '../../provider';-import storage from '../../utils/storage';+import {DDS} from '../../services/DeviceDetection';+import {eSendEvent, ToastEvent} from '../../services/EventManager';+import Exporter from '../../services/Exporter';+import PremiumService from '../../services/PremiumService';import {getElevation} from '../../utils';+import {ph, pv, SIZE, WEIGHT} from '../../utils/SizeUtils';+import {sleep} from '../../utils/TimeUtils';+import {GetPremium} from '../ActionSheetComponent/GetPremium';import {Button} from '../Button/index';import BaseDialog from '../Dialog/base-dialog';import DialogHeader from '../Dialog/dialog-header';import {Loading} from '../Loading';import Seperator from '../Seperator';-import {sleep} from '../../utils/TimeUtils';-import {ToastEvent} from '../../services/EventManager';-import {opacity, ph, pv, SIZE, WEIGHT} from '../../utils/SizeUtils';-import {DDS} from '../../services/DeviceDetection';import Heading from '../Typography/Heading';import Paragraph from '../Typography/Paragraph';@@ -29,7 +23,11 @@ const {eSubscribeEvent,eUnSubscribeEvent,} = require('../../services/EventManager');-const {eOpenExportDialog, eCloseExportDialog} = require('../../utils/Events');+const {+ eOpenExportDialog,+ eCloseExportDialog,+ eShowGetPremium,+} = require('../../utils/Events');const ExportDialog = () => {const [state] = useTracked();@@ -89,7 +87,19 @@ const ExportDialog = () => {{title: 'PDF',func: async () => {- await save(storage.saveToPDF, 'PDF');+ await PremiumService.verify(+ async () => {+ await save(Exporter.saveToPDF, 'PDF');+ },+ () => {+ eSendEvent(eShowGetPremium, {+ context: 'export',+ title: 'Get Notesnook Pro',+ desc:+ 'With Notesnook Pro you will be able to export your note in PDF, Markdown and HTML formats! Get it today.',+ });+ },+ );},icon: 'file-pdf-box',desc: 'Most commonly used, opens on any device.',@@ -97,7 +107,19 @@ const ExportDialog = () => {{title: 'Markdown',func: async () => {- await save(storage.saveToMarkdown, 'Markdown');+ await PremiumService.verify(+ async () => {+ await save(Exporter.saveToMarkdown, 'Markdown');+ },+ () => {+ eSendEvent(eShowGetPremium, {+ context: 'export',+ title: 'Get Notesnook Pro',+ desc:+ 'With Notesnook Pro you will be able to export your note in PDF, Markdown and HTML formats! Get it today.',+ });+ },+ );},icon: 'language-markdown',desc: 'Most commonly used, opens on any device.',@@ -105,7 +127,7 @@ const ExportDialog = () => {{title: 'Plain Text',func: async () => {- await save(storage.saveToText, 'Text');+ await save(Exporter.saveToText, 'Text');},icon: 'card-text',desc: 'A plain text file with no formatting.',@@ -113,7 +135,19 @@ const ExportDialog = () => {{title: 'HTML',func: async () => {- await save(storage.saveToHTML, 'Html');+ await PremiumService.verify(+ async () => {+ await save(Exporter.saveToHTML, 'Html');+ },+ () => {+ eSendEvent(eShowGetPremium, {+ context: 'export',+ title: 'Get Notesnook Pro',+ desc:+ 'With Notesnook Pro you will be able to export your note in PDF, Markdown and HTML formats! Get it today.',+ });+ },+ );},icon: 'language-html5',desc: 'A file that can be opened in a browser.',@@ -130,6 +164,7 @@ const ExportDialog = () => {},styles.container,]}>+ <GetPremium context="export" offset={-100} close={close} /><DialogHeadericon="export"title="Export Note"@@ -174,14 +209,24 @@ const ExportDialog = () => {width: '100%',alignItems: 'center',flexDirection: 'row',- paddingHorizontal: 12,+ paddingRight: 12,paddingVertical: 10,}}>- <Icon- name={item.icon}- color={colors.accent}- size={SIZE.lg}- />+ <View+ style={{+ backgroundColor: colors.shade,+ borderRadius: 5,+ height: 40,+ width: 40,+ justifyContent: 'center',+ alignItems: 'center',+ }}>+ <Icon+ name={item.icon}+ color={colors.accent}+ size={SIZE.xxxl}+ />+ </View><Headingstyle={{marginLeft: 5, maxWidth: '90%'}}size={SIZE.md}>diff --git a/apps/mobile/src/services/Exporter.js b/apps/mobile/src/services/Exporter.jsindex ea18bd04f..b916cb556 100644--- a/apps/mobile/src/services/Exporter.js+++ b/apps/mobile/src/services/Exporter.js@@ -1,79 +1,83 @@-import {Platform} from "react-native";-import {db} from "../utils/DB";-import RNFetchBlob from "rn-fetch-blob";-import {ToastEvent} from "./EventManager";-import he from "he";-import RNHTMLtoPDF from "react-native-html-to-pdf";-import Storage from "../utils/Storage";+import {Platform} from 'react-native';+import {db} from '../utils/DB';+import RNFetchBlob from 'rn-fetch-blob';+import {ToastEvent} from './EventManager';+import he from 'he';+import RNHTMLtoPDF from 'react-native-html-to-pdf';+import Storage from '../utils/storage';-export async function saveToPDF(note) {- let androidSavePath = '/Notesnook/exported/PDF';- if (Platform.OS === 'android') {- let hasPermission = await Storage.requestPermission();- if (!hasPermission) {- ToastEvent.show('Failed to get storage permission');- return null;- }- }-- await Storage.checkAndCreateDir ('/exported/PDF/');- let html = await db.notes.note(note).export('html');+async function saveToPDF(note) {+ let androidSavePath = '/Notesnook/exported/PDF';+ if (Platform.OS === 'android') {+ let hasPermission = await Storage.requestPermission();+ if (!hasPermission) {+ ToastEvent.show('Failed to get storage permission');+ return null;+ }+ }- html = he.decode(html);- let options = {- html: html,- fileName:- Platform.OS === 'ios' ? '/exported/PDF/' + note.title : note.title,- directory: Platform.OS === 'ios' ? 'Documents' : androidSavePath,- };- let res = await RNHTMLtoPDF.convert(options);+ await Storage.checkAndCreateDir('/exported/PDF/');+ let html = await db.notes.note(note).export('html');- return {- filePath: res.filePath,- type: 'application/pdf',- name: 'PDF',- };+ html = he.decode(html);+ let options = {+ html: html,+ fileName:+ Platform.OS === 'ios' ? '/exported/PDF/' + note.title : note.title,+ directory: Platform.OS === 'ios' ? 'Documents' : androidSavePath,+ };+ let res = await RNHTMLtoPDF.convert(options);++ return {+ filePath: res.filePath,+ type: 'application/pdf',+ name: 'PDF',+ };}-export async function saveToMarkdown(note) {-- let path = await Storage.checkAndCreateDir('/exported/Markdown/');- let markdown = await db.notes.note(note.id).export('md');+async function saveToMarkdown(note) {+ let path = await Storage.checkAndCreateDir('/exported/Markdown/');+ let markdown = await db.notes.note(note.id).export('md');- path = path + note.title + '.md';- await RNFetchBlob.fs.writeFile(path, markdown, 'utf8');+ path = path + note.title + '.md';+ await RNFetchBlob.fs.writeFile(path, markdown, 'utf8');- return {- filePath: path,- type: 'text/markdown',- name: 'Markdown',- };+ return {+ filePath: path,+ type: 'text/markdown',+ name: 'Markdown',+ };}-export async function saveToText(note) {-- let path = await Storage.checkAndCreateDir('/exported/Text/');- let markdown = await db.notes.note(note.id).export('txt');- path = path + note.title + '.txt';- await RNFetchBlob.fs.writeFile(path, markdown, 'utf8');+async function saveToText(note) {+ let path = await Storage.checkAndCreateDir('/exported/Text/');+ let markdown = await db.notes.note(note.id).export('txt');+ path = path + note.title + '.txt';+ await RNFetchBlob.fs.writeFile(path, markdown, 'utf8');- return {- filePath: path,- type: 'text/plain',- name: 'Text',- };+ return {+ filePath: path,+ type: 'text/plain',+ name: 'Text',+ };}-export async function saveToHTML(note) {-- let path = await Storage.checkAndCreateDir('/exported/Html/');- let markdown = await db.notes.note(note.id).export('html');- path = path + note.title + '.html';- await RNFetchBlob.fs.writeFile(path, markdown, 'utf8');+async function saveToHTML(note) {+ let path = await Storage.checkAndCreateDir('/exported/Html/');+ let markdown = await db.notes.note(note.id).export('html');+ path = path + note.title + '.html';+ await RNFetchBlob.fs.writeFile(path, markdown, 'utf8');++ return {+ filePath: path,+ type: 'text/html',+ name: 'Html',+ };+}- return {- filePath: path,- type: 'text/html',- name: 'Html',- };-}\ No newline at end of file+export default {+ saveToHTML,+ saveToText,+ saveToMarkdown,+ saveToPDF,+};