Skip to content

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

mobile: fix exporter

ammarahm-ed8df4b26f5b76
diff --git a/apps/mobile/app/components/sheets/export-notes/index.js b/apps/mobile/app/components/sheets/export-notes/index.js
index 34c79d6c6..6d97ec010 100644
--- a/apps/mobile/app/components/sheets/export-notes/index.js
+++ b/apps/mobile/app/components/sheets/export-notes/index.js
@@ -17,60 +17,30 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import React, { Fragment, useEffect, useRef, useState } from "react";
+import React, { Fragment, useState } from "react";
import { Platform, StyleSheet, View } from "react-native";
import FileViewer from "react-native-file-viewer";
import Share from "react-native-share";
import Icon from "react-native-vector-icons/MaterialCommunityIcons";
import { notesnook } from "../../../../e2e/test.ids";
-import {
- eSubscribeEvent,
- eUnSubscribeEvent,
- ToastEvent
-} from "../../../services/event-manager";
+import { presentSheet, ToastEvent } from "../../../services/event-manager";
import Exporter from "../../../services/exporter";
import { useThemeStore } from "../../../stores/use-theme-store";
import { getElevation } from "../../../utils";
-import { eCloseExportDialog, eOpenExportDialog } from "../../../utils/events";
import { ph, pv, SIZE } from "../../../utils/size";
import { sleep } from "../../../utils/time";
import DialogHeader from "../../dialog/dialog-header";
import { Button } from "../../ui/button";
import { PressableButton } from "../../ui/pressable";
import Seperator from "../../ui/seperator";
-import SheetWrapper from "../../ui/sheet";
import Heading from "../../ui/typography/heading";
import Paragraph from "../../ui/typography/paragraph";
-const ExportNotesSheet = () => {
- const colors = useThemeStore((state) => state.colors);
- const [visible, setVisible] = useState(false);
- const actionSheetRef = useRef();
- const [notes, setNotes] = useState([]);
+const ExportNotesSheet = ({ notes }) => {
+ const colors = useThemeStore((state) => state.colors);
const [exporting, setExporting] = useState(false);
const [complete, setComplete] = useState(false);
const [result, setResult] = useState({});
- useEffect(() => {
- eSubscribeEvent(eOpenExportDialog, open);
- eSubscribeEvent(eCloseExportDialog, close);
-
- return () => {
- eUnSubscribeEvent(eOpenExportDialog, open);
- eUnSubscribeEvent(eCloseExportDialog, close);
- };
- }, []);
-
- const open = (data) => {
- setVisible(true);
- setNotes(data);
- };
-
- const close = () => {
- setComplete(false);
- setExporting(false);
- setVisible(false);
- setNotes([]);
- };
const save = async (func) => {
if (exporting) return;
@@ -87,16 +57,10 @@ const ExportNotesSheet = () => {
}
setResult(res);
- setExporting(false);
setComplete(true);
+ setExporting(false);
};
- useEffect(() => {
- if (visible) {
- actionSheetRef.current.show();
- }
- }, [visible]);
-
const actions = [
{
title: "PDF",
@@ -136,155 +100,156 @@ const ExportNotesSheet = () => {
}
];
- return !visible ? null : (
- <SheetWrapper fwdRef={actionSheetRef} onClose={close} visible={true}>
- <View>
- <View
- style={{
- paddingHorizontal: 12
- }}
- >
- <DialogHeader
- icon="export"
- title="Export Note"
- paragraph={
- "All exports are saved in Notesnook/exported folder in phone storage"
- }
- />
- </View>
+ return (
+ <View>
+ <View
+ style={{
+ paddingHorizontal: 12
+ }}
+ >
+ <DialogHeader
+ icon="export"
+ title="Export Note"
+ paragraph={
+ "All exports are saved in Notesnook/exported folder in phone storage"
+ }
+ />
+ </View>
- <Seperator half />
- <View style={styles.buttonContainer}>
- {actions.map((item) => (
- <Fragment key={item.title}>
- <Seperator half />
- <PressableButton
- onPress={item.func}
- customStyle={{
- width: "100%",
- alignItems: "center",
- flexDirection: "row",
- paddingRight: 12,
- paddingVertical: 10,
- justifyContent: "flex-start",
- borderRadius: 0,
- paddingHorizontal: 12
+ <Seperator half />
+ <View style={styles.buttonContainer}>
+ {actions.map((item) => (
+ <Fragment key={item.title}>
+ <Seperator half />
+ <PressableButton
+ onPress={item.func}
+ customStyle={{
+ width: "100%",
+ alignItems: "center",
+ flexDirection: "row",
+ paddingRight: 12,
+ paddingVertical: 10,
+ justifyContent: "flex-start",
+ borderRadius: 0,
+ paddingHorizontal: 12
+ }}
+ >
+ <View
+ style={{
+ backgroundColor: colors.shade,
+ borderRadius: 5,
+ height: 60,
+ width: 60,
+ justifyContent: "center",
+ alignItems: "center"
}}
>
- <View
- style={{
- backgroundColor: colors.shade,
- borderRadius: 5,
- height: 60,
- width: 60,
- justifyContent: "center",
- alignItems: "center"
- }}
- >
- <Icon
- name={item.icon}
- color={colors.accent}
- size={SIZE.xxxl + 10}
- />
- </View>
- <View
- style={{
- flexShrink: 1
- }}
+ <Icon
+ name={item.icon}
+ color={colors.accent}
+ size={SIZE.xxxl + 10}
+ />
+ </View>
+ <View
+ style={{
+ flexShrink: 1
+ }}
+ >
+ <Heading style={{ marginLeft: 10 }} size={SIZE.md}>
+ {item.title}
+ </Heading>
+ <Paragraph
+ style={{ marginLeft: 10 }}
+ size={SIZE.sm}
+ color={colors.icon}
>
- <Heading style={{ marginLeft: 10 }} size={SIZE.md}>
- {item.title}
- </Heading>
- <Paragraph
- style={{ marginLeft: 10 }}
- size={SIZE.sm}
- color={colors.icon}
- >
- {item.desc}
- </Paragraph>
- </View>
- </PressableButton>
- </Fragment>
- ))}
+ {item.desc}
+ </Paragraph>
+ </View>
+ </PressableButton>
+ </Fragment>
+ ))}
- <View
- style={{
- width: "100%",
- paddingHorizontal: 12,
- marginTop: 10
- }}
- >
- {complete && (
- <>
- <Button
- title="Open"
- type="accent"
- width="100%"
- fontSize={SIZE.md}
- onPress={async () => {
- close();
- await sleep(500);
- FileViewer.open(result.filePath, {
- showOpenWithDialog: true,
- showAppsSuggestions: true
- }).catch(() => {
- ToastEvent.show({
- heading: "Cannot open",
- message: `No application found to open ${result.name} file.`,
- type: "success",
- context: "local"
- });
+ <View
+ style={{
+ width: "100%",
+ paddingHorizontal: 12,
+ marginTop: 10
+ }}
+ >
+ {complete && (
+ <>
+ <Button
+ title="Open"
+ type="accent"
+ width="100%"
+ fontSize={SIZE.md}
+ onPress={async () => {
+ close();
+ await sleep(500);
+ FileViewer.open(result.filePath, {
+ showOpenWithDialog: true,
+ showAppsSuggestions: true
+ }).catch(() => {
+ ToastEvent.show({
+ heading: "Cannot open",
+ message: `No application found to open ${result.name} file.`,
+ type: "success",
+ context: "local"
});
- }}
- height={50}
- />
- <Button
- title="Share"
- type="shade"
- width="100%"
- fontSize={SIZE.md}
- style={{
- marginTop: 10
- }}
- onPress={async () => {
- if (Platform.OS === "ios") {
- Share.open({
- url: result.filePath
- }).catch(console.log);
- } else {
- FileViewer.open(result.filePath, {
- showOpenWithDialog: true,
- showAppsSuggestions: true,
- shareFile: true
- }).catch(console.log);
- }
- }}
- height={50}
- />
- </>
- )}
- {complete && (
- <Paragraph
+ });
+ }}
+ height={50}
+ />
+ <Button
+ title="Share"
+ type="shade"
+ width="100%"
+ fontSize={SIZE.md}
style={{
- textAlign: "center",
- marginTop: 5
+ marginTop: 10
}}
- color={colors.icon}
- size={SIZE.xs}
- >
- {"Note exported as " + result.fileName}
- </Paragraph>
- )}
- {exporting && !complete && (
- <Button loading={true} height={50} width="100%" />
- )}
- </View>
+ onPress={async () => {
+ if (Platform.OS === "ios") {
+ Share.open({
+ url: result.filePath
+ }).catch(console.log);
+ } else {
+ FileViewer.open(result.filePath, {
+ showOpenWithDialog: true,
+ showAppsSuggestions: true,
+ shareFile: true
+ }).catch(console.log);
+ }
+ }}
+ height={50}
+ />
+ </>
+ )}
+ {complete && (
+ <Paragraph
+ style={{
+ textAlign: "center",
+ marginTop: 5
+ }}
+ color={colors.icon}
+ size={SIZE.xs}
+ >
+ {"Note exported as " + result.fileName}
+ </Paragraph>
+ )}
</View>
</View>
- </SheetWrapper>
+ </View>
);
};
+ExportNotesSheet.present = (note) => {
+ presentSheet({
+ component: <ExportNotesSheet notes={[note]} />
+ });
+};
+
const styles = StyleSheet.create({
container: {
...getElevation(5),
diff --git a/apps/mobile/app/hooks/use-actions.js b/apps/mobile/app/hooks/use-actions.js
index af947cfa6..50a5f1e14 100644
--- a/apps/mobile/app/hooks/use-actions.js
+++ b/apps/mobile/app/hooks/use-actions.js
@@ -18,13 +18,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import Clipboard from "@react-native-clipboard/clipboard";
-import React, { useEffect, useState } from "react";
+import React, { useCallback, useEffect, useState } from "react";
import { Platform } from "react-native";
import Share from "react-native-share";
import { notesnook } from "../../e2e/test.ids";
import { db } from "../common/database";
import { presentDialog } from "../components/dialog/functions";
import NoteHistory from "../components/note-history";
+import ExportNotesSheet from "../components/sheets/export-notes";
import { MoveNotes } from "../components/sheets/move-notes/movenote";
import {
eSendEvent,
@@ -48,15 +49,12 @@ import { toggleDarkMode } from "../utils/color-scheme/utils";
import {
eOpenAddNotebookDialog,
eOpenAddTopicDialog,
- eOpenAttachmentsDialog,
- eOpenExportDialog,
- eOpenLoginDialog,
+ eOpenAttachmentsDialog, eOpenLoginDialog,
eOpenMoveNoteDialog,
eOpenPublishNoteDialog
} from "../utils/events";
import { deleteItems } from "../utils/functions";
import { sleep } from "../utils/time";
-import { useCallback } from "react";
export const useActions = ({ close = () => null, item }) => {
const colors = useThemeStore((state) => state.colors);
@@ -536,7 +534,7 @@ export const useActions = ({ close = () => null, item }) => {
async function exportNote() {
close();
await sleep(300);
- eSendEvent(eOpenExportDialog, [item]);
+ ExportNotesSheet.present(item);
}
async function toggleLocalOnly() {
diff --git a/apps/mobile/app/services/exporter.js b/apps/mobile/app/services/exporter.js
index 0ac469392..85baef73e 100644
--- a/apps/mobile/app/services/exporter.js
+++ b/apps/mobile/app/services/exporter.js
@@ -25,7 +25,7 @@ import RNFetchBlob from "rn-fetch-blob";
import { toTXT } from "../utils";
import { sanitizeFilename } from "../utils/sanitizer";
import Storage from "../common/database/storage";
-import db from "../common/database";
+import {db} from "../common/database/index";
const defaultStyle = `<style>
.img_size_one {
@@ -332,6 +332,7 @@ hr {
</style>`;
async function releasePermissions(path) {
+ if (Platform.OS === "ios") return;
const uris = await ScopedStorage.getPersistedUriPermissions();
for (let uri of uris) {
if (path.startsWith(uri)) {
@@ -349,8 +350,7 @@ async function saveToPDF(note) {
}
Platform.OS === "ios" && (await Storage.checkAndCreateDir("/exported/PDF/"));
-
- let html = await db.notes.note(note).export("html");
+ let html = await db.notes.note(note.id).export("html");
html = decode(html, {
level: EntityLevel.HTML
});