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

fix star button working #518

Merged
merged 1 commit into from
Jan 10, 2025
Merged

fix star button working #518

merged 1 commit into from
Jan 10, 2025

Conversation

techmannih
Copy link
Contributor

fixes #509

@techmannih
Copy link
Contributor Author

@ShiboSoftwareDev review this one

Copy link
Contributor

@Abse2001 Abse2001 left a comment

Choose a reason for hiding this comment

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

just a video and your good to go nice job

@techmannih
Copy link
Contributor Author

@Abse2001 yeah sure

20250110001535.mp4

@Abse2001 Abse2001 self-requested a review January 9, 2025 19:01
Copy link
Contributor

@seveibar seveibar left a comment

Choose a reason for hiding this comment

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

i'm not sure i like having an unnecessary useState, an optimistic update is a better fit for this scenario, but i guess it's fine

https://tanstack.com/query/v4/docs/framework/react/guides/optimistic-updates#updating-a-list-of-todos-when-adding-a-new-todo

await axios.post("/snippets/remove_star", {
snippet_id: snippet!.snippet_id,
})
setIsStarred(false)
Copy link
Contributor

Choose a reason for hiding this comment

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

use qc.invalidateQueries(["snippets", snippet?.snippet_id]) (or whatever the query key is)

@@ -16,6 +16,7 @@ export default function ViewSnippetHeader() {
const axios = useAxios()
const qc = useQueryClient()
const session = useGlobalStore((s) => s.session)
const [isStarred, setIsStarred] = useState(snippet?.is_starred || false)
Copy link
Contributor

Choose a reason for hiding this comment

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

don't use useState for the is_starred state, instead use an optimistic update or just wait for the invalidation

https://tanstack.com/query/v4/docs/framework/react/guides/optimistic-updates#updating-a-list-of-todos-when-adding-a-new-todo

@seveibar seveibar merged commit 7385c8e into tscircuit:main Jan 10, 2025
5 checks passed
@techmannih techmannih deleted the star branch January 24, 2025 20:04
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.

there is no indication that you starred the snippet
3 participants