-
Notifications
You must be signed in to change notification settings - Fork 127
/
index.tsx
47 lines (43 loc) · 1.17 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import React, {
createContext,
Dispatch,
FC,
PropsWithChildren,
useReducer,
} from "react";
import { IMainState } from "../../../store/mainStateReducer";
import { PDFActions } from "./actions";
import {
initialPDFState,
IPDFState,
PDFStateReducer,
reducer,
} from "./reducer";
const PDFContext = createContext<{
state: IPDFState;
dispatch: Dispatch<PDFActions>;
}>({ state: initialPDFState, dispatch: () => null });
const PDFProvider: FC<PropsWithChildren<{ mainState: IMainState }>> = ({
children,
mainState,
}) => {
const [state, dispatch] = useReducer<PDFStateReducer>(reducer, {
...initialPDFState,
defaultZoomLevel:
mainState.config?.pdfZoom?.defaultZoom ??
initialPDFState.defaultZoomLevel,
zoomLevel:
mainState.config?.pdfZoom?.defaultZoom ?? initialPDFState.zoomLevel,
zoomJump: mainState.config?.pdfZoom?.zoomJump ?? initialPDFState.zoomJump,
paginated: mainState.config?.pdfVerticalScrollByDefault
? false
: initialPDFState.paginated,
mainState,
});
return (
<PDFContext.Provider value={{ state, dispatch }}>
{children}
</PDFContext.Provider>
);
};
export { PDFContext, PDFProvider };