Skip to content

Commit 5ce34ed

Browse files
committed
feat(desktop): display rsshub route heat
1 parent 8ef045d commit 5ce34ed

File tree

4 files changed

+55
-23
lines changed

4 files changed

+55
-23
lines changed

apps/desktop/layer/renderer/src/pages/(main)/(layer)/(subview)/discover/category/[category].tsx

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ import { RecommendationContent } from "~/modules/discover/RecommendationContent"
1818
import { FeedIcon } from "~/modules/feed/feed-icon"
1919
import { Queries } from "~/queries"
2020

21-
type Language = "all" | "eng" | "cmn"
22-
type DiscoverCategories = (typeof RSSHubCategories)[number] | string
23-
2421
const LanguageMap = {
2522
all: "all",
2623
eng: "en",
@@ -29,24 +26,23 @@ const LanguageMap = {
2926

3027
type RouteData = Awaited<ReturnType<typeof apiClient.discover.rsshub.$get>>["data"]
3128

32-
const fetchRsshubPopular = (category: DiscoverCategories, lang: Language) => {
33-
return Queries.discover.rsshubCategory({
34-
// category: "popular",
35-
categories: category === "all" ? "popular" : `${category}`,
36-
lang: LanguageMap[lang],
37-
})
38-
}
3929
export const Component = () => {
4030
const { t } = useTranslation()
4131
const lang = useUISettingKey("discoverLanguage")
4232
const category = useParams().category as (typeof RSSHubCategories)[number]
4333
const title = t(`discover.category.${category}`, { ns: "common" })
4434
useSubViewTitle(title)
4535

46-
const rsshubPopular = useAuthQuery(fetchRsshubPopular(category, lang), {
47-
staleTime: 1000 * 60 * 60 * 24, // 1 day
48-
placeholderData: keepPreviousData,
49-
})
36+
const rsshubPopular = useAuthQuery(
37+
Queries.discover.rsshubCategory({
38+
categories: category === "all" ? "popular" : `${category}`,
39+
lang: LanguageMap[lang],
40+
}),
41+
{
42+
staleTime: 1000 * 60 * 60 * 24, // 1 day
43+
placeholderData: keepPreviousData,
44+
},
45+
)
5046

5147
const data: RouteData = rsshubPopular.data as any
5248
const { isLoading } = rsshubPopular
@@ -171,6 +167,11 @@ const RecommendationListItem = ({
171167
}
172168
}, [data])
173169

170+
const rsshubAnalytics = useAuthQuery(Queries.discover.rsshubAnalytics(), {
171+
staleTime: 1000 * 60 * 60 * 24, // 1 day
172+
placeholderData: keepPreviousData,
173+
})
174+
174175
return (
175176
<Card className="shadow-background border-border overflow-hidden rounded-lg border transition-shadow duration-200 hover:shadow-md">
176177
<div className="border-border flex items-center gap-3 border-b p-4">
@@ -194,7 +195,7 @@ const RecommendationListItem = ({
194195
<Link
195196
to={`/discover/category/${c}`}
196197
key={c}
197-
className={`bg-accent/10 cursor-pointer rounded-full px-2 py-0.5 duration-200 ${
198+
className={`bg-accent/10 flex cursor-pointer items-center rounded-full px-2 py-0.5 duration-200 ${
198199
!RSSHubCategories.includes(c) ? "pointer-events-none opacity-50" : ""
199200
}`}
200201
>
@@ -213,10 +214,12 @@ const RecommendationListItem = ({
213214
if (Array.isArray(routeData.path)) {
214215
routeData.path = routeData.path.find((p) => p === route) ?? routeData.path[0]
215216
}
217+
const subscriptionCount =
218+
rsshubAnalytics.data?.[`/${routePrefix}${routeData.path}`]?.subscriptionCount
216219
return (
217220
<li
218221
key={route}
219-
className="hover:bg-material-opaque -mx-4 flex items-center rounded p-2 px-5 transition-colors"
222+
className="hover:bg-material-opaque -mx-4 flex items-center gap-8 rounded p-2 px-5 transition-colors"
220223
role="button"
221224
onClick={() => {
222225
present({
@@ -232,15 +235,23 @@ const RecommendationListItem = ({
232235
})
233236
}}
234237
>
235-
<div className="bg-accent mr-2 size-1.5 rounded-full" />
236-
<div className="relative h-5 grow">
237-
<div className="absolute inset-0 flex items-center gap-2 text-sm">
238-
<EllipsisHorizontalTextWithTooltip>
239-
{routeData.name}
240-
</EllipsisHorizontalTextWithTooltip>
241-
<div className="text-text-secondary shrink-0 text-xs">{`rsshub://${routePrefix}${routeData.path}`}</div>
238+
<div className="flex flex-1 items-center gap-2">
239+
<div className="bg-accent mr-2 size-1.5 rounded-full" />
240+
<div className="relative h-5 grow">
241+
<div className="absolute inset-0 flex items-center gap-3 text-sm">
242+
<EllipsisHorizontalTextWithTooltip>
243+
{routeData.name}
244+
</EllipsisHorizontalTextWithTooltip>
245+
<EllipsisHorizontalTextWithTooltip className="text-text-secondary text-xs">{`rsshub://${routePrefix}${routeData.path}`}</EllipsisHorizontalTextWithTooltip>
246+
</div>
242247
</div>
243248
</div>
249+
{subscriptionCount && (
250+
<div className="flex items-center gap-0.5 text-xs">
251+
<i className="i-mgc-fire-cute-re" />
252+
{subscriptionCount}
253+
</div>
254+
)}
244255
</li>
245256
)
246257
})}

apps/desktop/layer/renderer/src/queries/discover.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,9 @@ export const discover = {
3939
})
4040
return res.data
4141
}),
42+
rsshubAnalytics: () =>
43+
defineQuery(["discover", "rsshub", "analytics"], async () => {
44+
const res = await apiClient.discover["rsshub-analytics"].$get()
45+
return res.data
46+
}),
4247
}

icons/mgc/fire_cute_re.svg

Lines changed: 1 addition & 0 deletions
Loading

packages/internal/shared/src/hono.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14574,6 +14574,21 @@ declare const _routes: hono_hono_base.HonoBase<Env, ({
1457414574
status: 200;
1457514575
};
1457614576
};
14577+
} & {
14578+
"/rsshub-analytics": {
14579+
$get: {
14580+
input: {};
14581+
output: {
14582+
data: {
14583+
[x: string]: {
14584+
subscriptionCount: number;
14585+
};
14586+
};
14587+
};
14588+
outputFormat: "json";
14589+
status: 200;
14590+
};
14591+
};
1457714592
}, "/discover"> | hono_types.MergeSchemaPath<hono_types.MergeSchemaPath<{
1457814593
"/": {
1457914594
$post: {

0 commit comments

Comments
 (0)