Skip to content

Commit

Permalink
fix: drag error
Browse files Browse the repository at this point in the history
  • Loading branch information
dlt1111 committed Jun 1, 2020
1 parent dd7d94a commit c045a0d
Showing 1 changed file with 35 additions and 31 deletions.
66 changes: 35 additions & 31 deletions webapp/app/containers/Display/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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: [],
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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 {
Expand Down

0 comments on commit c045a0d

Please sign in to comment.