diff --git a/src/renderers/pdf/state/actions.ts b/src/renderers/pdf/state/actions.ts index f7b942ab..995343cc 100644 --- a/src/renderers/pdf/state/actions.ts +++ b/src/renderers/pdf/state/actions.ts @@ -1,3 +1,5 @@ +import { IMainState } from "../../../store/mainStateReducer"; + export const SET_ZOOM_LEVEL: string = "SET_ZOOM_LEVEL"; export interface SetZoomLevel { @@ -40,6 +42,13 @@ export interface SetCurrentPage { value: number; } +export const SET_CURRENT_MAIN_STATE: string = "SET_CURRENT_MAIN_STATE"; + +export interface SetCurrentMainState { + type: typeof SET_CURRENT_MAIN_STATE; + value: IMainState; +} + export const setCurrentPage = (value: number): SetCurrentPage => ({ type: SET_CURRENT_PAGE, value, @@ -49,4 +58,5 @@ export type PDFActions = | SetZoomLevel | SetPDFPaginated | SetNumPages - | SetCurrentPage; + | SetCurrentPage + | SetCurrentMainState; diff --git a/src/renderers/pdf/state/index.tsx b/src/renderers/pdf/state/index.tsx index e8da00cf..53a3b2c0 100644 --- a/src/renderers/pdf/state/index.tsx +++ b/src/renderers/pdf/state/index.tsx @@ -3,10 +3,11 @@ import React, { Dispatch, FC, PropsWithChildren, + useEffect, useReducer, } from "react"; import { IMainState } from "../../../store/mainStateReducer"; -import { PDFActions } from "./actions"; +import { PDFActions, SET_CURRENT_MAIN_STATE } from "./actions"; import { initialPDFState, IPDFState, @@ -37,6 +38,13 @@ const PDFProvider: FC> = ({ mainState, }); + useEffect(() => { + dispatch({ + type: SET_CURRENT_MAIN_STATE, + value: mainState, + }); + }, [mainState]); + return ( {children} diff --git a/src/renderers/pdf/state/reducer.ts b/src/renderers/pdf/state/reducer.ts index 14277e4f..5dbe5c36 100644 --- a/src/renderers/pdf/state/reducer.ts +++ b/src/renderers/pdf/state/reducer.ts @@ -9,6 +9,8 @@ import { SET_NUM_PAGES, SET_PDF_PAGINATED, SET_ZOOM_LEVEL, + SET_CURRENT_MAIN_STATE, + SetCurrentMainState, } from "./actions"; export type IPDFState = { @@ -61,6 +63,11 @@ export const reducer: PDFStateReducer = ( return { ...state, currentPage: value }; } + case SET_CURRENT_MAIN_STATE: { + const { value } = action as SetCurrentMainState; + return { ...state, mainState: value }; + } + default: return state; }