Skip to content

Commit

Permalink
feat: add Boost feed status query and mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
lawvs committed Oct 23, 2024
1 parent 2757763 commit 4f11046
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions apps/renderer/src/queries/boosts.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { useMutation } from "@tanstack/react-query"
import { toast } from "sonner"

import { apiClient } from "~/lib/api-fetch"
import { defineQuery } from "~/lib/defineQuery"
import { toastFetchError } from "~/lib/error-parser"

export const boosts = {
getStatus: ({ feedId }: { feedId: string }) =>
defineQuery(["boostFeed", feedId], async () => {
const res = await apiClient.boosts.$get({
query: {
feedId,
},
})
return res.data
}),
}

export const useBoostFeedMutation = () =>
useMutation({
mutationKey: ["boostFeed"],
mutationFn: (data: Parameters<typeof apiClient.boosts.$post>[0]["json"]) =>
apiClient.boosts.$post({ json: data }),
onError(err) {
toastFetchError(err)
},
onSuccess(_, variables) {
boosts.getStatus({ feedId: variables.feedId }).invalidate()
window.analytics?.capture("boost_sent", {
amount: variables.amount,
feedId: variables.feedId,
})
toast("🎉 Boosted.")
},
})

0 comments on commit 4f11046

Please sign in to comment.