Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

open all file types

ammarahm-edfacac9343ea0
diff --git a/apps/mobile/src/components/ExportDialog/index.js b/apps/mobile/src/components/ExportDialog/index.js
index 232d4e6fe..cc0422ee9 100644
--- a/apps/mobile/src/components/ExportDialog/index.js
+++ b/apps/mobile/src/components/ExportDialog/index.js
@@ -12,6 +12,7 @@ import {opacity, ph, pv, SIZE, WEIGHT} from '../../common/common';
import {useTracked} from '../../provider';
import {DDS, getElevation, db, ToastEvent} from '../../utils/utils';
import {Loading} from '../Loading';
+import FileViewer from 'react-native-file-viewer';
const {
eSubscribeEvent,
@@ -57,7 +58,7 @@ const ExportDialog = () => {
setNotes([]);
};
- const save = async (func, mime, name) => {
+ const save = async (func, name) => {
setExporting(true);
let res;
for (var i = 0; i < notes.length; i++) {
@@ -75,10 +76,8 @@ const ExportDialog = () => {
: `Storage/Notesnook/exported/${name}`
}.`,
);
- let fileData = {...res};
- fileData.type = mime;
- fileData.name = name;
- setResult(fileData);
+
+ setResult(res);
setComplete(true);
};
@@ -86,28 +85,28 @@ const ExportDialog = () => {
{
title: 'PDF',
func: async () => {
- await save(storage.saveToPDF, 'application/pdf', 'PDF');
+ await save(storage.saveToPDF, 'PDF');
},
icon: 'file-pdf-box',
},
{
title: 'Markdown',
func: async () => {
- await save(storage.saveToMarkdown, 'text/markdown', 'Markdown');
+ await save(storage.saveToMarkdown, 'Markdown');
},
icon: 'language-markdown',
},
{
title: 'Plain Text',
func: async () => {
- await save(storage.saveToText, 'text/plain', 'Text');
+ await save(storage.saveToText, 'Text');
},
icon: 'card-text',
},
{
title: 'HTML',
func: async () => {
- await save(storage.saveToHTML, 'text/html', 'Html');
+ await save(storage.saveToHTML, 'Html');
},
icon: 'language-html5',
},
@@ -147,17 +146,19 @@ const ExportDialog = () => {
done={complete}
doneText={doneText}
onDone={() => {
- RNFetchBlob.android
- .actionViewIntent(result.filePath, result.type)
- .catch((e) => {
- console.log(e);
- ToastEvent.show(
- `No application found to open ${result.name} file`,
- );
- });
+ console.log(result.type,result.filePath);
+ FileViewer.open(result.filePath, {
+ showOpenWithDialog: true,
+ showAppsSuggestions: true,
+ }).catch((e) => {
+ console.log(e);
+ ToastEvent.show(
+ `No application found to open ${result.name} file`,
+ );
+ });
close();
}}
- tagline="Exporting notes..."
+ tagline="Exporting notes"
/>
) : (
<>
diff --git a/apps/mobile/src/utils/storage.js b/apps/mobile/src/utils/storage.js
index 44e46e6fa..dbbda942b 100644
--- a/apps/mobile/src/utils/storage.js
+++ b/apps/mobile/src/utils/storage.js
@@ -1,14 +1,14 @@
-import 'react-native-get-random-values';
-import {isArray} from 'lodash';
+import he from 'he';
import {Platform} from 'react-native';
+import 'react-native-get-random-values';
import RNHTMLtoPDF from 'react-native-html-to-pdf';
import MMKVStorage from 'react-native-mmkv-storage';
+import {and} from 'react-native-reanimated';
import {generateSecureRandom} from 'react-native-securerandom';
import Sodium from 'react-native-sodium';
import RNFetchBlob from 'rn-fetch-blob';
import {db, requestStoragePermission, ToastEvent} from './utils';
export const MMKV = new MMKVStorage.Loader().initialize();
-import he from 'he';
async function read(key, isArray = false) {
let data;
@@ -103,7 +103,62 @@ async function saveToPDF(note) {
fileName: note.title,
directory: Platform.OS === 'ios' ? 'Documents' : androidSavePath,
};
- return await RNHTMLtoPDF.convert(options);
+ let res = await RNHTMLtoPDF.convert(options);
+
+ return {
+ filePath: res.filePath,
+ type: 'application/pdf',
+ name: 'Markdown',
+ };
+}
+
+async function saveToMarkdown(note) {
+ let androidSavePath =
+ RNFetchBlob.fs.dirs.SDCardDir + '/Notesnook/exported/Markdown/';
+ await checkAndCreateDir(androidSavePath);
+ let markdown = await db.notes.note(note.id).export('md');
+ console.log(markdown);
+ let path = androidSavePath + note.title + '.md';
+ await RNFetchBlob.fs.writeFile(path, markdown, 'utf8');
+
+ return {
+ filePath: path,
+ type: 'text/markdown',
+ name: 'Markdown',
+ };
+}
+
+async function saveToText(note) {
+ let androidSavePath =
+ RNFetchBlob.fs.dirs.SDCardDir + '/Notesnook/exported/Text/';
+ await checkAndCreateDir(androidSavePath);
+ let markdown = await db.notes.note(note.id).export('txt');
+ console.log(markdown);
+
+ let path = androidSavePath + note.title + '.txt';
+ await RNFetchBlob.fs.writeFile(path, markdown, 'utf8');
+
+ return {
+ filePath: path,
+ type: 'text/plain',
+ name: 'Text',
+ };
+}
+
+async function saveToHTML(note) {
+ let androidSavePath =
+ RNFetchBlob.fs.dirs.SDCardDir + '/Notesnook/exported/Html/';
+ await checkAndCreateDir(androidSavePath);
+ let markdown = await db.notes.note(note.id).export('html');
+ console.log(markdown);
+ let path = androidSavePath + note.title + '.html';
+ await RNFetchBlob.fs.writeFile(path, markdown, 'utf8');
+
+ return {
+ filePath: path,
+ type: 'text/html',
+ name: 'Html',
+ };
}
async function checkAndCreateDir(dir) {
@@ -129,4 +184,7 @@ export default {
getAllKeys,
getRandomBytes,
checkAndCreateDir,
+ saveToMarkdown,
+ saveToText,
+ saveToHTML,
};