Skip to content

Commit 66a0e5e

Browse files
authored
Merge pull request #284 from SuperZ3/mainState
fix: PDFProvider initialized mainState but not updated
2 parents bd5f925 + 00e0298 commit 66a0e5e

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src/renderers/pdf/state/actions.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { IMainState } from "../../../store/mainStateReducer";
2+
13
export const SET_ZOOM_LEVEL: string = "SET_ZOOM_LEVEL";
24

35
export interface SetZoomLevel {
@@ -40,6 +42,13 @@ export interface SetCurrentPage {
4042
value: number;
4143
}
4244

45+
export const SET_CURRENT_MAIN_STATE: string = "SET_CURRENT_MAIN_STATE";
46+
47+
export interface SetCurrentMainState {
48+
type: typeof SET_CURRENT_MAIN_STATE;
49+
value: IMainState;
50+
}
51+
4352
export const setCurrentPage = (value: number): SetCurrentPage => ({
4453
type: SET_CURRENT_PAGE,
4554
value,
@@ -49,4 +58,5 @@ export type PDFActions =
4958
| SetZoomLevel
5059
| SetPDFPaginated
5160
| SetNumPages
52-
| SetCurrentPage;
61+
| SetCurrentPage
62+
| SetCurrentMainState;

src/renderers/pdf/state/index.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import React, {
33
Dispatch,
44
FC,
55
PropsWithChildren,
6+
useEffect,
67
useReducer,
78
} from "react";
89
import { IMainState } from "../../../store/mainStateReducer";
9-
import { PDFActions } from "./actions";
10+
import { PDFActions, SET_CURRENT_MAIN_STATE } from "./actions";
1011
import {
1112
initialPDFState,
1213
IPDFState,
@@ -37,6 +38,13 @@ const PDFProvider: FC<PropsWithChildren<{ mainState: IMainState }>> = ({
3738
mainState,
3839
});
3940

41+
useEffect(() => {
42+
dispatch({
43+
type: SET_CURRENT_MAIN_STATE,
44+
value: mainState,
45+
});
46+
}, [mainState]);
47+
4048
return (
4149
<PDFContext.Provider value={{ state, dispatch }}>
4250
{children}

src/renderers/pdf/state/reducer.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import {
99
SET_NUM_PAGES,
1010
SET_PDF_PAGINATED,
1111
SET_ZOOM_LEVEL,
12+
SET_CURRENT_MAIN_STATE,
13+
SetCurrentMainState,
1214
} from "./actions";
1315

1416
export type IPDFState = {
@@ -61,6 +63,11 @@ export const reducer: PDFStateReducer = (
6163
return { ...state, currentPage: value };
6264
}
6365

66+
case SET_CURRENT_MAIN_STATE: {
67+
const { value } = action as SetCurrentMainState;
68+
return { ...state, mainState: value };
69+
}
70+
6471
default:
6572
return state;
6673
}

0 commit comments

Comments
 (0)