2025-02-23 10:11:47 +08:00
|
|
|
import {
|
2025-02-22 17:34:25 +08:00
|
|
|
createContext,
|
|
|
|
|
useState,
|
|
|
|
|
useContext,
|
|
|
|
|
type PropsWithChildren,
|
2025-02-23 10:11:47 +08:00
|
|
|
type Dispatch,
|
|
|
|
|
type SetStateAction,
|
2025-02-22 17:34:25 +08:00
|
|
|
} from 'react'
|
|
|
|
|
|
2025-02-25 05:18:40 +08:00
|
|
|
import type { ModalProperties } from '~/components/popup/success-modal'
|
|
|
|
|
|
|
|
|
|
export type NewsContextProperties = {
|
2025-02-22 17:34:25 +08:00
|
|
|
isLoginOpen: boolean
|
2025-02-23 10:11:47 +08:00
|
|
|
setIsLoginOpen: Dispatch<SetStateAction<boolean>>
|
2025-02-22 17:34:25 +08:00
|
|
|
isRegisterOpen: boolean
|
2025-02-23 10:11:47 +08:00
|
|
|
setIsRegisterOpen: Dispatch<SetStateAction<boolean>>
|
2025-02-22 21:17:56 +07:00
|
|
|
isForgetOpen: boolean
|
2025-02-28 22:50:58 +08:00
|
|
|
setIsForgetOpen: Dispatch<SetStateAction<boolean>>
|
2025-02-25 06:00:12 +08:00
|
|
|
isSuccessOpen: ModalProperties['isOpen']
|
|
|
|
|
setIsSuccessOpen: Dispatch<
|
2025-02-25 05:18:40 +08:00
|
|
|
SetStateAction<ModalProperties['isOpen'] | undefined>
|
|
|
|
|
>
|
|
|
|
|
isInitSubscribeOpen: boolean
|
|
|
|
|
setIsInitSubscribeOpen: Dispatch<SetStateAction<boolean>>
|
2025-02-22 17:34:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NewsContext = createContext<NewsContextProperties | undefined>(undefined)
|
|
|
|
|
|
|
|
|
|
export const NewsProvider = ({ children }: PropsWithChildren) => {
|
|
|
|
|
const [isLoginOpen, setIsLoginOpen] = useState(false)
|
|
|
|
|
const [isRegisterOpen, setIsRegisterOpen] = useState(false)
|
2025-02-28 22:50:58 +08:00
|
|
|
const [isForgetOpen, setIsForgetOpen] = useState(false)
|
2025-02-25 06:00:12 +08:00
|
|
|
const [isSuccessOpen, setIsSuccessOpen] =
|
2025-02-25 05:18:40 +08:00
|
|
|
useState<ModalProperties['isOpen']>()
|
|
|
|
|
const [isInitSubscribeOpen, setIsInitSubscribeOpen] = useState(false)
|
2025-02-22 17:34:25 +08:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<NewsContext.Provider
|
2025-02-22 21:17:56 +07:00
|
|
|
value={{
|
|
|
|
|
isLoginOpen,
|
|
|
|
|
setIsLoginOpen,
|
|
|
|
|
isRegisterOpen,
|
|
|
|
|
setIsRegisterOpen,
|
|
|
|
|
isForgetOpen,
|
2025-02-28 22:50:58 +08:00
|
|
|
setIsForgetOpen,
|
2025-02-25 06:00:12 +08:00
|
|
|
isSuccessOpen,
|
|
|
|
|
setIsSuccessOpen,
|
2025-02-25 05:18:40 +08:00
|
|
|
isInitSubscribeOpen,
|
|
|
|
|
setIsInitSubscribeOpen,
|
2025-02-22 21:17:56 +07:00
|
|
|
}}
|
2025-02-22 17:34:25 +08:00
|
|
|
>
|
|
|
|
|
{children}
|
|
|
|
|
</NewsContext.Provider>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const useNewsContext = (): NewsContextProperties => {
|
|
|
|
|
const context = useContext(NewsContext)
|
|
|
|
|
if (!context) {
|
|
|
|
|
throw new Error('useNewsContext must be used within a NewsProvider')
|
|
|
|
|
}
|
|
|
|
|
return context
|
|
|
|
|
}
|