Skip to content

Commit

Permalink
Refactor Apollo onCompleted callbacks
Browse files Browse the repository at this point in the history
This resolves the issue described at apollographql/apollo-client#6301

Perform Yarn upgrade. Bump minor version.
  • Loading branch information
bengal75 committed Jun 28, 2020
1 parent ed7dec9 commit 11ed248
Show file tree
Hide file tree
Showing 5 changed files with 1,480 additions and 1,374 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "@cecilian-archives/uploader",
"version": "2.6.3",
"version": "2.7.0",
"author": {
"name": "Ben Galloway",
"email": "[email protected]"
},
"private": true,
"dependencies": {
"@apollo/client": "3.0.0-beta.45",
"@apollo/client": "3.0.0-rc.9",
"@date-io/date-fns": "1.3.13",
"@material-ui/core": "^4.9.7",
"@material-ui/icons": "^4.9.1",
Expand All @@ -19,13 +19,13 @@
"date-fns": "^2.13.0",
"firebase": "^7.14.2",
"graphql": "^14.6.0",
"history": "^5.0.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-firebaseui": "^4.1.0",
"react-image": "^3.0.3",
"react-image-crop": "^8.6.2",
"react-router": "^6.0.0-alpha.2",
"react-router-dom": "^6.0.0-alpha.2",
"react-router-dom": "^6.0.0-beta.0",
"react-scripts": "3.4.1"
},
"scripts": {
Expand Down
28 changes: 19 additions & 9 deletions src/components/person/LoadPersonTags.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,8 @@ const LoadPersonTags = ({
const classes = useStyles();
const [statusToDisplay, setStatusToDisplay] = React.useState("");

const [getPerson, { loading, error, data }] = useLazyQuery(GET_PERSON, {
variables: { personId: currentPerson?.person?.id },
fetchPolicy: "network-only",
errorPolicy: "none",
partialRefetch: true,
returnPartialData: true,
notifyOnNetworkStatusChange: true,
onCompleted: () => {
const queryCompleted = React.useCallback(
(data) => {
const tags = data?.getCecilianById?.tags || [];
setStatusToDisplay(
`Loaded tags for ${currentPerson.person.name}${
Expand All @@ -102,11 +96,27 @@ const LoadPersonTags = ({
);
successCallback && successCallback(tags);
},
onError: () => {
[setStatusToDisplay, successCallback, currentPerson]
);

const queryErrored = React.useCallback(
(error) => {
setStatusToDisplay(
`Could not load tags for ${currentPerson?.person?.name}. Error was: ${error}`
);
},
[setStatusToDisplay, currentPerson]
);

const [getPerson, { loading }] = useLazyQuery(GET_PERSON, {
variables: { personId: currentPerson?.person?.id },
fetchPolicy: "network-only",
errorPolicy: "none",
partialRefetch: true,
returnPartialData: true,
notifyOnNetworkStatusChange: true,
onCompleted: queryCompleted,
onError: queryErrored,
});

const getPersonData = () => {
Expand Down
17 changes: 7 additions & 10 deletions src/components/root/MinutesPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,13 @@ const MinutesPage = () => {
const [uploadCompleted, setUploadCompleted] = React.useState(false);
const [uploadError, setUploadError] = React.useState(false);

const [addArchiveItem, { loading, error, data }] = useMutation(
ADD_ARCHIVE_ITEM,
{
onCompleted: () => {
setUploadCompleted(true);
console.log(`Successful upload: ${data.id}`);
},
onError: () => setUploadError(error),
}
);
const [addArchiveItem, { loading }] = useMutation(ADD_ARCHIVE_ITEM, {
onCompleted: (data) => {
setUploadCompleted(true);
console.log(`Successful upload: ${data.setArchiveItem.id}`);
},
onError: (error) => setUploadError(error),
});

const resetState = async () => {
await uppy.reset();
Expand Down
17 changes: 7 additions & 10 deletions src/components/root/PhotosPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,13 @@ const PhotosPage = () => {
autoProceed: true,
});

const [addArchiveItem, { loading, error, data }] = useMutation(
ADD_ARCHIVE_ITEM,
{
onCompleted: () => {
setUploadCompleted(true);
console.log(`Successful upload: ${data.id}`);
},
onError: () => setUploadError(error),
}
);
const [addArchiveItem, { loading }] = useMutation(ADD_ARCHIVE_ITEM, {
onCompleted: (data) => {
setUploadCompleted(true);
console.log(`Successful upload: ${data.setArchiveItem.id}`);
},
onError: (error) => setUploadError(error),
});

const resetState = async () => {
await uppy.reset();
Expand Down
Loading

0 comments on commit 11ed248

Please sign in to comment.