Skip to content

Commit

Permalink
feat: discover rss3
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Jul 22, 2024
1 parent 2f380bf commit 070c267
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 30 deletions.
3 changes: 2 additions & 1 deletion src/renderer/src/hono.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3020,7 +3020,8 @@ declare const _routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
$get: {
input: {
query: {
category: string;
category?: string | undefined;
namespace?: string | undefined;
};
};
output: {
Expand Down
38 changes: 23 additions & 15 deletions src/renderer/src/modules/discover/content-components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
parseRegexpPathParams,
regexpPathToPath,
} from "@renderer/lib/path-parser"
import { cn } from "@renderer/lib/utils"
import { omit } from "lodash-es"
import type { FC } from "react"
import {
Expand Down Expand Up @@ -86,9 +87,13 @@ const FeedDescription = ({ description }: { description?: string }) => {
export const DiscoverFeedForm = ({
route,
routePrefix,
noDescription,
submitButtonClassName,
}: {
route: RSSHubRoute
routePrefix: string
noDescription?: boolean
submitButtonClassName?: string
}) => {
const keys = useMemo(
() =>
Expand Down Expand Up @@ -176,18 +181,20 @@ export const DiscoverFeedForm = ({
$form.querySelectorAll("input")[0]?.focus()
}, [formElRef])

const { setClickOutSideToDismiss } = useCurrentModal()
const modal = useCurrentModal()

useEffect(() => {
setClickOutSideToDismiss(!form.formState.isDirty)
}, [form.formState.isDirty, setClickOutSideToDismiss])
modal?.setClickOutSideToDismiss?.(!form.formState.isDirty)
}, [form.formState.isDirty, modal?.setClickOutSideToDismiss])
return (
<Form {...form}>
<PreviewUrl
watch={form.watch}
path={route.path}
routePrefix={`rsshub://${routePrefix}`}
/>
{!noDescription && (
<PreviewUrl
watch={form.watch}
path={route.path}
routePrefix={`rsshub://${routePrefix}`}
/>
)}
<form
className="flex flex-col gap-4"
onSubmit={form.handleSubmit(onSubmit)}
Expand All @@ -202,7 +209,7 @@ export const DiscoverFeedForm = ({

return (
<FormItem key={keyItem.name} className="flex flex-col space-y-2">
<FormLabel>
<FormLabel className="capitalize">
{keyItem.name}
{!keyItem.optional && (
<sup className="ml-1 align-sub text-red-500">*</sup>
Expand Down Expand Up @@ -247,12 +254,13 @@ export const DiscoverFeedForm = ({
</FormItem>
)
})}

<FeedDescription description={route.description} />

<FeedMaintainers maintainers={route.maintainers} />

<div className="sticky bottom-0 -mt-4 flex w-full translate-y-3 justify-end bg-theme-modal-background-opaque py-3">
{!noDescription && (
<>
<FeedDescription description={route.description} />
<FeedMaintainers maintainers={route.maintainers} />
</>
)}
<div className={cn("sticky bottom-0 -mt-4 flex w-full translate-y-3 justify-end py-3", submitButtonClassName)}>
<StyledButton type="submit">Preview</StyledButton>
</div>
</form>
Expand Down
5 changes: 0 additions & 5 deletions src/renderer/src/modules/discover/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { Image } from "@renderer/components/ui/image"
import { Input } from "@renderer/components/ui/input"
import { useModalStack } from "@renderer/components/ui/modal/stacked/hooks"
import { apiClient } from "@renderer/lib/api-fetch"
import { DEEPLINK_SCHEME } from "@shared/constants"
import { useMutation } from "@tanstack/react-query"
import { useEffect } from "react"
import { useForm } from "react-hook-form"
Expand Down Expand Up @@ -49,10 +48,6 @@ const info: Record<
label: "RSSHub Route",
prefix: "rsshub://",
},
user: {
label: "User Handle",
prefix: DEEPLINK_SCHEME,
},
}

export function DiscoverForm({ type }: { type: string }) {
Expand Down
27 changes: 27 additions & 0 deletions src/renderer/src/modules/discover/rss3-form.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { useAuthQuery } from "@renderer/hooks/common"
import { Queries } from "@renderer/queries"

import { DiscoverFeedForm } from "./content-components"

export function DiscoverRSS3() {
const { data } = useAuthQuery(
Queries.discover.rsshubNamespace({
namespace: "rss3",
}),
)

return (
<>
{data?.rss3.routes && (
<div className="w-[512px]">
<DiscoverFeedForm
routePrefix="rss3"
route={data.rss3.routes[Object.keys(data.rss3.routes)[0]]}
noDescription
submitButtonClassName="justify-center"
/>
</div>
)}
</>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import { DiscoverForm } from "@renderer/modules/discover/form"
import { DiscoverImport } from "@renderer/modules/discover/import"
import { Recommendations } from "@renderer/modules/discover/recommendations"
import { DiscoverRSS3 } from "@renderer/modules/discover/rss3-form"

export function Component() {
const tabs = [
Expand All @@ -22,15 +23,9 @@ export function Component() {
name: "RSSHub",
value: "rsshub",
},
{
name: "Follow User",
value: "user",
disabled: true,
},
{
name: "RSS3",
value: "rss3",
disabled: true,
},
{
name: "Email",
Expand Down Expand Up @@ -60,9 +55,11 @@ export function Component() {
</TabsList>
{tabs.map((tab) => (
<TabsContent key={tab.name} value={tab.name} className="mt-8">
{tab.value === "import" ?
{tab.value === "import" ? (
<DiscoverImport />
) : tab.value === "rss3" ?
(
<DiscoverImport />
<DiscoverRSS3 />
) :
(
<DiscoverForm type={tab.value} />
Expand Down
15 changes: 14 additions & 1 deletion src/renderer/src/queries/discover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,25 @@ export const discover = {
}: {
category: string
}) =>
defineQuery(["discover", "rsshub", category], async () => {
defineQuery(["discover", "rsshub", "category", category], async () => {
const res = await apiClient.discover.rsshub.$get({
query: {
category,
},
})
return res.data
}),
rsshubNamespace: ({
namespace,
}: {
namespace: string
}) =>
defineQuery(["discover", "rsshub", "namespace", namespace], async () => {
const res = await apiClient.discover.rsshub.$get({
query: {
namespace,
},
})
return res.data
}),
}

0 comments on commit 070c267

Please sign in to comment.