Added file delete after upload.
This commit is contained in:
@@ -1021,6 +1021,27 @@
|
|||||||
<folder_node>
|
<folder_node>
|
||||||
<name>actions</name>
|
<name>actions</name>
|
||||||
<children>
|
<children>
|
||||||
|
<concept_node>
|
||||||
|
<name>refresh</name>
|
||||||
|
<definition_loaded>false</definition_loaded>
|
||||||
|
<description></description>
|
||||||
|
<comment></comment>
|
||||||
|
<default_text></default_text>
|
||||||
|
<translations>
|
||||||
|
<translation>
|
||||||
|
<language>en-US</language>
|
||||||
|
<approved>false</approved>
|
||||||
|
</translation>
|
||||||
|
<translation>
|
||||||
|
<language>es-MX</language>
|
||||||
|
<approved>false</approved>
|
||||||
|
</translation>
|
||||||
|
<translation>
|
||||||
|
<language>fr-CA</language>
|
||||||
|
<approved>false</approved>
|
||||||
|
</translation>
|
||||||
|
</translations>
|
||||||
|
</concept_node>
|
||||||
<concept_node>
|
<concept_node>
|
||||||
<name>upload</name>
|
<name>upload</name>
|
||||||
<definition_loaded>false</definition_loaded>
|
<definition_loaded>false</definition_loaded>
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import { Ionicons } from "@expo/vector-icons";
|
import { Ionicons } from "@expo/vector-icons";
|
||||||
|
import { useNavigation } from "@react-navigation/native";
|
||||||
import { AssetsSelector } from "expo-images-picker";
|
import { AssetsSelector } from "expo-images-picker";
|
||||||
|
import * as MediaLibrary from "expo-media-library";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import React, { useState } from "react";
|
import React, { useCallback, useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { StyleSheet, Text, View } from "react-native";
|
import { StyleSheet, Text, View } from "react-native";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
@@ -18,7 +20,6 @@ import { handleUpload } from "../../util/document-upload.utility";
|
|||||||
import CameraSelectJob from "../camera-select-job/camera-select-job.component";
|
import CameraSelectJob from "../camera-select-job/camera-select-job.component";
|
||||||
import UploadDeleteSwitch from "../upload-delete-switch/upload-delete-switch.component";
|
import UploadDeleteSwitch from "../upload-delete-switch/upload-delete-switch.component";
|
||||||
import UploadProgress from "../upload-progress/upload-progress.component";
|
import UploadProgress from "../upload-progress/upload-progress.component";
|
||||||
import * as FileSystem from "expo-file-system";
|
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
currentUser: selectCurrentUser,
|
currentUser: selectCurrentUser,
|
||||||
@@ -35,19 +36,25 @@ export function ImageBrowserScreen({
|
|||||||
deleteAfterUpload,
|
deleteAfterUpload,
|
||||||
}) {
|
}) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const navigation = useNavigation();
|
||||||
const [uploads, setUploads] = useState({});
|
const [uploads, setUploads] = useState({});
|
||||||
|
|
||||||
function handleOnProgress(uri, percent) {
|
function handleOnProgress(uri, percent) {
|
||||||
setUploads((prevUploads) => ({ ...prevUploads, [uri]: { percent } }));
|
setUploads((prevUploads) => ({ ...prevUploads, [uri]: { percent } }));
|
||||||
}
|
}
|
||||||
function handleOnSuccess(uri) {
|
|
||||||
|
const [tick, setTick] = useState(0);
|
||||||
|
const forceRerender = useCallback(() => {
|
||||||
|
setTick((tick) => tick + 1);
|
||||||
|
}, []);
|
||||||
|
async function handleOnSuccess(uri, id) {
|
||||||
console.log("onSucces!", uri);
|
console.log("onSucces!", uri);
|
||||||
setTimeout(async function () {
|
|
||||||
setUploads((prevUploads) => _.omit(prevUploads, uri));
|
if (deleteAfterUpload) {
|
||||||
if (deleteAfterUpload) {
|
const result = await MediaLibrary.deleteAssetsAsync([id]);
|
||||||
await FileSystem.deleteAsync(uri);
|
console.log("result :>> ", result);
|
||||||
}
|
}
|
||||||
}, 1000);
|
console.log("Omitting", uri);
|
||||||
|
setUploads((prevUploads) => _.omit(prevUploads, uri));
|
||||||
}
|
}
|
||||||
|
|
||||||
const onDone = async (data) => {
|
const onDone = async (data) => {
|
||||||
@@ -61,7 +68,7 @@ export function ImageBrowserScreen({
|
|||||||
uri: p.uri,
|
uri: p.uri,
|
||||||
onError: handleOnError,
|
onError: handleOnError,
|
||||||
onProgress: ({ percent }) => handleOnProgress(uri, percent),
|
onProgress: ({ percent }) => handleOnProgress(uri, percent),
|
||||||
onSuccess: () => handleOnSuccess(uri),
|
onSuccess: () => handleOnSuccess(uri, p.id),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
bodyshop: bodyshop,
|
bodyshop: bodyshop,
|
||||||
@@ -72,7 +79,9 @@ export function ImageBrowserScreen({
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
Promise.all(actions);
|
await Promise.all(actions);
|
||||||
|
forceRerender();
|
||||||
|
//navigation.goBack();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -81,7 +90,8 @@ export function ImageBrowserScreen({
|
|||||||
<UploadDeleteSwitch />
|
<UploadDeleteSwitch />
|
||||||
{selectedCameraJobId && (
|
{selectedCameraJobId && (
|
||||||
<AssetsSelector
|
<AssetsSelector
|
||||||
style={{ flex: 9 }}
|
style={{ flex: 1 }}
|
||||||
|
key={tick}
|
||||||
options={{
|
options={{
|
||||||
// manipulate: {
|
// manipulate: {
|
||||||
// //width: 512,
|
// //width: 512,
|
||||||
@@ -113,28 +123,23 @@ export function ImageBrowserScreen({
|
|||||||
},
|
},
|
||||||
defaultTopNavigator: {
|
defaultTopNavigator: {
|
||||||
continueText: t("mediabrowser.actions.upload"),
|
continueText: t("mediabrowser.actions.upload"),
|
||||||
//goBackText: "Back",
|
goBackText: t("mediabrowser.actions.refresh"),
|
||||||
buttonStyle: styles.buttonStyle,
|
buttonStyle: styles.buttonStyle,
|
||||||
textStyle: styles.textStyle,
|
textStyle: styles.textStyle,
|
||||||
|
|
||||||
backFunction: (props) => {
|
backFunction: () => {
|
||||||
console.log("Back Function", props);
|
forceRerender();
|
||||||
},
|
},
|
||||||
doneFunction: onDone,
|
doneFunction: onDone,
|
||||||
},
|
},
|
||||||
noAssets: {
|
noAssets: {
|
||||||
Component: function NoAsset() {
|
Component: function NoAsset() {
|
||||||
return (
|
return <Text>{`Looks like there's nothing here...`}</Text>;
|
||||||
<View>
|
|
||||||
<Text>Looks like nothing here</Text>
|
|
||||||
</View>
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<UploadProgress uploads={uploads} />
|
<UploadProgress uploads={uploads} />
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { ScrollView, StyleSheet, Text, View } from "react-native";
|
|||||||
import * as Progress from "react-native-progress";
|
import * as Progress from "react-native-progress";
|
||||||
|
|
||||||
export default function UploadProgress({ uploads }) {
|
export default function UploadProgress({ uploads }) {
|
||||||
|
console.log("uploads :>> ", uploads);
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<ScrollView>
|
<ScrollView>
|
||||||
|
|||||||
@@ -74,6 +74,7 @@
|
|||||||
},
|
},
|
||||||
"mediabrowser": {
|
"mediabrowser": {
|
||||||
"actions": {
|
"actions": {
|
||||||
|
"refresh": "Refresh",
|
||||||
"upload": "Upload"
|
"upload": "Upload"
|
||||||
},
|
},
|
||||||
"labels": {
|
"labels": {
|
||||||
|
|||||||
@@ -74,6 +74,7 @@
|
|||||||
},
|
},
|
||||||
"mediabrowser": {
|
"mediabrowser": {
|
||||||
"actions": {
|
"actions": {
|
||||||
|
"refresh": "",
|
||||||
"upload": ""
|
"upload": ""
|
||||||
},
|
},
|
||||||
"labels": {
|
"labels": {
|
||||||
|
|||||||
@@ -74,6 +74,7 @@
|
|||||||
},
|
},
|
||||||
"mediabrowser": {
|
"mediabrowser": {
|
||||||
"actions": {
|
"actions": {
|
||||||
|
"refresh": "",
|
||||||
"upload": ""
|
"upload": ""
|
||||||
},
|
},
|
||||||
"labels": {
|
"labels": {
|
||||||
|
|||||||
Reference in New Issue
Block a user