From 25bffe20538296d07923136d0ab55a4ff64acf59 Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Fri, 14 Oct 2022 17:31:36 +0500 Subject: [PATCH] mobile: bulk export all notes --- .../components/sheets/export-notes/index.js | 350 +++++++++++------- apps/mobile/app/package.json | 3 +- .../app/screens/settings/settings-data.tsx | 13 +- apps/mobile/app/services/exporter.js | 346 +++++++++-------- apps/mobile/app/services/premium.js | 2 +- apps/mobile/native/package.json | 3 +- apps/mobile/package-lock.json | 29 ++ apps/mobile/package.json | 3 +- 8 files changed, 445 insertions(+), 304 deletions(-) diff --git a/apps/mobile/app/components/sheets/export-notes/index.js b/apps/mobile/app/components/sheets/export-notes/index.js index 6d97ec010..eb9abeb57 100644 --- a/apps/mobile/app/components/sheets/export-notes/index.js +++ b/apps/mobile/app/components/sheets/export-notes/index.js @@ -18,19 +18,22 @@ along with this program. If not, see . */ import React, { Fragment, useState } from "react"; -import { Platform, StyleSheet, View } from "react-native"; +import { Platform, StyleSheet, View, ActivityIndicator } 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 { db } from "../../../common/database"; import { presentSheet, ToastEvent } from "../../../services/event-manager"; import Exporter from "../../../services/exporter"; +import PremiumService from "../../../services/premium"; import { useThemeStore } from "../../../stores/use-theme-store"; import { getElevation } from "../../../utils"; import { ph, pv, SIZE } from "../../../utils/size"; import { sleep } from "../../../utils/time"; import DialogHeader from "../../dialog/dialog-header"; import { Button } from "../../ui/button"; +import { IconButton } from "../../ui/icon-button"; import { PressableButton } from "../../ui/pressable"; import Seperator from "../../ui/seperator"; import Heading from "../../ui/typography/heading"; @@ -41,22 +44,23 @@ const ExportNotesSheet = ({ notes }) => { const [exporting, setExporting] = useState(false); const [complete, setComplete] = useState(false); const [result, setResult] = useState({}); + const [status, setStatus] = useState(null); - const save = async (func) => { + const save = async (type) => { if (exporting) return; + if (!PremiumService.get() && type !== "txt") return; setExporting(true); setComplete(false); - let res; - for (var i = 0; i < notes.length; i++) { - let note = notes[i]; - res = await func(note); - if (!res) { - setExporting(false); - return; - } + let result; + if (notes.length > 1) { + result = await Exporter.bulkExport(notes, type, setStatus); + } else { + result = await Exporter.exportNote(notes[0], type); + await sleep(1000); } + if (!result) return setExporting(false); - setResult(res); + setResult(result); setComplete(true); setExporting(false); }; @@ -65,7 +69,7 @@ const ExportNotesSheet = ({ notes }) => { { title: "PDF", func: async () => { - await save(Exporter.saveToPDF, "PDF"); + await save("pdf"); }, icon: "file-pdf-box", desc: "Can be opened in a pdf reader like Adobe or Foxit Reader", @@ -74,7 +78,7 @@ const ExportNotesSheet = ({ notes }) => { { title: "Markdown", func: async () => { - await save(Exporter.saveToMarkdown, "Markdown"); + await save("md"); }, icon: "language-markdown", desc: "Can be opened in any text or markdown editor", @@ -83,7 +87,7 @@ const ExportNotesSheet = ({ notes }) => { { title: "Plain Text", func: async () => { - await save(Exporter.saveToText, "Text"); + await save("txt"); }, icon: "card-text", desc: "Can be opened in any text editor", @@ -92,7 +96,7 @@ const ExportNotesSheet = ({ notes }) => { { title: "HTML", func: async () => { - await save(Exporter.saveToHTML, "Html"); + await save("html"); }, icon: "language-html5", desc: "Can be opened in any web browser", @@ -102,151 +106,209 @@ const ExportNotesSheet = ({ notes }) => { return ( - - - + {!complete && !exporting ? ( + <> + + 1 ? "Export Notes" : "Export Note"} + paragraph={`All exports are saved in ${ + Platform.OS === "android" + ? "the selected" + : "Notesnook/exported" + } folder in phone storage`} + /> + + + + + ) : null} - - {actions.map((item) => ( - - - - ( + + + - + + + + + {item.title} + + + {item.desc} + + + + + )) + ) : ( + + {!complete ? ( + <> + + + {notes.length === 1 + ? "Exporting note... Please wait" + : `Exporting notes${ + status ? ` (${status})` : `` + }... Please wait`} + + + ) : ( + <> + - - - - {item.title} - - - {item.desc} + {notes.length > 1 ? "Notes exported" : "Note exported"} + + + Your {notes.length > 1 ? "notes are" : "note is"} exported + successfully as {result.fileName} - - - - ))} - - - {complete && ( - <> -