Skip to content

Commit

Permalink
fix: feed claim action
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Sep 10, 2024
1 parent 6e36232 commit 4a814ee
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions src/renderer/src/store/feed/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")(() => ({
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4a814ee

Please sign in to comment.