Skip to content

Commit 9b0691a

Browse files
committed
fix(desktop): follow state for url
1 parent 72ed7df commit 9b0691a

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

apps/desktop/layer/renderer/src/hooks/biz/useFollow.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { FeedForm } from "~/modules/discover/FeedForm"
1313
import type { ListFormDataValuesType } from "~/modules/discover/ListForm"
1414
import { ListForm } from "~/modules/discover/ListForm"
1515
import {
16-
getSubscriptionByFeedId,
16+
getSubscriptionByFeedIdOrUrl,
1717
useFeedSubscriptionCount,
1818
useListSubscriptionCount,
1919
} from "~/store/subscription"
@@ -73,10 +73,12 @@ export const useFollow = () => {
7373
} else {
7474
canFollowMoreInboxAndNotify("feed")
7575
}
76-
let isFollowed = false
77-
if (options?.id) {
78-
isFollowed = !!getSubscriptionByFeedId(options.id)
79-
}
76+
77+
const subscription = getSubscriptionByFeedIdOrUrl({
78+
id: options?.id,
79+
url: options?.url,
80+
})
81+
const isFollowed = !!subscription
8082

8183
present({
8284
title: `${isFollowed ? `${t("common:words.edit")} ` : ""}${options?.isList ? t("words.lists") : t("words.feeds")}`,

apps/desktop/layer/renderer/src/store/feed/store.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { FeedService } from "~/services"
1515
import { getSubscriptionByFeedId } from "../subscription"
1616
import { userActions } from "../user"
1717
import { createImmerSetter, createTransaction, createZustandStore } from "../utils/helper"
18+
import { feedByIdOrUrlSelector } from "./selector"
1819
import type { FeedQueryParams, FeedState } from "./types"
1920

2021
export const useFeedStore = createZustandStore<FeedState>("feed")(() => ({
@@ -142,6 +143,9 @@ export const feedActions = new FeedActions()
142143

143144
export const getFeedById = (feedId: string): Nullable<FeedOrListRespModel> =>
144145
useFeedStore.getState().feeds[feedId]
146+
export const getFeedByIdOrUrl = (feed: FeedQueryParams): Nullable<FeedOrListRespModel> => {
147+
return feedByIdOrUrlSelector(feed)(get())
148+
}
145149

146150
export const getPreferredTitle = (
147151
feed?: Pick<FeedOrListRespModel, "type" | "id" | "title"> | null,

apps/desktop/layer/renderer/src/store/subscription/getters.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import type { FeedViewType } from "@follow/constants"
22

3+
import type { FeedQueryParams } from "../feed"
4+
import { getFeedByIdOrUrl } from "../feed"
35
import {
46
folderFeedsByFeedIdSelector,
57
subscriptionByViewSelector,
@@ -12,6 +14,11 @@ export const getSubscriptionByFeedId = (feedId: FeedId) => {
1214
const state = get()
1315
return state.data[feedId]
1416
}
17+
export const getSubscriptionByFeedIdOrUrl = (params: FeedQueryParams) => {
18+
const feed = getFeedByIdOrUrl(params)
19+
if (!feed) return
20+
return getSubscriptionByFeedId(feed.id)
21+
}
1522

1623
export const isListSubscription = (feedId?: FeedId) => {
1724
if (!feedId) return false

0 commit comments

Comments
 (0)