mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-17 20:27:53 +01:00
mobile: fix opening exported files after export
This commit is contained in:
@@ -19,7 +19,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
import { useThemeColors } from "@notesnook/theme";
|
import { useThemeColors } from "@notesnook/theme";
|
||||||
import React, { Fragment, useState } from "react";
|
import React, { Fragment, useState } from "react";
|
||||||
import { ActivityIndicator, Platform, StyleSheet, View } from "react-native";
|
import {
|
||||||
|
ActivityIndicator,
|
||||||
|
Linking,
|
||||||
|
Platform,
|
||||||
|
StyleSheet,
|
||||||
|
View
|
||||||
|
} from "react-native";
|
||||||
import FileViewer from "react-native-file-viewer";
|
import FileViewer from "react-native-file-viewer";
|
||||||
import Share from "react-native-share";
|
import Share from "react-native-share";
|
||||||
import Icon from "react-native-vector-icons/MaterialCommunityIcons";
|
import Icon from "react-native-vector-icons/MaterialCommunityIcons";
|
||||||
@@ -29,14 +35,12 @@ import { requestInAppReview } from "../../../services/app-review";
|
|||||||
import {
|
import {
|
||||||
PresentSheetOptions,
|
PresentSheetOptions,
|
||||||
ToastManager,
|
ToastManager,
|
||||||
eSendEvent,
|
|
||||||
presentSheet
|
presentSheet
|
||||||
} from "../../../services/event-manager";
|
} from "../../../services/event-manager";
|
||||||
import Exporter from "../../../services/exporter";
|
import Exporter from "../../../services/exporter";
|
||||||
import PremiumService from "../../../services/premium";
|
import PremiumService from "../../../services/premium";
|
||||||
import { useUserStore } from "../../../stores/use-user-store";
|
import { useUserStore } from "../../../stores/use-user-store";
|
||||||
import { getElevationStyle } from "../../../utils/elevation";
|
import { getElevationStyle } from "../../../utils/elevation";
|
||||||
import { eCloseSheet } from "../../../utils/events";
|
|
||||||
import { SIZE, ph, pv } from "../../../utils/size";
|
import { SIZE, ph, pv } from "../../../utils/size";
|
||||||
import { sleep } from "../../../utils/time";
|
import { sleep } from "../../../utils/time";
|
||||||
import { Dialog } from "../../dialog";
|
import { Dialog } from "../../dialog";
|
||||||
@@ -65,6 +69,7 @@ const ExportNotesSheet = ({
|
|||||||
filePath: string;
|
filePath: string;
|
||||||
name: string;
|
name: string;
|
||||||
type: string;
|
type: string;
|
||||||
|
fileDir: string;
|
||||||
}
|
}
|
||||||
| undefined
|
| undefined
|
||||||
>();
|
>();
|
||||||
@@ -295,7 +300,9 @@ const ExportNotesSheet = ({
|
|||||||
successfully as {result?.fileName}
|
successfully as {result?.fileName}
|
||||||
</Paragraph>
|
</Paragraph>
|
||||||
<Button
|
<Button
|
||||||
title="Open"
|
title={
|
||||||
|
Platform.OS === "android" ? "Open file location" : "Open"
|
||||||
|
}
|
||||||
type="accent"
|
type="accent"
|
||||||
width={250}
|
width={250}
|
||||||
fontSize={SIZE.md}
|
fontSize={SIZE.md}
|
||||||
@@ -305,13 +312,15 @@ const ExportNotesSheet = ({
|
|||||||
}}
|
}}
|
||||||
onPress={async () => {
|
onPress={async () => {
|
||||||
if (!result?.filePath) return;
|
if (!result?.filePath) return;
|
||||||
eSendEvent(eCloseSheet);
|
if (Platform.OS === "android") {
|
||||||
await sleep(500);
|
Linking.openURL(result.fileDir).catch((e) => {
|
||||||
|
ToastManager.error(e as Error);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
FileViewer.open(result?.filePath, {
|
FileViewer.open(result?.filePath, {
|
||||||
showOpenWithDialog: true,
|
showOpenWithDialog: true,
|
||||||
showAppsSuggestions: true
|
showAppsSuggestions: true
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
console.log(e);
|
|
||||||
ToastManager.show({
|
ToastManager.show({
|
||||||
heading: "Cannot open",
|
heading: "Cannot open",
|
||||||
message: `No application found to open ${result.name} file.`,
|
message: `No application found to open ${result.name} file.`,
|
||||||
@@ -319,6 +328,7 @@ const ExportNotesSheet = ({
|
|||||||
context: "local"
|
context: "local"
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
@@ -331,10 +341,10 @@ const ExportNotesSheet = ({
|
|||||||
borderRadius: 100
|
borderRadius: 100
|
||||||
}}
|
}}
|
||||||
onPress={async () => {
|
onPress={async () => {
|
||||||
if (!result?.filePath) return;
|
if (!result) return;
|
||||||
if (Platform.OS === "ios") {
|
if (Platform.OS === "ios") {
|
||||||
Share.open({
|
Share.open({
|
||||||
url: result.filePath
|
url: result?.fileDir + result.fileName
|
||||||
}).catch(console.log);
|
}).catch(console.log);
|
||||||
} else {
|
} else {
|
||||||
FileViewer.open(result.filePath, {
|
FileViewer.open(result.filePath, {
|
||||||
@@ -347,7 +357,7 @@ const ExportNotesSheet = ({
|
|||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
title="Export in another format"
|
title="Export in another format"
|
||||||
type="secondaryAccented"
|
type="inverted"
|
||||||
width={250}
|
width={250}
|
||||||
fontSize={SIZE.md}
|
fontSize={SIZE.md}
|
||||||
style={{
|
style={{
|
||||||
|
|||||||
@@ -119,6 +119,7 @@ async function createZip(
|
|||||||
callback: (progress?: string) => void
|
callback: (progress?: string) => void
|
||||||
) {
|
) {
|
||||||
const fileName = `nn-export-${totalNotes}-${type}-${Date.now()}.zip`;
|
const fileName = `nn-export-${totalNotes}-${type}-${Date.now()}.zip`;
|
||||||
|
const dir = path;
|
||||||
try {
|
try {
|
||||||
callback("Creating zip");
|
callback("Creating zip");
|
||||||
const zipOutputPath =
|
const zipOutputPath =
|
||||||
@@ -126,6 +127,7 @@ async function createZip(
|
|||||||
? join(path, fileName)
|
? join(path, fileName)
|
||||||
: join(RNFetchBlob.fs.dirs.CacheDir, fileName);
|
: join(RNFetchBlob.fs.dirs.CacheDir, fileName);
|
||||||
await zip(cacheFolder, zipOutputPath);
|
await zip(cacheFolder, zipOutputPath);
|
||||||
|
|
||||||
callback("Saving zip file");
|
callback("Saving zip file");
|
||||||
if (Platform.OS === "android") {
|
if (Platform.OS === "android") {
|
||||||
const file = await ScopedStorage.createFile(
|
const file = await ScopedStorage.createFile(
|
||||||
@@ -137,6 +139,8 @@ async function createZip(
|
|||||||
await copyFileAsync("file://" + zipOutputPath, path);
|
await copyFileAsync("file://" + zipOutputPath, path);
|
||||||
await RNFetchBlob.fs.unlink(zipOutputPath);
|
await RNFetchBlob.fs.unlink(zipOutputPath);
|
||||||
callback();
|
callback();
|
||||||
|
} else {
|
||||||
|
path = zipOutputPath;
|
||||||
}
|
}
|
||||||
RNFetchBlob.fs.unlink(cacheFolder);
|
RNFetchBlob.fs.unlink(cacheFolder);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -145,6 +149,7 @@ async function createZip(
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
filePath: path,
|
filePath: path,
|
||||||
|
fileDir: dir,
|
||||||
type: "application/zip",
|
type: "application/zip",
|
||||||
name: "zip",
|
name: "zip",
|
||||||
fileName: fileName,
|
fileName: fileName,
|
||||||
|
|||||||
Reference in New Issue
Block a user