122 lines
5.0 KiB
JavaScript
122 lines
5.0 KiB
JavaScript
import { useMessage } from '@/hooks/useMessage'
|
|
import WithDraggable from '@/components/common/draggable/WithDraggable'
|
|
import { usePopup } from '@/hooks/usePopup'
|
|
import { useRecoilValue } from 'recoil'
|
|
import { contextPopupPositionState } from '@/store/popupAtom'
|
|
import { useState } from 'react'
|
|
import { currentObjectState } from '@/store/canvasAtom'
|
|
import { useAuxiliaryDrawing } from '@/hooks/roofcover/useAuxiliaryDrawing'
|
|
import { useSwal } from '@/hooks/useSwal'
|
|
|
|
export default function AuxiliaryEdit(props) {
|
|
const contextPopupPosition = useRecoilValue(contextPopupPositionState)
|
|
const { id, pos = contextPopupPosition, type } = props
|
|
const { getMessage } = useMessage()
|
|
const { closePopup } = usePopup()
|
|
const { move, copy } = useAuxiliaryDrawing()
|
|
const [verticalSize, setVerticalSize] = useState('0')
|
|
const [horizonSize, setHorizonSize] = useState('0')
|
|
const [arrow1, setArrow1] = useState(null)
|
|
const [arrow2, setArrow2] = useState(null)
|
|
const currentObject = useRecoilValue(currentObjectState)
|
|
const { swalFire } = useSwal()
|
|
const handleSave = () => {
|
|
if ((!arrow1 && !arrow2) || (+verticalSize === 0 && +horizonSize === 0)) {
|
|
swalFire({ title: getMessage('length.direction.is.required'), type: 'alert' })
|
|
return
|
|
}
|
|
|
|
if (verticalSize && +verticalSize !== 0 && !arrow1) {
|
|
swalFire({ title: getMessage('length.direction.is.required'), type: 'alert' })
|
|
return
|
|
}
|
|
|
|
if (horizonSize && +horizonSize !== 0 && !arrow2) {
|
|
swalFire({ title: getMessage('length.direction.is.required'), type: 'alert' })
|
|
return
|
|
}
|
|
|
|
if (type === 'copy') {
|
|
if (currentObject) {
|
|
copy(
|
|
currentObject,
|
|
arrow2 ? (arrow2 === '←' ? Number(horizonSize) * -1 : Number(horizonSize)) : 0,
|
|
arrow1 ? (arrow1 === '↑' ? Number(verticalSize) * -1 : Number(verticalSize)) : 0,
|
|
)
|
|
}
|
|
} else {
|
|
move(
|
|
currentObject,
|
|
arrow2 ? (arrow2 === '←' ? Number(horizonSize) * -1 : Number(horizonSize)) : 0,
|
|
arrow1 ? (arrow1 === '↑' ? Number(verticalSize) * -1 : Number(verticalSize)) : 0,
|
|
)
|
|
}
|
|
|
|
closePopup(id)
|
|
}
|
|
return (
|
|
<WithDraggable isShow={true} pos={pos} className="xm">
|
|
<WithDraggable.Header title={getMessage(type === 'copy' ? 'modal.auxiliary.copy' : 'modal.auxiliary.move')} onClose={() => closePopup(id)} />
|
|
<WithDraggable.Body>
|
|
<div className="grid-option-tit">{getMessage(type === 'copy' ? 'modal.auxiliary.copy.info' : 'modal.auxiliary.move.info')}</div>
|
|
<div className="grid-option-wrap">
|
|
<div className="grid-option-box">
|
|
<div className="move-form">
|
|
<p className="mb5">{getMessage('length')}</p>
|
|
<div className="input-move-wrap mb5">
|
|
<div className="input-move">
|
|
<input type="text" className="input-origin" value={verticalSize} onChange={(e) => setVerticalSize(e.target.value)} />
|
|
</div>
|
|
<span>mm</span>
|
|
<div className="direction-move-wrap">
|
|
<button
|
|
className={`direction up ${arrow1 === '↑' ? 'act' : ''}`}
|
|
onClick={() => {
|
|
setArrow1('↑')
|
|
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowUp' }))
|
|
}}
|
|
></button>
|
|
<button
|
|
className={`direction down ${arrow1 === '↓' ? 'act' : ''}`}
|
|
onClick={() => {
|
|
setArrow1('↓')
|
|
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowDown' }))
|
|
}}
|
|
></button>
|
|
</div>
|
|
</div>
|
|
<div className="input-move-wrap">
|
|
<div className="input-move">
|
|
<input type="text" className="input-origin" value={horizonSize} onChange={(e) => setHorizonSize(e.target.value)} />
|
|
</div>
|
|
<span>mm</span>
|
|
<div className="direction-move-wrap">
|
|
<button
|
|
className={`direction left ${arrow2 === '←' ? 'act' : ''}`}
|
|
onClick={() => {
|
|
setArrow2('←')
|
|
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowLeft' }))
|
|
}}
|
|
></button>
|
|
<button
|
|
className={`direction right ${arrow2 === '→' ? 'act' : ''}`}
|
|
onClick={() => {
|
|
setArrow2('→')
|
|
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowRight' }))
|
|
}}
|
|
></button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div className="grid-btn-wrap">
|
|
<button className="btn-frame modal act" onClick={handleSave}>
|
|
{getMessage('modal.common.save')}
|
|
</button>
|
|
</div>
|
|
</WithDraggable.Body>
|
|
</WithDraggable>
|
|
)
|
|
}
|