File tree Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Original file line number Diff line number Diff line change
1
+ import { IMainState } from "../../../store/mainStateReducer" ;
2
+
1
3
export const SET_ZOOM_LEVEL : string = "SET_ZOOM_LEVEL" ;
2
4
3
5
export interface SetZoomLevel {
@@ -40,6 +42,13 @@ export interface SetCurrentPage {
40
42
value : number ;
41
43
}
42
44
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
+
43
52
export const setCurrentPage = ( value : number ) : SetCurrentPage => ( {
44
53
type : SET_CURRENT_PAGE ,
45
54
value,
@@ -49,4 +58,5 @@ export type PDFActions =
49
58
| SetZoomLevel
50
59
| SetPDFPaginated
51
60
| SetNumPages
52
- | SetCurrentPage ;
61
+ | SetCurrentPage
62
+ | SetCurrentMainState ;
Original file line number Diff line number Diff line change @@ -3,10 +3,11 @@ import React, {
3
3
Dispatch ,
4
4
FC ,
5
5
PropsWithChildren ,
6
+ useEffect ,
6
7
useReducer ,
7
8
} from "react" ;
8
9
import { IMainState } from "../../../store/mainStateReducer" ;
9
- import { PDFActions } from "./actions" ;
10
+ import { PDFActions , SET_CURRENT_MAIN_STATE } from "./actions" ;
10
11
import {
11
12
initialPDFState ,
12
13
IPDFState ,
@@ -37,6 +38,13 @@ const PDFProvider: FC<PropsWithChildren<{ mainState: IMainState }>> = ({
37
38
mainState,
38
39
} ) ;
39
40
41
+ useEffect ( ( ) => {
42
+ dispatch ( {
43
+ type : SET_CURRENT_MAIN_STATE ,
44
+ value : mainState ,
45
+ } ) ;
46
+ } , [ mainState ] ) ;
47
+
40
48
return (
41
49
< PDFContext . Provider value = { { state, dispatch } } >
42
50
{ children }
Original file line number Diff line number Diff line change 9
9
SET_NUM_PAGES ,
10
10
SET_PDF_PAGINATED ,
11
11
SET_ZOOM_LEVEL ,
12
+ SET_CURRENT_MAIN_STATE ,
13
+ SetCurrentMainState ,
12
14
} from "./actions" ;
13
15
14
16
export type IPDFState = {
@@ -61,6 +63,11 @@ export const reducer: PDFStateReducer = (
61
63
return { ...state , currentPage : value } ;
62
64
}
63
65
66
+ case SET_CURRENT_MAIN_STATE : {
67
+ const { value } = action as SetCurrentMainState ;
68
+ return { ...state , mainState : value } ;
69
+ }
70
+
64
71
default :
65
72
return state ;
66
73
}
You can’t perform that action at this time.
0 commit comments