Skip to content

Commit

Permalink
nits
Browse files Browse the repository at this point in the history
  • Loading branch information
sidvishnoi committed Aug 22, 2024
1 parent 8a098ca commit 75d3b5c
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/popup/lib/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ export type ReducerActions =
| UpdateRateOfPayAction
| BackgroundToPopupAction

export const PopupStateContext = React.createContext<PopupContext>(
{} as PopupContext
)
const PopupStateContext = React.createContext<PopupContext>({} as PopupContext)

export const usePopupState = () => React.useContext(PopupStateContext)

const reducer = (state: PopupState, action: ReducerActions): PopupState => {
Expand Down Expand Up @@ -154,6 +153,8 @@ export function PopupContextProvider({ children }: PopupContextProviderProps) {
// #region Browser
const BrowserContext = React.createContext<Browser>({} as Browser)

export const useBrowser = () => React.useContext(BrowserContext)

export const BrowserContextProvider = ({
browser,
children
Expand All @@ -165,12 +166,13 @@ export const BrowserContextProvider = ({
)
}

export const useBrowser = () => React.useContext(BrowserContext)
// #endregion

// #region Translation
const TranslationContext = React.createContext<Translation>((v: string) => v)

export const useTranslation = () => React.useContext(TranslationContext)

export const TranslationContextProvider = ({ children }: PropsWithChildren) => {
const browser = useBrowser()
const t = tFactory(browser)
Expand All @@ -182,14 +184,15 @@ export const TranslationContextProvider = ({ children }: PropsWithChildren) => {
)
}

export const useTranslation = () => React.useContext(TranslationContext)
// #endregion

// #region Translation
const MessageContext = React.createContext<
MessageManager<PopupToBackgroundMessage>
>({} as MessageManager<PopupToBackgroundMessage>)

export const useMessage = () => React.useContext(MessageContext)

export const MessageContextProvider = ({ children }: PropsWithChildren) => {
const browser = useBrowser()
const message = new MessageManager<PopupToBackgroundMessage>({ browser })
Expand All @@ -201,5 +204,4 @@ export const MessageContextProvider = ({ children }: PropsWithChildren) => {
)
}

export const useMessage = () => React.useContext(MessageContext)
// #endregion

0 comments on commit 75d3b5c

Please sign in to comment.