fix: boost modal and reward desc behavior

Signed-off-by: Innei <i@innei.in>
This commit is contained in:
Innei 2024-10-24 16:12:45 +08:00
parent 3a35a971f1
commit 8212d0699d
No known key found for this signature in database
GPG Key ID: 0F62D33977F021F7
5 changed files with 15 additions and 8 deletions

View File

@ -1,6 +1,5 @@
/* eslint-disable react-refresh/only-export-components */
import { useTypeScriptHappyCallback } from "@follow/hooks"
import { useSingleton } from "foxact/use-singleton"
import { useOnce, useTypeScriptHappyCallback } from "@follow/hooks"
import type { FC } from "react"
import { createContext, createElement, useContext } from "react"
import { useEventCallback } from "usehooks-ts"
@ -20,6 +19,7 @@ export type AsyncModalOptions<T> = {
// Modal options
overlay?: boolean
clickOutsideToDismiss?: boolean
}
const AsyncModalContext = createContext<AsyncModalOptions<any>>(null!)
export const useAsyncModal = () => {
@ -63,13 +63,14 @@ const Presentable: FC<{
const { present, dismissTop } = useModalStack()
const ctx = useContext(AsyncModalContext)
useSingleton(() => {
useOnce(() => {
dismissTop()
present({
id: `presentable-${ctx.id}`,
content: (props) => createElement(ctx.content, { data, ...props }),
title: typeof ctx.title === "function" ? ctx.title(data) : ctx.title,
icon: ctx.icon?.(data),
clickOutsideToDismiss: ctx.clickOutsideToDismiss,
})
})
return null

View File

@ -24,6 +24,7 @@ export const useBoostModal = () => {
content: () => <BoostModalContent feedId={feedId} />,
overlay: true,
useDataFetcher,
clickOutsideToDismiss: true,
})
},
[present, t],

View File

@ -68,11 +68,7 @@ export const useRewardDescriptionModal = () => {
</div>
),
title: t("wallet.rewardDescription.title"),
overlay: true,
overlayOptions: {
blur: true,
className: "bg-black/80",
},
clickOutsideToDismiss: true,
})
}, [serverConfigs, present, t])

View File

@ -5,6 +5,7 @@ export * from "./useInputComposition"
export * from "./useInterval"
export * from "./useIsOnline"
export * from "./useMeasure"
export * from "./useOnce"
export * from "./usePageVisibility"
export * from "./usePrevious"
export * from "./useRefValue"

View File

@ -0,0 +1,8 @@
import { useSingleton } from "foxact/use-singleton"
export const useOnce = (fn: () => any) => {
useSingleton(async () => {
await fn()
return true
})
}