-
Notifications
You must be signed in to change notification settings - Fork 30
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
refactor(app-project): optimistic updates for YourProjectStats #6589
base: master
Are you sure you want to change the base?
refactor(app-project): optimistic updates for YourProjectStats #6589
Conversation
Changes unknown |
ebf5eda
to
dc36edd
Compare
b67622b
to
d2f8c54
Compare
- [x] a new module-scoped function, `mutate`, in the `useYourProjectStats` module. `mutate` is generated each time that stats data is fetched from ERAS, and can be used to update the fetched stats. - [x] a new export from the `useYourProjectStats` module. `updateYourStats` runs an optimistic update of your stats, incrementing both counts when you press Done or Done & Talk, without revalidating the SWR cache.
d2f8c54
to
68d31d4
Compare
This is a very jargon-laden way of saying it adds 1 to each of your total stats counts. |
export default function useYourProjectStats({ projectID, userID }) { | ||
const token = usePanoptesAuthToken() | ||
|
||
// only fetch stats when a userID is available. Don't fetch if no user signed in. | ||
const key = token && userID ? { endpoint, projectID, userID, token } : null | ||
return useSWR(key, fetchStats, SWROptions) | ||
const fetchedStats = useSWR(key, fetchStats, SWROptions) | ||
mutate = fetchedStats.mutate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does anyone know what mutate
evaluates to here when the key is null? The old stats code kept a running count of classifications in the current tab, if you weren’t logged in. Just so you’d have some visible feedback that your classification had been saved, after you pressed Done.
mutate
, in theuseYourProjectStats
module.mutate
is generated each time that stats data is fetched from ERAS, and bound to the current cache key. It can be used to update the fetched stats.useYourProjectStats
module.updateYourStats
runs an optimistic update of your stats for the current cache key, incrementing both counts when you press Done or Done & Talk, without revalidating the SWR cache.Please request review from
@zooniverse/frontend
team or an individual member of that team.Package
Linked Issue and/or Talk Post
How to Review
https://local.zooniverse.org:3000/projects/eatyourgreens/-project-testing-ground/classify/workflow/3599?env=staging
You should see your stats increment instantly after each classification, but the fetched stats aren't revalidated (there won't be any HTTP requests to
eras.zooniverse.org
.)Checklist
PR Creator - Please cater the checklist to fit the review needed for your code changes.
PR Reviewer - Use the checklist during your review. Each point should be checkmarked or discussed before PR approval.
General
yarn panic && yarn bootstrap
ordocker-compose up --build
and FEM works as expectedGeneral UX
Example Staging Project: i-fancy-cats
Bug Fix