Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: PDFProvider initialized mainState but not updated #284

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading