Skip to content

Commit

Permalink
Merge pull request #284 from SuperZ3/mainState
Browse files Browse the repository at this point in the history
fix: PDFProvider initialized mainState but not updated
  • Loading branch information
cyntler committed Aug 16, 2024
2 parents bd5f925 + 00e0298 commit 66a0e5e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/renderers/pdf/state/actions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { IMainState } from "../../../store/mainStateReducer";

export const SET_ZOOM_LEVEL: string = "SET_ZOOM_LEVEL";

export interface SetZoomLevel {
Expand Down Expand Up @@ -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,
Expand All @@ -49,4 +58,5 @@ export type PDFActions =
| SetZoomLevel
| SetPDFPaginated
| SetNumPages
| SetCurrentPage;
| SetCurrentPage
| SetCurrentMainState;
10 changes: 9 additions & 1 deletion src/renderers/pdf/state/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -37,6 +38,13 @@ const PDFProvider: FC<PropsWithChildren<{ mainState: IMainState }>> = ({
mainState,
});

useEffect(() => {
dispatch({
type: SET_CURRENT_MAIN_STATE,
value: mainState,
});
}, [mainState]);

return (
<PDFContext.Provider value={{ state, dispatch }}>
{children}
Expand Down
7 changes: 7 additions & 0 deletions src/renderers/pdf/state/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
SET_NUM_PAGES,
SET_PDF_PAGINATED,
SET_ZOOM_LEVEL,
SET_CURRENT_MAIN_STATE,
SetCurrentMainState,
} from "./actions";

export type IPDFState = {
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 66a0e5e

Please sign in to comment.