From c045a0d48743d8328a254e79a49cd4a0f3cb9f33 Mon Sep 17 00:00:00 2001 From: dlt1111 Date: Mon, 1 Jun 2020 19:45:15 +0800 Subject: [PATCH] fix: drag error --- webapp/app/containers/Display/reducer.ts | 66 +++++++++++++----------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/webapp/app/containers/Display/reducer.ts b/webapp/app/containers/Display/reducer.ts index 0a68d593f..b29f1a389 100644 --- a/webapp/app/containers/Display/reducer.ts +++ b/webapp/app/containers/Display/reducer.ts @@ -23,7 +23,6 @@ import produce from 'immer' import { LOCATION_CHANGE, LocationChangeAction } from 'connected-react-router' import { matchDisplaySlidePath } from 'utils/router' - import { ActionTypes } from './constants' import { ActionTypes as VizActionTypes } from 'containers/Viz/constants' import { ActionTypes as ViewActionTypes } from '../View/constants' @@ -126,7 +125,7 @@ const displayReducer = ( datasource: { resultList: [] }, loading: false, queryConditions: { - tempFilters: [], // @TODO combine widget static filters with local filters + tempFilters: [], // @TODO combine widget static filters with local filters linkageFilters: [], globalFilters: [], variables: [], @@ -296,40 +295,40 @@ const displayReducer = ( break case ActionTypes.DRAG_LAYER_ADJUSTED_INDEPENDENCE: { const { - slideSize: { - width: slideWidth, - height: slideHeight - }, + slideSize: { width: slideWidth, height: slideHeight }, layerIds, deltaPosition } = action.payload const isEmpty = draft.operateItemParams.length === 0 layerIds.forEach((layerId) => { if (isEmpty) { - draft.operateItemParams.push({...draft.slideLayers[draft.currentSlideId][layerId]}) - } - const item = draft.operateItemParams.find((item) => item.id === layerId) - item.params.positionX += deltaPosition.deltaX - item.params.positionY += deltaPosition.deltaY - if (item.params.positionX < 0) { - item.params.positionX = 0 - } else if ( - item.params.positionX + item.params.width > - slideWidth - ) { - item.params.positionX = slideWidth - item.params.width + draft.operateItemParams.push({ + ...draft.slideLayers[draft.currentSlideId][layerId] + }) } - if (item.params.positionY < 0) { - item.params.positionY = 0 - } else if ( - item.params.positionY + item.params.height > - slideHeight - ) { - item.params.positionY = slideHeight - item.params.height + const item = draft.operateItemParams.find( + (item) => item.id === layerId + ) + if (item) { + item.params.positionX += deltaPosition.deltaX + item.params.positionY += deltaPosition.deltaY + if (item.params.positionX < 0) { + item.params.positionX = 0 + } else if (item.params.positionX + item.params.width > slideWidth) { + item.params.positionX = slideWidth - item.params.width + } + if (item.params.positionY < 0) { + item.params.positionY = 0 + } else if ( + item.params.positionY + item.params.height > + slideHeight + ) { + item.params.positionY = slideHeight - item.params.height + } + draft.slideLayersOperationInfo[draft.currentSlideId][ + layerId + ].dragging = true } - draft.slideLayersOperationInfo[draft.currentSlideId][ - layerId - ].dragging = true }) break } @@ -401,7 +400,9 @@ const displayReducer = ( case ActionTypes.CLEAR_EDITOR_BASELINES: draft.editorBaselines = [] draft.operateItemParams = [] - Object.values(draft.slideLayersOperationInfo[draft.currentSlideId]).forEach((item) => { + Object.values( + draft.slideLayersOperationInfo[draft.currentSlideId] + ).forEach((item) => { item.dragging = false }) break @@ -427,7 +428,8 @@ const displayReducer = ( break case ActionTypes.LOAD_DISPLAY_AUTHORIZED_SHARE_LINK_SUCCESS: - draft.currentDisplayAuthorizedShareToken = action.payload.authorizedShareToken + draft.currentDisplayAuthorizedShareToken = + action.payload.authorizedShareToken draft.loading.shareToken = false break @@ -452,7 +454,9 @@ const displayReducer = ( return initialState case LOCATION_CHANGE: - const matchSlide = matchDisplaySlidePath(action.payload.location.pathname) + const matchSlide = matchDisplaySlidePath( + action.payload.location.pathname + ) if (matchSlide) { draft.currentSlideId = +matchSlide.params.slideId || null } else {