fix: feed claim action

Signed-off-by: Innei <i@innei.in>
This commit is contained in:
Innei 2024-09-10 21:26:17 +08:00
parent 6e36232b41
commit 4a814ee917
No known key found for this signature in database
GPG Key ID: 0F62D33977F021F7
1 changed files with 13 additions and 18 deletions

View File

@ -7,7 +7,7 @@ import { produce } from "immer"
import { nanoid } from "nanoid"
import { getSubscriptionByFeedId } from "../subscription"
import { createZustandStore, doMutationAndTransaction } from "../utils/helper"
import { createZustandStore } from "../utils/helper"
import type { FeedQueryParams, FeedState } from "./types"
export const useFeedStore = createZustandStore<FeedState>("feed")(() => ({
@ -61,24 +61,19 @@ class FeedActions {
}
async claimFeed(feedId: string) {
await doMutationAndTransaction(
() =>
apiClient.feeds.claim.challenge.$post({
json: {
feedId,
},
}),
async () => {
const currentUser = whoami()
if (!currentUser) return
this.updateFeedOwnership(feedId, currentUser.id)
const feed = get().feeds[feedId]
if (!feed) return
await FeedService.upsert(feed)
await apiClient.feeds.claim.challenge.$post({
json: {
feedId,
},
{ doTranscationWhenMutationFail: false, waitMutation: true },
)
})
runTransactionInScope(async () => {
const currentUser = whoami()
if (!currentUser) return
this.updateFeedOwnership(feedId, currentUser.id)
const feed = get().feeds[feedId]
if (!feed) return
await FeedService.upsert(feed)
})
}
// API Fetcher