Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: enhance delete repo UX #364

Merged
merged 1 commit into from Jul 11, 2023
Merged

Conversation

sumtsui
Copy link
Contributor

@sumtsui sumtsui commented Jul 9, 2023

before:

  • no loading state for deleting a repo
  • no instant feedback after a repo deleted

after:
Jul-09-2023 15-49-10

caveat:
Directly remove deleted repo from Apollo Client cache after mutation succeeded instead of refetching repo list to provide that instant UI feedback.
https://www.apollographql.com/docs/react/data/mutations/#updating-local-data

@@ -50,14 +72,25 @@ function RepoLine({ repo, deletable, sharable, runtimeInfo, onDeleteRepo }) {
}
);

// haochen: any reason not using Loading state from useMutation?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. We should use the loading status from useMutation.

Comment on lines -212 to +265
refetchQueries: ["GetRepos"],
onCompleted() {
client.writeQuery({
query: GET_REPOS,
data: {
myRepos: repos.filter((repo) => repo.id !== clickedRepo?.id),
},
});
enqueueSnackbar("Successfully deleted repo", { variant: "success" });
},
onError() {
enqueueSnackbar("Failed to delete repo", { variant: "error" });
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need to manually update a cache here. The deleting variable is enough to achieve the black-out effect in your gif.

In my understanding, the cache-update mechanism is most useful when we want to delete the repo instantly without waiting for deleteRepo mutation returns, which isn't the case here as you are still waiting for the completion of deleteRepo mutation. I can see that the waiting for the second GET_REPOS request is avoided, but that's like reducing from 2s to 1s; not that important. The cache-update is for reducing waiting time from 1s to 0s.

I'd rather do refetchQueries to reduce the complexity of the logic. What do you think?

Copy link
Contributor Author

@sumtsui sumtsui Jul 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lihebi Good point, managing apollo cache will add logic overhead. But if we rely on refetchQueries, can't achieve UI in gif. The deleted repo will not disappear right away when deleting become false. It will disappear after refetchQueries done. so there will be some noticeable delay between success toast show and the repo disappears.

I think this behavior can seem clumsy to the user, but not a big issue, up to us to see if it is worth fixing.

In my understanding, the cache-update mechanism is most useful when we want to delete the repo instantly without waiting for deleteRepo mutation returns

actually common practice with apollo cache is to wait till the mutation api succeeded then remove cache, because the mutation might fail.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the insight. Yep, let's use this manual cache-update here.

@lihebi lihebi merged commit 6a78d32 into codepod-io:main Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants