IO-1132 improve caching after insert.

This commit is contained in:
Patrick Fic
2021-06-01 11:11:49 -07:00
parent 659881e012
commit 642568bc01
6 changed files with 49 additions and 22 deletions

View File

@@ -23,9 +23,7 @@ export default function JobDocumentsComponent({ job, loading, refetch }) {
job.documents.map((doc) => { job.documents.map((doc) => {
return { return {
source: { source: {
uri: `${env.REACT_APP_CLOUDINARY_ENDPOINT}/${DetermineFileType( uri: GenerateSrcUrl(doc),
doc.type
)}/upload/${doc.key}`,
}, },
}; };
}), }),
@@ -62,11 +60,7 @@ export default function JobDocumentsComponent({ job, loading, refetch }) {
source={{ source={{
width: 100, width: 100,
height: 100, height: 100,
uri: `${ uri: GenerateThumbUrl(object.item),
env.REACT_APP_CLOUDINARY_ENDPOINT
}/${DetermineFileType(object.item.type)}/upload/${
env.REACT_APP_CLOUDINARY_THUMB_TRANSFORMATIONS
}/${object.item.key}`,
}} }}
/> />
</TouchableOpacity> </TouchableOpacity>
@@ -84,3 +78,17 @@ export default function JobDocumentsComponent({ job, loading, refetch }) {
</View> </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}`;

View File

@@ -34,9 +34,6 @@ export default function JobLines({ job, loading, refetch }) {
<DataTable.Title style={{ flex: 1 }}> <DataTable.Title style={{ flex: 1 }}>
{t("jobdetail.labels.lines_qty")} {t("jobdetail.labels.lines_qty")}
</DataTable.Title> </DataTable.Title>
<DataTable.Title style={{ flex: 1 }}>
{t("jobdetail.labels.lines_price")}
</DataTable.Title>
</DataTable.Header> </DataTable.Header>
</DataTable> </DataTable>

View File

@@ -204,7 +204,7 @@ export function UploadProgress({
forceRerender(); forceRerender();
}; };
console.log("speed", progress.speed, progress.speed !== 0);
return ( return (
<Modal <Modal
visible={progress.uploadInProgress} visible={progress.uploadInProgress}

View File

@@ -27,15 +27,8 @@ export const GET_DOCUMENTS_BY_JOB = gql`
key key
type type
takenat takenat
bill { extension
id jobid
invoice_number
date
vendor {
id
name
}
}
} }
} }
`; `;
@@ -47,6 +40,10 @@ export const INSERT_NEW_DOCUMENT = gql`
id id
name name
key key
type
takenat
extension
jobid
} }
} }
} }

View File

@@ -34,7 +34,7 @@ i18n.use(initReactI18next).init({
// have a common namespace used around the full app // have a common namespace used around the full app
// ns: ["common"], // ns: ["common"],
// defaultNS: "common", // defaultNS: "common",
debug: true, //debug: true,
// cache: { // cache: {
// enabled: true // enabled: true
// }, // },

View File

@@ -4,6 +4,7 @@ import { client } from "../graphql/client";
import { INSERT_NEW_DOCUMENT } from "../graphql/documents.queries"; import { INSERT_NEW_DOCUMENT } from "../graphql/documents.queries";
import { axiosAuthInterceptorId } from "./CleanAxios"; import { axiosAuthInterceptorId } from "./CleanAxios";
import * as MediaLibrary from "expo-media-library"; import * as MediaLibrary from "expo-media-library";
import { gql } from "@apollo/client";
//Context: currentUserEmail, bodyshop, jobid, invoiceid //Context: currentUserEmail, bodyshop, jobid, invoiceid
@@ -143,6 +144,30 @@ export const uploadToCloudinary = async (
//Insert the document with the matching key. //Insert the document with the matching key.
const documentInsert = await client.mutate({ const documentInsert = await client.mutate({
mutation: INSERT_NEW_DOCUMENT, 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: { variables: {
docInput: [ docInput: [
{ {