Skip to content

Commit

Permalink
feat: popular card in discover page
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Jun 24, 2024
1 parent 5278c16 commit 48d141a
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 13 deletions.
28 changes: 28 additions & 0 deletions src/renderer/src/hono.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,34 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
status: 200;
};
};
"/discover/rsshub": {
$get: {
input: {
query: {
category: string;
};
};
output: {
data: Record<string, {
description: string;
name: string;
url: string;
routes: Record<string, {
path: string;
example: string;
description: string;
name: string;
categories: string[];
parameters: Record<string, string>;
maintainers: string[];
location: string;
}>;
}>;
};
outputFormat: "json";
status: 200;
};
};
} & {
"/auth-app/new-session": {
$post: {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/modules/discover/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const info: Record<
prefix?: string
}
> = {
general: {
search: {
label: "Any URL or Keyword",
},
rss: {
Expand Down
48 changes: 42 additions & 6 deletions src/renderer/src/modules/discover/recommendations.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,47 @@
export function Recommendations({ type: _type }: { type: string }) {
import { SiteIcon } from "@renderer/components/site-icon"
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@renderer/components/ui/card"
import { useBizQuery } from "@renderer/hooks"
import { Queries } from "@renderer/queries"

export function Recommendations() {
const rsshubPopular = useBizQuery(Queries.discover.rsshubCategory({
category: "popular",
}))

return (
<div className="mt-8">
<div className="text-lg font-medium">Suggested</div>
<ul className="mt-2">
<li>Suggestions1</li>
<li>Suggestions2</li>
</ul>
<div className="text-center text-lg font-medium">Popular</div>
{rsshubPopular.data && (
<div className="mt-4 grid grid-cols-3 gap-4">
{Object.keys(rsshubPopular.data).map((key) => (
<Card key={key}>
<CardHeader className="p-5 pb-3">
<CardTitle className="flex items-center text-base">
<SiteIcon
url={`https://${rsshubPopular.data[key].url}`}
/>
{rsshubPopular.data[key].name}
</CardTitle>
</CardHeader>
<CardContent className="p-5 pt-0">
<CardDescription>
<ul className="space-y-1">
{Object.keys(rsshubPopular.data[key].routes).map((route) => (
<li key={route} className="transition-colors hover:font-medium hover:text-zinc-800">{rsshubPopular.data[key].routes[route].name}</li>
))}
</ul>
</CardDescription>
</CardContent>
</Card>
))}
</div>
)}
</div>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { Recommendations } from "@renderer/modules/discover/recommendations"
export function Component() {
const tabs = [
{
name: "General",
value: "general",
name: "Search",
value: "search",
},
{
name: "RSS",
Expand Down Expand Up @@ -44,9 +44,9 @@ export function Component() {
]

return (
<div className="flex w-full flex-col items-center justify-center gap-8 overflow-y-auto">
<div className="flex w-full flex-col items-center gap-8 overflow-y-auto pb-10 pt-40">
<div className="text-2xl font-bold">Discover</div>
<Tabs defaultValue="General">
<Tabs defaultValue="Search">
<TabsList className="w-full">
{tabs.map((tab) => (
<TabsTrigger
Expand All @@ -59,18 +59,18 @@ export function Component() {
))}
</TabsList>
{tabs.map((tab) => (
<TabsContent key={tab.name} value={tab.name} className="mt-8 h-96">
<TabsContent key={tab.name} value={tab.name} className="mt-8">
{tab.value === "import" ?
(
<DiscoverImport />
) :
(
<DiscoverForm type={tab.value} />
)}
<Recommendations type={tab.value} />
</TabsContent>
))}
</Tabs>
<Recommendations />
</div>
)
}
18 changes: 18 additions & 0 deletions src/renderer/src/queries/discover.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { apiClient } from "@renderer/lib/api-fetch"
import { defineQuery } from "@renderer/lib/defineQuery"

export const discover = {
rsshubCategory: ({
category,
}: {
category: string
}) =>
defineQuery(["discover", "rsshub", category], async () => {
const res = await apiClient.discover.rsshub.$get({
query: {
category,
},
})
return res.data
}),
}
2 changes: 2 additions & 0 deletions src/renderer/src/queries/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { action } from "./actions"
import { ai } from "./ai"
import { auth } from "./auth"
import { discover } from "./discover"
import { entries } from "./entries"
import { feed } from "./feed"
import { subscription } from "./subscriptions"
Expand All @@ -12,4 +13,5 @@ export const Queries = {
action,
auth,
ai,
discover,
}

0 comments on commit 48d141a

Please sign in to comment.