refactor: simplify useTipModal parameter handling
This commit is contained in:
@@ -173,11 +173,7 @@ export const useEntryActions = ({
|
||||
} as CombinedEntryModel
|
||||
}, [entry, feed, inbox])
|
||||
|
||||
const openTipModal = useTipModal({
|
||||
userId: populatedEntry?.feeds?.ownerUserId ?? undefined,
|
||||
feedId: populatedEntry?.feeds?.id ?? undefined,
|
||||
entryId: populatedEntry?.entries.id ?? undefined,
|
||||
})
|
||||
const openTipModal = useTipModal()
|
||||
|
||||
const showSourceContent = useShowSourceContent()
|
||||
const showSourceContentModal = useSourceContentModal()
|
||||
@@ -210,7 +206,13 @@ export const useEntryActions = ({
|
||||
className: "i-mgc-power-outline",
|
||||
hide: isInbox || feed?.ownerUserId === whoami()?.id,
|
||||
onClick: () => {
|
||||
nextFrame(openTipModal)
|
||||
nextFrame(() =>
|
||||
openTipModal({
|
||||
userId: populatedEntry?.feeds?.ownerUserId ?? undefined,
|
||||
feedId: populatedEntry?.feeds?.id ?? undefined,
|
||||
entryId: populatedEntry?.entries.id ?? undefined,
|
||||
}),
|
||||
)
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -21,11 +21,7 @@ export const SupportCreator = ({ entryId }: { entryId: string }) => {
|
||||
const feed = useFeedById(entry?.feedId)
|
||||
const { data: feedBoosters } = useFeedBoostersQuery(entry?.feedId)
|
||||
|
||||
const openTipModal = useTipModal({
|
||||
userId: feed?.ownerUserId ?? undefined,
|
||||
feedId: entry?.feedId,
|
||||
entryId,
|
||||
})
|
||||
const openTipModal = useTipModal()
|
||||
const openBoostModal = useBoostModal()
|
||||
|
||||
const isMyOwnedFeed = feed?.ownerUserId === useWhoami()?.id
|
||||
@@ -60,7 +56,15 @@ export const SupportCreator = ({ entryId }: { entryId: string }) => {
|
||||
|
||||
<div className="flex items-center gap-4">
|
||||
{!isMyOwnedFeed && (
|
||||
<Button onClick={() => openTipModal()}>
|
||||
<Button
|
||||
onClick={() =>
|
||||
openTipModal({
|
||||
userId: feed.ownerUserId ?? undefined,
|
||||
feedId: entry?.feedId,
|
||||
entryId,
|
||||
})
|
||||
}
|
||||
>
|
||||
<i className="i-mgc-power-outline mr-1.5 text-lg" />
|
||||
{t("entry_content.support_creator")}
|
||||
</Button>
|
||||
|
||||
@@ -6,27 +6,22 @@ import { useModalStack } from "~/components/ui/modal/stacked/hooks"
|
||||
|
||||
import { TipModalContent } from "./tip-modal"
|
||||
|
||||
export const useTipModal = ({
|
||||
userId,
|
||||
feedId,
|
||||
entryId,
|
||||
}: {
|
||||
userId?: string
|
||||
feedId?: string
|
||||
entryId?: string
|
||||
}) => {
|
||||
export const useTipModal = () => {
|
||||
const { present } = useModalStack()
|
||||
const { t } = useTranslation()
|
||||
return useCallback(() => {
|
||||
if (!feedId || !entryId) {
|
||||
// this should not happen unless there is a bug in the code
|
||||
toast.error("Invalid feed id or entry id")
|
||||
return
|
||||
}
|
||||
window.analytics?.capture("tip_modal_opened", { entryId })
|
||||
present({
|
||||
title: t("tip_modal.tip_title"),
|
||||
content: () => createElement(TipModalContent, { userId, feedId, entryId }),
|
||||
})
|
||||
}, [present, userId, feedId, entryId])
|
||||
return useCallback(
|
||||
({ userId, feedId, entryId }: { userId?: string; feedId?: string; entryId?: string }) => {
|
||||
if (!feedId || !entryId) {
|
||||
// this should not happen unless there is a bug in the code
|
||||
toast.error("Invalid feed id or entry id")
|
||||
return
|
||||
}
|
||||
window.analytics?.capture("tip_modal_opened", { entryId })
|
||||
present({
|
||||
title: t("tip_modal.tip_title"),
|
||||
content: () => createElement(TipModalContent, { userId, feedId, entryId }),
|
||||
})
|
||||
},
|
||||
[present, t],
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user