Resolve upload issues.
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import { Video } from "expo-av";
|
||||||
import React, { useMemo, useState } from "react";
|
import React, { useMemo, useState } from "react";
|
||||||
import {
|
import {
|
||||||
FlatList,
|
FlatList,
|
||||||
@@ -13,6 +14,13 @@ import MediaCacheOverlay from "../media-cache-overlay/media-cache-overlay.compon
|
|||||||
|
|
||||||
export default function JobDocumentsComponent({ job, loading, refetch }) {
|
export default function JobDocumentsComponent({ job, loading, refetch }) {
|
||||||
const [previewVisible, setPreviewVisible] = useState(false);
|
const [previewVisible, setPreviewVisible] = useState(false);
|
||||||
|
const [videoUri, setVideoUri] = useState(null);
|
||||||
|
const [status, setStatus] = React.useState({});
|
||||||
|
console.log(
|
||||||
|
"🚀 ~ file: job-documents.component.jsx ~ line 19 ~ status",
|
||||||
|
status
|
||||||
|
);
|
||||||
|
|
||||||
const [imgIndex, setImgIndex] = useState(0);
|
const [imgIndex, setImgIndex] = useState(0);
|
||||||
const onRefresh = async () => {
|
const onRefresh = async () => {
|
||||||
return refetch();
|
return refetch();
|
||||||
@@ -41,33 +49,43 @@ export default function JobDocumentsComponent({ job, loading, refetch }) {
|
|||||||
style={{ flex: 1 }}
|
style={{ flex: 1 }}
|
||||||
keyExtractor={(item) => item.id}
|
keyExtractor={(item) => item.id}
|
||||||
renderItem={(object) => (
|
renderItem={(object) => (
|
||||||
<View
|
<TouchableOpacity
|
||||||
style={{
|
style={{ flex: 1 / 4, aspectRatio: 1 }}
|
||||||
flex: 1,
|
onPress={() => {
|
||||||
flexDirection: "column",
|
if (DetermineFileType(object.item.type) === "image") {
|
||||||
justifyContent: "center",
|
//If image
|
||||||
alignItems: "center",
|
|
||||||
margin: 5,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<TouchableOpacity
|
|
||||||
onPress={() => {
|
|
||||||
setImgIndex(object.index);
|
setImgIndex(object.index);
|
||||||
setPreviewVisible(true);
|
setPreviewVisible(true);
|
||||||
|
} else {
|
||||||
|
//If Video
|
||||||
|
setVideoUri(GenerateSrcUrl(object.item));
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Image
|
||||||
|
style={{ flex: 1 }}
|
||||||
|
resizeMode="cover"
|
||||||
|
source={{
|
||||||
|
uri: GenerateThumbUrl(object.item),
|
||||||
|
aspectRatio: 1,
|
||||||
}}
|
}}
|
||||||
>
|
/>
|
||||||
<Image
|
</TouchableOpacity>
|
||||||
source={{
|
|
||||||
width: 100,
|
|
||||||
height: 100,
|
|
||||||
uri: GenerateThumbUrl(object.item),
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</TouchableOpacity>
|
|
||||||
</View>
|
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
<Text>{job.documents.length}</Text>
|
<Text>{job.documents.length}</Text>
|
||||||
|
<Video
|
||||||
|
source={
|
||||||
|
videoUri
|
||||||
|
? {
|
||||||
|
uri: videoUri,
|
||||||
|
}
|
||||||
|
: null
|
||||||
|
}
|
||||||
|
useNativeControls
|
||||||
|
isLooping
|
||||||
|
onPlaybackStatusUpdate={(status) => setStatus(() => status)}
|
||||||
|
/>
|
||||||
<MediaCacheOverlay
|
<MediaCacheOverlay
|
||||||
photos={fullphotos}
|
photos={fullphotos}
|
||||||
imgIndex={imgIndex}
|
imgIndex={imgIndex}
|
||||||
@@ -88,7 +106,18 @@ export const GenerateSrcUrl = (value) => {
|
|||||||
)}/upload/${value.key}${extension ? `.${extension}` : ""}`;
|
)}/upload/${value.key}${extension ? `.${extension}` : ""}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const GenerateThumbUrl = (value) =>
|
export const GenerateThumbUrl = (value) => {
|
||||||
`${env.REACT_APP_CLOUDINARY_ENDPOINT}/${DetermineFileType(
|
let extension = value.extension;
|
||||||
|
if (extension && extension.includes("heic")) extension = "jpg";
|
||||||
|
else if (
|
||||||
|
DetermineFileType(value.type) !== "image" ||
|
||||||
|
(value.type && value.type.includes("application"))
|
||||||
|
)
|
||||||
|
extension = "jpg";
|
||||||
|
|
||||||
|
return `${env.REACT_APP_CLOUDINARY_ENDPOINT}/${DetermineFileType(
|
||||||
value.type
|
value.type
|
||||||
)}/upload/${env.REACT_APP_CLOUDINARY_THUMB_TRANSFORMATIONS}/${value.key}`;
|
)}/upload/${env.REACT_APP_CLOUDINARY_THUMB_TRANSFORMATIONS}/${value.key}${
|
||||||
|
extension ? `.${extension}` : ""
|
||||||
|
}`;
|
||||||
|
};
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export function ImageBrowserScreen({ selectedCameraJobId }) {
|
|||||||
|
|
||||||
const onDone = (data) => {
|
const onDone = (data) => {
|
||||||
logImEXEvent("imexmobile_upload_documents", { count: data.length });
|
logImEXEvent("imexmobile_upload_documents", { count: data.length });
|
||||||
setUploads(data);
|
if (data.length !== 0) setUploads(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -152,40 +152,25 @@ export function UploadProgress({
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Sequentially await the proms.
|
//Sequentially await the proms.
|
||||||
for (const p of data) {
|
|
||||||
let filename;
|
|
||||||
filename = p.filename || p.uri.split("/").pop();
|
|
||||||
|
|
||||||
await handleUpload(
|
for (var i = 0; i < data.length + 4; i = i + 4) {
|
||||||
{
|
console.log("i :>> ", i);
|
||||||
filename,
|
let proms = [];
|
||||||
mediaId: p.id,
|
if (data[i]) {
|
||||||
onError: handleOnError,
|
proms.push(CreateUploadProm(data[i]));
|
||||||
onProgress: ({ percent, loaded }) =>
|
}
|
||||||
handleOnProgress(p.id, percent, loaded),
|
if (data[i + 1]) {
|
||||||
onSuccess: () => handleOnSuccess(p.id),
|
proms.push(CreateUploadProm(data[i + 1]));
|
||||||
},
|
}
|
||||||
{
|
if (data[i + 2]) {
|
||||||
bodyshop: bodyshop,
|
proms.push(CreateUploadProm(data[i + 2]));
|
||||||
jobId: selectedCameraJobId !== "temp" ? selectedCameraJobId : null,
|
}
|
||||||
uploaded_by: currentUser.email,
|
if (data[i + 3]) {
|
||||||
photo: p,
|
proms.push(CreateUploadProm(data[i + 3]));
|
||||||
}
|
}
|
||||||
);
|
console.log("Proms Length", proms.length);
|
||||||
|
await Promise.all(proms);
|
||||||
//Set the state to mark that it's done.
|
console.log("Await done.");
|
||||||
setProgress((progress) => ({
|
|
||||||
...progress,
|
|
||||||
action: null,
|
|
||||||
speed: 0,
|
|
||||||
files: {
|
|
||||||
...progress.files,
|
|
||||||
[p.id]: {
|
|
||||||
...progress.files[p.id],
|
|
||||||
action: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deleteAfterUpload) {
|
if (deleteAfterUpload) {
|
||||||
@@ -208,6 +193,43 @@ export function UploadProgress({
|
|||||||
forceRerender();
|
forceRerender();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const CreateUploadProm = async (p) => {
|
||||||
|
let filename;
|
||||||
|
filename = p.filename || p.uri.split("/").pop();
|
||||||
|
console.log("Start upping.", p.id);
|
||||||
|
|
||||||
|
await handleUpload(
|
||||||
|
{
|
||||||
|
filename,
|
||||||
|
mediaId: p.id,
|
||||||
|
onError: handleOnError,
|
||||||
|
onProgress: ({ percent, loaded }) =>
|
||||||
|
handleOnProgress(p.id, percent, loaded),
|
||||||
|
onSuccess: () => handleOnSuccess(p.id),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
bodyshop: bodyshop,
|
||||||
|
jobId: selectedCameraJobId !== "temp" ? selectedCameraJobId : null,
|
||||||
|
uploaded_by: currentUser.email,
|
||||||
|
photo: p,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
console.log("Done upping.", p.id);
|
||||||
|
//Set the state to mark that it's done.
|
||||||
|
setProgress((progress) => ({
|
||||||
|
...progress,
|
||||||
|
action: null,
|
||||||
|
speed: 0,
|
||||||
|
files: {
|
||||||
|
...progress.files,
|
||||||
|
[p.id]: {
|
||||||
|
...progress.files[p.id],
|
||||||
|
action: null,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
visible={progress.uploadInProgress}
|
visible={progress.uploadInProgress}
|
||||||
|
|||||||
4
env.js
4
env.js
@@ -9,7 +9,7 @@ const ENV = {
|
|||||||
"https://api.cloudinary.com/v1_1/bodyshop",
|
"https://api.cloudinary.com/v1_1/bodyshop",
|
||||||
REACT_APP_CLOUDINARY_ENDPOINT: "https://res.cloudinary.com/bodyshop",
|
REACT_APP_CLOUDINARY_ENDPOINT: "https://res.cloudinary.com/bodyshop",
|
||||||
REACT_APP_CLOUDINARY_API_KEY: "473322739956866",
|
REACT_APP_CLOUDINARY_API_KEY: "473322739956866",
|
||||||
REACT_APP_CLOUDINARY_THUMB_TRANSFORMATIONS: "c_fill,f_auto,h_250,w_250",
|
REACT_APP_CLOUDINARY_THUMB_TRANSFORMATIONS: "c_fill,h_250,w_250",
|
||||||
firebase: {
|
firebase: {
|
||||||
apiKey: "AIzaSyBw7_GTy7GtQyfkIRPVrWHEGKfcqeyXw0c",
|
apiKey: "AIzaSyBw7_GTy7GtQyfkIRPVrWHEGKfcqeyXw0c",
|
||||||
authDomain: "imex-test.firebaseapp.com",
|
authDomain: "imex-test.firebaseapp.com",
|
||||||
@@ -29,7 +29,7 @@ const ENV = {
|
|||||||
"https://api.cloudinary.com/v1_1/bodyshop",
|
"https://api.cloudinary.com/v1_1/bodyshop",
|
||||||
REACT_APP_CLOUDINARY_ENDPOINT: "https://res.cloudinary.com/bodyshop",
|
REACT_APP_CLOUDINARY_ENDPOINT: "https://res.cloudinary.com/bodyshop",
|
||||||
REACT_APP_CLOUDINARY_API_KEY: "473322739956866",
|
REACT_APP_CLOUDINARY_API_KEY: "473322739956866",
|
||||||
REACT_APP_CLOUDINARY_THUMB_TRANSFORMATIONS: "h_200,w_200,c_thumb",
|
REACT_APP_CLOUDINARY_THUMB_TRANSFORMATIONS: "c_fill,h_250,w_250",
|
||||||
firebase: {
|
firebase: {
|
||||||
apiKey: "AIzaSyDSezy-jGJreo7ulgpLdlpOwAOrgcaEkhU",
|
apiKey: "AIzaSyDSezy-jGJreo7ulgpLdlpOwAOrgcaEkhU",
|
||||||
authDomain: "imex-prod.firebaseapp.com",
|
authDomain: "imex-prod.firebaseapp.com",
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
"@react-navigation/native": "^5.9.4",
|
"@react-navigation/native": "^5.9.4",
|
||||||
"@react-navigation/stack": "^5.14.5",
|
"@react-navigation/stack": "^5.14.5",
|
||||||
"axios": "^0.21.0",
|
"axios": "^0.21.0",
|
||||||
|
"cloudinary-core": "^2.11.4",
|
||||||
"dinero.js": "^1.8.1",
|
"dinero.js": "^1.8.1",
|
||||||
"expo": "^41.0.0",
|
"expo": "^41.0.0",
|
||||||
"expo-app-loading": "^1.0.3",
|
"expo-app-loading": "^1.0.3",
|
||||||
|
|||||||
16
yarn.lock
16
yarn.lock
@@ -2271,16 +2271,7 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
deep-assign "^3.0.0"
|
deep-assign "^3.0.0"
|
||||||
|
|
||||||
"@react-native-community/art@^1.1.2":
|
"@react-native-community/art@^1.1.2", "@react-native-community/art@^1.2.0":
|
||||||
version "1.2.0"
|
|
||||||
resolved "https://registry.npmjs.org/@react-native-community/art/-/art-1.2.0.tgz"
|
|
||||||
integrity sha512-a+ZcRGl/BzLa89yi33Mbn5SHavsEXqKUMdbfLf3U8MDLElndPqUetoJyGkv63+BcPO49UMWiQRP1YUz6/zfJ+A==
|
|
||||||
dependencies:
|
|
||||||
art "^0.10.3"
|
|
||||||
invariant "^2.2.4"
|
|
||||||
prop-types "^15.7.2"
|
|
||||||
|
|
||||||
"@react-native-community/art@^1.2.0":
|
|
||||||
version "1.2.0"
|
version "1.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/@react-native-community/art/-/art-1.2.0.tgz#386d95393f6042d9006f9d4bc6063fb898794460"
|
resolved "https://registry.yarnpkg.com/@react-native-community/art/-/art-1.2.0.tgz#386d95393f6042d9006f9d4bc6063fb898794460"
|
||||||
integrity sha512-a+ZcRGl/BzLa89yi33Mbn5SHavsEXqKUMdbfLf3U8MDLElndPqUetoJyGkv63+BcPO49UMWiQRP1YUz6/zfJ+A==
|
integrity sha512-a+ZcRGl/BzLa89yi33Mbn5SHavsEXqKUMdbfLf3U8MDLElndPqUetoJyGkv63+BcPO49UMWiQRP1YUz6/zfJ+A==
|
||||||
@@ -3605,6 +3596,11 @@ clone@^1.0.2:
|
|||||||
resolved "https://registry.npmjs.org/clone/-/clone-1.0.4.tgz"
|
resolved "https://registry.npmjs.org/clone/-/clone-1.0.4.tgz"
|
||||||
integrity sha1-2jCcwmPfFZlMaIypAheco8fNfH4=
|
integrity sha1-2jCcwmPfFZlMaIypAheco8fNfH4=
|
||||||
|
|
||||||
|
cloudinary-core@^2.11.4:
|
||||||
|
version "2.11.4"
|
||||||
|
resolved "https://registry.yarnpkg.com/cloudinary-core/-/cloudinary-core-2.11.4.tgz#1d191935bcdcd412d499a91b928a94b266fee49d"
|
||||||
|
integrity sha512-F1BZczD6f5mB73D0c8gl/iuacVQQO+UhckNZxeeS9ZIVeIHbsfqwWiAZMQmIvEb7Wti/9MLU0xVwaWOak2THHA==
|
||||||
|
|
||||||
code-point-at@^1.0.0:
|
code-point-at@^1.0.0:
|
||||||
version "1.1.0"
|
version "1.1.0"
|
||||||
resolved "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz"
|
resolved "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz"
|
||||||
|
|||||||
Reference in New Issue
Block a user