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

refactor(app-project): optimistic updates for YourProjectStats #6589

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

eatyourgreens
Copy link
Contributor

@eatyourgreens eatyourgreens commented Dec 20, 2024

  • a new module-scoped bound function, mutate, in the useYourProjectStats 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.
  • a new export from the 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

  • app-project

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

  • Tests are passing locally and on Github
  • Documentation is up to date and changelog has been updated if appropriate
  • You can yarn panic && yarn bootstrap or docker-compose up --build and FEM works as expected
  • FEM works in all major desktop browsers: Firefox, Chrome, Edge, Safari (Use Browserstack account as needed)
  • FEM works in a mobile browser

General UX

Example Staging Project: i-fancy-cats

  • All pages of a FEM project load: Home Page, Classify Page, and About Pages
  • Can submit a classification
  • Can sign-in and sign-out
  • The component is accessible

Bug Fix

  • The PR creator has listed user actions to use when testing if bug is fixed
  • The bug is fixed
  • Unit tests are added or updated

@coveralls
Copy link

coveralls commented Dec 20, 2024

Coverage Status

Changes unknown
when pulling 68d31d4 on eatyourgreens:optimistic-project-stats
into ** on zooniverse:master**.

@eatyourgreens eatyourgreens marked this pull request as ready for review December 20, 2024 08:57
@eatyourgreens eatyourgreens force-pushed the optimistic-project-stats branch from ebf5eda to dc36edd Compare December 20, 2024 08:57
@eatyourgreens eatyourgreens force-pushed the optimistic-project-stats branch 2 times, most recently from b67622b to d2f8c54 Compare December 20, 2024 09:49
- [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.
@eatyourgreens
Copy link
Contributor Author

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.

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
Copy link
Contributor Author

@eatyourgreens eatyourgreens Dec 20, 2024

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.

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.

Your Stats makes an expensive GET request on every classification
2 participants