Skip to content

Commit

Permalink
fix: discover form should preview twice when has optional value
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <[email protected]>
  • Loading branch information
Innei committed Jul 31, 2024
1 parent 79b26a0 commit f0f8185
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const FeedDescription = ({ description }: { description?: string }) => {
The description of this feed is as follows, and you can fill out the
parameter form with the relevant information.
</p>
<Markdown className="my-4 w-full max-w-full cursor-text select-text">
<Markdown className="my-4 w-full max-w-full cursor-text select-text break-all">
{description}
</Markdown>
</>
Expand Down Expand Up @@ -116,7 +116,9 @@ export const DiscoverFeedForm = ({
...Object.fromEntries(
keys.array.map((keyItem) => [
keyItem.name,
keyItem.optional ? z.string().optional() : z.string().min(1),
keyItem.optional ?
z.string().optional().nullable() :
z.string().min(1),
]),
),
}),
Expand All @@ -133,6 +135,7 @@ export const DiscoverFeedForm = ({
}
return ret
}, [route.parameters])

const form = useForm<z.infer<typeof dynamicFormSchema>>({
resolver: zodResolver(dynamicFormSchema),
defaultValues: defaultValue,
Expand All @@ -146,7 +149,8 @@ export const DiscoverFeedForm = ({
try {
const fillRegexpPath = regexpPathToPath(route.path, data)
const url = `rsshub://${routePrefix}${fillRegexpPath}`
const defaultView = getViewFromRoute(route) || getSidebarActiveView() as FeedViewType
const defaultView =
getViewFromRoute(route) || (getSidebarActiveView() as FeedViewType)

present({
title: "Add Feed",
Expand Down Expand Up @@ -185,7 +189,7 @@ export const DiscoverFeedForm = ({

useEffect(() => {
modal?.setClickOutSideToDismiss?.(!form.formState.isDirty)
}, [form.formState.isDirty, modal?.setClickOutSideToDismiss])
}, [form.formState.isDirty, modal, modal.setClickOutSideToDismiss])

return (
<Form {...form}>
Expand Down Expand Up @@ -261,7 +265,12 @@ export const DiscoverFeedForm = ({
<FeedMaintainers maintainers={route.maintainers} />
</>
)}
<div className={cn("sticky bottom-0 -mt-4 mb-1 flex w-full translate-y-3 justify-end py-3", submitButtonClassName)}>
<div
className={cn(
"sticky bottom-0 -mt-4 mb-1 flex w-full translate-y-3 justify-end py-3",
submitButtonClassName,
)}
>
<StyledButton type="submit">Preview</StyledButton>
</div>
</form>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DiscoverFeedForm } from "./content-components"
import { DiscoverFeedForm } from "./DiscoverFeedForm"
import type { RSSHubRoute } from "./types"

export const RecommendationContent = ({
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/modules/discover/rss3-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { LoadingCircle } from "@renderer/components/ui/loading"
import { useAuthQuery } from "@renderer/hooks/common"
import { Queries } from "@renderer/queries"

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

export function DiscoverRSS3() {
const { data, isLoading } = useAuthQuery(
Expand Down

0 comments on commit f0f8185

Please sign in to comment.