feat(desktop): recommend analytics view in subscription form
This commit is contained in:
@@ -11,7 +11,6 @@ import {
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@follow/components/ui/select/index.jsx"
|
||||
import { FeedViewType } from "@follow/constants"
|
||||
import { nextFrame } from "@follow/utils/dom"
|
||||
import {
|
||||
MissingOptionalParamError,
|
||||
@@ -38,7 +37,6 @@ import {
|
||||
useIsTopModal,
|
||||
useModalStack,
|
||||
} from "~/components/ui/modal/stacked/hooks"
|
||||
import { getViewFromRoute } from "~/lib/utils"
|
||||
|
||||
import { FeedForm } from "./feed-form"
|
||||
import type { RSSHubRoute } from "./types"
|
||||
@@ -190,20 +188,10 @@ export const DiscoverFeedForm = ({
|
||||
|
||||
const finalUrl = routeParams && routeParamsPath ? `${url}/${routeParamsPath}` : url
|
||||
|
||||
const defaultView = getViewFromRoute(route) || FeedViewType.Articles
|
||||
|
||||
present({
|
||||
title: t("feed_form.add_feed"),
|
||||
modalContentClassName: "overflow-visible",
|
||||
content: () => (
|
||||
<FeedForm
|
||||
url={finalUrl}
|
||||
defaultValues={{
|
||||
view: defaultView.toString(),
|
||||
}}
|
||||
onSuccess={dismissAll}
|
||||
/>
|
||||
),
|
||||
content: () => <FeedForm url={finalUrl} onSuccess={dismissAll} />,
|
||||
})
|
||||
} catch (err: unknown) {
|
||||
if (err instanceof MissingOptionalParamError) {
|
||||
|
||||
@@ -12,7 +12,6 @@ import { setPreviewBackPath } from "~/atoms/preview"
|
||||
import { Media } from "~/components/ui/media"
|
||||
import { useFollow } from "~/hooks/biz/useFollow"
|
||||
import { navigateEntry } from "~/hooks/biz/useNavigateEntry"
|
||||
import { getRouteParams } from "~/hooks/biz/useRouteParams"
|
||||
import { useFeedSafeUrl } from "~/hooks/common/useFeedSafeUrl"
|
||||
import type { apiClient } from "~/lib/api-fetch"
|
||||
import { useSubscriptionByFeedId } from "~/store/subscription"
|
||||
@@ -136,9 +135,6 @@ export const FeedCard: FC<{
|
||||
isList: !!item.list?.id,
|
||||
id: item.list?.id || item.feed?.id,
|
||||
url: item.feed?.url,
|
||||
defaultValues: {
|
||||
view: getRouteParams().view.toString(),
|
||||
},
|
||||
onSuccess() {
|
||||
onSuccess?.(item)
|
||||
},
|
||||
|
||||
@@ -27,6 +27,7 @@ import { z } from "zod"
|
||||
|
||||
import { Autocomplete } from "~/components/ui/auto-completion"
|
||||
import { useCurrentModal, useIsInModal } from "~/components/ui/modal/stacked/hooks"
|
||||
import { getRouteParams } from "~/hooks/biz/useRouteParams"
|
||||
import { useAuthQuery, useI18n } from "~/hooks/common"
|
||||
import { apiClient } from "~/lib/api-fetch"
|
||||
import { tipcClient } from "~/lib/client"
|
||||
@@ -48,15 +49,13 @@ const formSchema = z.object({
|
||||
})
|
||||
export type FeedFormDataValuesType = z.infer<typeof formSchema>
|
||||
|
||||
const defaultValue = { view: FeedViewType.Articles.toString() } as FeedFormDataValuesType
|
||||
|
||||
export const FeedForm: Component<{
|
||||
url?: string
|
||||
id?: string
|
||||
defaultValues?: FeedFormDataValuesType
|
||||
|
||||
onSuccess?: () => void
|
||||
}> = ({ id: _id, defaultValues = defaultValue, url, onSuccess }) => {
|
||||
}> = ({ id: _id, defaultValues, url, onSuccess }) => {
|
||||
const queryParams = { id: _id, url }
|
||||
|
||||
const feedQuery = useFeedQuery(queryParams)
|
||||
@@ -189,7 +188,9 @@ const FeedInnerForm = ({
|
||||
|
||||
const form = useForm<z.infer<typeof formSchema>>({
|
||||
resolver: zodResolver(formSchema),
|
||||
defaultValues,
|
||||
defaultValues: defaultValues || {
|
||||
view: getRouteParams().view.toString() || FeedViewType.Articles.toString(),
|
||||
},
|
||||
})
|
||||
|
||||
const { setClickOutSideToDismiss, dismiss } = useCurrentModal()
|
||||
@@ -207,6 +208,12 @@ const FeedInnerForm = ({
|
||||
}
|
||||
}, [subscription])
|
||||
|
||||
useEffect(() => {
|
||||
if (analytics?.view !== undefined && !subscription && defaultValues?.view === undefined) {
|
||||
form.setValue("view", `${analytics.view}`)
|
||||
}
|
||||
}, [analytics, subscription, defaultValues?.view])
|
||||
|
||||
const followMutation = useMutation({
|
||||
mutationFn: async (values: z.infer<typeof formSchema>) => {
|
||||
const body = {
|
||||
|
||||
@@ -24,7 +24,6 @@ import { z } from "zod"
|
||||
|
||||
import { useIsInMASReview } from "~/atoms/server-configs"
|
||||
import { useModalStack } from "~/components/ui/modal/stacked/hooks"
|
||||
import { getRouteParams } from "~/hooks/biz/useRouteParams"
|
||||
import { apiClient } from "~/lib/api-fetch"
|
||||
|
||||
import { FeedCard } from "./feed-card"
|
||||
@@ -126,18 +125,9 @@ export function DiscoverForm({ type = "search" }: { type?: string }) {
|
||||
|
||||
function onSubmit(values: z.infer<typeof formSchema>) {
|
||||
if (info[type]!.showModal) {
|
||||
const defaultView = getRouteParams().view
|
||||
present({
|
||||
title: t("feed_form.add_feed"),
|
||||
content: () => (
|
||||
<FeedForm
|
||||
url={values.keyword}
|
||||
defaultValues={{
|
||||
view: defaultView.toString(),
|
||||
}}
|
||||
onSuccess={dismissAll}
|
||||
/>
|
||||
),
|
||||
content: () => <FeedForm url={values.keyword} onSuccess={dismissAll} />,
|
||||
})
|
||||
} else {
|
||||
mutation.mutate(values)
|
||||
|
||||
@@ -54,15 +54,7 @@ const CmdNPanel = () => {
|
||||
present({
|
||||
title: t("feed_form.add_feed"),
|
||||
modalContentClassName: "overflow-visible",
|
||||
content: () => (
|
||||
<FeedForm
|
||||
url={url}
|
||||
defaultValues={{
|
||||
view: defaultView.toString(),
|
||||
}}
|
||||
onSuccess={dismissAll}
|
||||
/>
|
||||
),
|
||||
content: () => <FeedForm url={url} onSuccess={dismissAll} />,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user