IO-1132 improve caching after insert.
This commit is contained in:
@@ -23,9 +23,7 @@ export default function JobDocumentsComponent({ job, loading, refetch }) {
|
||||
job.documents.map((doc) => {
|
||||
return {
|
||||
source: {
|
||||
uri: `${env.REACT_APP_CLOUDINARY_ENDPOINT}/${DetermineFileType(
|
||||
doc.type
|
||||
)}/upload/${doc.key}`,
|
||||
uri: GenerateSrcUrl(doc),
|
||||
},
|
||||
};
|
||||
}),
|
||||
@@ -62,11 +60,7 @@ export default function JobDocumentsComponent({ job, loading, refetch }) {
|
||||
source={{
|
||||
width: 100,
|
||||
height: 100,
|
||||
uri: `${
|
||||
env.REACT_APP_CLOUDINARY_ENDPOINT
|
||||
}/${DetermineFileType(object.item.type)}/upload/${
|
||||
env.REACT_APP_CLOUDINARY_THUMB_TRANSFORMATIONS
|
||||
}/${object.item.key}`,
|
||||
uri: GenerateThumbUrl(object.item),
|
||||
}}
|
||||
/>
|
||||
</TouchableOpacity>
|
||||
@@ -84,3 +78,17 @@ export default function JobDocumentsComponent({ job, loading, refetch }) {
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
export const GenerateSrcUrl = (value) => {
|
||||
let extension = value.extension;
|
||||
if (extension && extension.includes("heic")) extension = "jpg";
|
||||
|
||||
return `${env.REACT_APP_CLOUDINARY_ENDPOINT}/${DetermineFileType(
|
||||
value.type
|
||||
)}/upload/${value.key}${extension ? `.${extension}` : ""}`;
|
||||
};
|
||||
|
||||
export const GenerateThumbUrl = (value) =>
|
||||
`${env.REACT_APP_CLOUDINARY_ENDPOINT}/${DetermineFileType(
|
||||
value.type
|
||||
)}/upload/${env.REACT_APP_CLOUDINARY_THUMB_TRANSFORMATIONS}/${value.key}`;
|
||||
|
||||
@@ -34,9 +34,6 @@ export default function JobLines({ job, loading, refetch }) {
|
||||
<DataTable.Title style={{ flex: 1 }}>
|
||||
{t("jobdetail.labels.lines_qty")}
|
||||
</DataTable.Title>
|
||||
<DataTable.Title style={{ flex: 1 }}>
|
||||
{t("jobdetail.labels.lines_price")}
|
||||
</DataTable.Title>
|
||||
</DataTable.Header>
|
||||
</DataTable>
|
||||
|
||||
|
||||
@@ -204,7 +204,7 @@ export function UploadProgress({
|
||||
|
||||
forceRerender();
|
||||
};
|
||||
console.log("speed", progress.speed, progress.speed !== 0);
|
||||
|
||||
return (
|
||||
<Modal
|
||||
visible={progress.uploadInProgress}
|
||||
|
||||
@@ -27,15 +27,8 @@ export const GET_DOCUMENTS_BY_JOB = gql`
|
||||
key
|
||||
type
|
||||
takenat
|
||||
bill {
|
||||
id
|
||||
invoice_number
|
||||
date
|
||||
vendor {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
extension
|
||||
jobid
|
||||
}
|
||||
}
|
||||
`;
|
||||
@@ -47,6 +40,10 @@ export const INSERT_NEW_DOCUMENT = gql`
|
||||
id
|
||||
name
|
||||
key
|
||||
type
|
||||
takenat
|
||||
extension
|
||||
jobid
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ i18n.use(initReactI18next).init({
|
||||
// have a common namespace used around the full app
|
||||
// ns: ["common"],
|
||||
// defaultNS: "common",
|
||||
debug: true,
|
||||
//debug: true,
|
||||
// cache: {
|
||||
// enabled: true
|
||||
// },
|
||||
|
||||
@@ -4,6 +4,7 @@ import { client } from "../graphql/client";
|
||||
import { INSERT_NEW_DOCUMENT } from "../graphql/documents.queries";
|
||||
import { axiosAuthInterceptorId } from "./CleanAxios";
|
||||
import * as MediaLibrary from "expo-media-library";
|
||||
import { gql } from "@apollo/client";
|
||||
|
||||
//Context: currentUserEmail, bodyshop, jobid, invoiceid
|
||||
|
||||
@@ -143,6 +144,30 @@ export const uploadToCloudinary = async (
|
||||
//Insert the document with the matching key.
|
||||
const documentInsert = await client.mutate({
|
||||
mutation: INSERT_NEW_DOCUMENT,
|
||||
|
||||
update: (cache, { data }) => {
|
||||
cache.modify({
|
||||
fields: {
|
||||
documents: (existingDocs = []) => {
|
||||
const newDocRef = cache.writeFragment({
|
||||
data: data.insert_documents.returning[0],
|
||||
fragment: gql`
|
||||
fragment newDoc on documents {
|
||||
id
|
||||
name
|
||||
key
|
||||
type
|
||||
takenat
|
||||
extension
|
||||
jobid
|
||||
}
|
||||
`,
|
||||
});
|
||||
return [...existingDocs, newDocRef];
|
||||
},
|
||||
},
|
||||
});
|
||||
},
|
||||
variables: {
|
||||
docInput: [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user