codu icon indicating copy to clipboard operation
codu copied to clipboard

Articles not appearing as bookmarked in some cases

Open JohnAllenTech opened this issue 1 year ago • 13 comments

Context

Please provide any relevant information about your setup

Expected Behavior

Post should appear as bookmarked without a refresh

Current Behavior

Post doesnt show as bookmarked with a refresh

Screenshots

https://github.com/codu-code/codu/assets/46611809/ab3ed4ee-9f73-4f78-bda1-551f8dc779a5

Steps to reproduce

Please provide detailed steps for reproducing the issue

  1. Navigate to https://www.codu.co/articles
  2. Click on an article
  3. Click bookmark icon on the left side of the page
  4. Navigate back to the articles page by clicking the link
  5. Notice the bookmark is not present

Additional info

Provide any additional information here

JohnAllenTech avatar Apr 04 '24 20:04 JohnAllenTech

@JohnAllenTech can you plz assign this issue to me? and also add hacktoberfest label to this

hrit2773 avatar Oct 06 '24 12:10 hrit2773

I assigned you @hrit2773 Thanks.

John-Paul-Larkin avatar Oct 06 '24 12:10 John-Paul-Larkin

@hrit2773 Have you made any progress on this, or should I unassign you and make it available to someone else?

John-Paul-Larkin avatar Oct 15 '24 13:10 John-Paul-Larkin

@John-Paul-Larkin Yes I'm still working on this is it ok if I make a PR by this week itself.

hrit2773 avatar Oct 15 '24 13:10 hrit2773

@John-Paul-Larkin I would like to share my progress and get the PR done by today if you approve. Actually what's happening is that as Next.js uses caching it always shows the previous loaded page when articles route is hit back. The bookmarked value is consistently updated in the database so no problems with the data. What we can do is we can always try to refetch the status of all articles when the articles page is mounted or even if the popstate event is made. That is the solution to this bug. Your thoughts?

hrit2773 avatar Oct 18 '24 05:10 hrit2773

Screenshot 2024-10-18 125249 I changed the cacheTime to 0 and its fetching all the articles again ensuring the changes are visible when the user visits the articles link back again. What do you think @John-Paul-Larkin @JohnAllenTech it was a small bug. Can I proceed with the PR

hrit2773 avatar Oct 18 '24 07:10 hrit2773

Uh oh! @hrit2773, the image you shared is missing helpful alt text. Check https://github.com/codu-code/codu/issues/882#issuecomment-2421645691.

Alt text is an invisible description that helps screen readers describe images to blind or low-vision users. If you are using markdown to display images, add your alt text inside the brackets of the markdown image.

Learn more about alt text at Basic writing and formatting syntax: images on GitHub Docs.

github-actions[bot] avatar Oct 18 '24 07:10 github-actions[bot]

Uh oh! @hrit2773, the image you shared is missing helpful alt text. Check https://github.com/codu-code/codu/issues/882#issuecomment-2421645691.

Alt text is an invisible description that helps screen readers describe images to blind or low-vision users. If you are using markdown to display images, add your alt text inside the brackets of the markdown image.

Learn more about alt text at Basic writing and formatting syntax: images on GitHub Docs.

github-actions[bot] avatar Oct 18 '24 07:10 github-actions[bot]

Hi @hrit2773 Although setting the cache time to 0 will work, I am sure there is a more efficient way to do this. I think, instead, we can set the stale time to 0 and revalidate the query when the user returns to the page. Im not sure of the implementation of this, but my hunch is that it is a problem with a well worn solution.

John-Paul-Larkin avatar Oct 20 '24 19:10 John-Paul-Larkin

invalidating the cache when an article is bookmarked seems like the way to go to me

JohnAllenTech avatar Oct 20 '24 21:10 JohnAllenTech

👌 That sounds right John thanks. We can invalidate the query when the users bookmarks an article.

queryClient.invalidateQueries({ queryKey: ['bookmarks'] })

A query key should be added to the bookmarks query.

John-Paul-Larkin avatar Oct 20 '24 21:10 John-Paul-Larkin

@JohnAllenTech yup nice Idea and it will be a better way. I'll make a pr by today and close it

hrit2773 avatar Oct 21 '24 03:10 hrit2773

hi @hrit2773! did you get the chance to finish this? If you did could you tag the PR here? thanks

CarolinaCobo avatar Nov 11 '24 20:11 CarolinaCobo