-
Notifications
You must be signed in to change notification settings - Fork 41
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
Conversation
@ShiboSoftwareDev review this one |
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.
just a video and your good to go nice job
@Abse2001 yeah sure 20250110001535.mp4 |
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.
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
await axios.post("/snippets/remove_star", { | ||
snippet_id: snippet!.snippet_id, | ||
}) | ||
setIsStarred(false) |
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.
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) |
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.
don't use useState
for the is_starred state, instead use an optimistic update or just wait for the invalidation
fixes #509