diff --git a/src/components/map/mapbox/dron/DronToast.js b/src/components/map/mapbox/dron/DronToast.js new file mode 100644 index 00000000..ecbe1557 --- /dev/null +++ b/src/components/map/mapbox/dron/DronToast.js @@ -0,0 +1,93 @@ +import { useEffect, useState } from 'react'; +import { useDispatch, useSelector } from 'react-redux'; +import useAudio from '../../../../utility/hooks/useAudio'; +import warning from '../../../../assets/sounds/warning.mp3'; +import { toast } from 'react-toastify'; +import { Fragment } from 'react'; +import { objectClickAction } from '../../../../modules/control/map/actions/controlMapActions'; +import { + controlGpDtlAction, + controlGpFlightPlanAction +} from '../../../../modules/control/gp'; + +export default function DronToast() { + const dispatch = useDispatch(); + const [playing, toggle] = useAudio(warning); + const { controlGpArcrftWarnList } = useSelector( + state => state.controlGpLogState + ); + const [toastId, setToastId] = useState(); + + let warningList = []; + + useEffect(() => { + if (controlGpArcrftWarnList) { + if (!toastId) { + for (let i = 0; i < controlGpArcrftWarnList.length; i++) { + if (controlGpArcrftWarnList[i].controlWarnCd) { + const id = toast.info( + toastRender( + `${controlGpArcrftWarnList[i].idntfNum} 비정상 상황 알림`, + `경로 상에 비행 구역을 이탈했습니다.` + ), + { + autoClose: false, + hideProgressBar: true, + position: toast.POSITION.BOTTOM_RIGHT, + onClick: () => { + handlerToastClick( + controlGpArcrftWarnList[i].cntrlId, + controlGpArcrftWarnList[i].idntfNum + ); + // setToastId(null); + }, + onClose: () => { + // setIs(true); + toggle(false); + setToastId(null); + } + } + ); + + setToastId(id); + break; + } + } + } + for (let i = 0; i < controlGpArcrftWarnList.length; i++) { + warningList.push(controlGpArcrftWarnList[i].controlWarnCd); + } + + warningList.find(i => i) ? toggle(true) : toggle(false); + } + }, [controlGpArcrftWarnList]); + + const handlerToastClick = (controlId, idntfNum) => { + dispatch(objectClickAction(controlId)); + dispatch(controlGpDtlAction.request(controlId)); + dispatch(controlGpFlightPlanAction.request(idntfNum)); + }; + + const toastRender = (title, message) => { + return ( + +
+
+ } /> +
+ {title} +
+
+
+ +
+ {message} +
+
+ ); + }; + + return null; + + return
DronToast
; +}