refactor: present form modal as a hook
Signed-off-by: Innei <i@innei.in>
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { useWhoami } from "@renderer/atoms/user"
|
||||
import { useModalStack } from "@renderer/components/ui/modal"
|
||||
import { FeedForm } from "@renderer/modules/discover/feed-form"
|
||||
import { DEEPLINK_SCHEME } from "@shared/constants"
|
||||
import { useCallback } from "react"
|
||||
|
||||
import { useI18n } from "../common"
|
||||
|
||||
export const usePresentFeedFormModal = () => {
|
||||
const { present } = useModalStack()
|
||||
const me = useWhoami()
|
||||
const t = useI18n()
|
||||
return useCallback(
|
||||
(feedId: string) => {
|
||||
if (me) {
|
||||
present({
|
||||
title: t("sidebar.feed_actions.edit_feed"),
|
||||
content: ({ dismiss }) => <FeedForm asWidget id={feedId} onSuccess={dismiss} />,
|
||||
})
|
||||
} else {
|
||||
window.location.href = `${DEEPLINK_SCHEME}add?id=${feedId}`
|
||||
}
|
||||
},
|
||||
[me, present, t],
|
||||
)
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import { Button } from "@renderer/components/ui/button"
|
||||
import { ListItemHoverOverlay } from "@renderer/components/ui/list-item-hover-overlay"
|
||||
import { LoadingCircle } from "@renderer/components/ui/loading"
|
||||
import { views } from "@renderer/constants"
|
||||
import { usePresentFeedFormModal } from "@renderer/hooks/biz/useFeedFormModal"
|
||||
import { useTitle } from "@renderer/hooks/common"
|
||||
import { FeedViewType } from "@renderer/lib/enum"
|
||||
import { cn } from "@renderer/lib/utils"
|
||||
@@ -15,7 +16,6 @@ import { VideoItem } from "@renderer/modules/entry-column/Items/video-item"
|
||||
import type { UniversalItemProps } from "@renderer/modules/entry-column/types"
|
||||
import { useEntriesPreview } from "@renderer/queries/entries"
|
||||
import { useFeed } from "@renderer/queries/feed"
|
||||
import { DEEPLINK_SCHEME } from "@shared/constants"
|
||||
import type { FC } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { useParams, useSearchParams } from "react-router-dom"
|
||||
@@ -60,6 +60,7 @@ export function Component() {
|
||||
}
|
||||
const { t } = useTranslation("external")
|
||||
useTitle(feed.data?.feed.title)
|
||||
const presentFeedFormModal = usePresentFeedFormModal()
|
||||
return (
|
||||
<>
|
||||
{feed.isLoading ? (
|
||||
@@ -88,12 +89,16 @@ export function Component() {
|
||||
appName: APP_NAME,
|
||||
})}
|
||||
</div>
|
||||
<a className="mb-8 cursor-default" href={`${DEEPLINK_SCHEME}add?id=${id}`}>
|
||||
<Button>
|
||||
<span className="mb-8 cursor-default">
|
||||
<Button
|
||||
onClick={() => {
|
||||
presentFeedFormModal(id!)
|
||||
}}
|
||||
>
|
||||
<FollowIcon className="mr-1 size-3" />
|
||||
{APP_NAME}
|
||||
</Button>
|
||||
</a>
|
||||
</span>
|
||||
<div
|
||||
className={cn(
|
||||
"w-full pb-12",
|
||||
|
||||
@@ -5,14 +5,12 @@ import { FollowIcon } from "@renderer/components/icons/follow"
|
||||
import { Avatar, AvatarFallback, AvatarImage } from "@renderer/components/ui/avatar"
|
||||
import { Button } from "@renderer/components/ui/button"
|
||||
import { LoadingCircle } from "@renderer/components/ui/loading"
|
||||
import { useModalStack } from "@renderer/components/ui/modal"
|
||||
import { usePresentFeedFormModal } from "@renderer/hooks/biz/useFeedFormModal"
|
||||
import { useAuthQuery, useI18n, useTitle } from "@renderer/hooks/common"
|
||||
import { apiClient } from "@renderer/lib/api-fetch"
|
||||
import { defineQuery } from "@renderer/lib/defineQuery"
|
||||
import { cn } from "@renderer/lib/utils"
|
||||
import { FeedForm } from "@renderer/modules/discover/feed-form"
|
||||
import { useUserSubscriptionsQuery } from "@renderer/modules/profile/hooks"
|
||||
import { DEEPLINK_SCHEME } from "@shared/constants"
|
||||
import { useParams } from "react-router-dom"
|
||||
|
||||
export function Component() {
|
||||
@@ -35,7 +33,7 @@ export function Component() {
|
||||
useTitle(user.data?.name)
|
||||
const me = useWhoami()
|
||||
const isMe = user.data?.id === me?.id
|
||||
const { present } = useModalStack()
|
||||
const presentFeedFormModal = usePresentFeedFormModal()
|
||||
|
||||
return user.isLoading ? (
|
||||
<LoadingCircle size="large" className="center h-48 w-full max-w-full" />
|
||||
@@ -85,16 +83,8 @@ export function Component() {
|
||||
<Button
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
if (me) {
|
||||
present({
|
||||
title: t("sidebar.feed_actions.edit_feed"),
|
||||
content: ({ dismiss }) => (
|
||||
<FeedForm asWidget id={subscription.feedId} onSuccess={dismiss} />
|
||||
),
|
||||
})
|
||||
} else {
|
||||
window.location.href = `${DEEPLINK_SCHEME}add?id=${subscription.feeds?.id}`
|
||||
}
|
||||
|
||||
presentFeedFormModal(subscription.feedId)
|
||||
}}
|
||||
>
|
||||
{isMe ? (
|
||||
|
||||
Reference in New Issue
Block a user