/* eslint-disable @typescript-eslint/camelcase */ import { Dispatch } from 'react'; import { CHANGE_SCALE, TOGGLE_DISPLAY_MODE } from '../../constants/actionTypes'; const applyMiddleware = ( state: any, dispatch: Dispatch, ) => ( action: { type: string; payload?: any }, ): void => { dispatch(action); switch (action.type) { case TOGGLE_DISPLAY_MODE: { if (action.payload === 'full') { const screenWidth = window.document.body.offsetWidth - 5; const originPdfWidth = state.viewport.width / state.scale; const rate = (screenWidth / originPdfWidth).toFixed(2); dispatch({ type: CHANGE_SCALE, payload: rate }); } else { dispatch({ type: CHANGE_SCALE, payload: 1 }); } break; } default: break; } }; export default applyMiddleware;