fix: boost modal and reward desc behavior
Signed-off-by: Innei <i@innei.in>
This commit is contained in:
parent
3a35a971f1
commit
8212d0699d
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ export const useBoostModal = () => {
|
|||
content: () => <BoostModalContent feedId={feedId} />,
|
||||
overlay: true,
|
||||
useDataFetcher,
|
||||
clickOutsideToDismiss: true,
|
||||
})
|
||||
},
|
||||
[present, t],
|
||||
|
|
|
|||
|
|
@ -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])
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
import { useSingleton } from "foxact/use-singleton"
|
||||
|
||||
export const useOnce = (fn: () => any) => {
|
||||
useSingleton(async () => {
|
||||
await fn()
|
||||
return true
|
||||
})
|
||||
}
|
||||
Loading…
Reference in New Issue