import { useEffect, useState, useReducer, useRef } from 'react' import { useRecoilValue, useRecoilState } from 'recoil' import { addedRoofsState } from '@/store/settingAtom' import { currentCanvasPlanState } from '@/store/canvasAtom' import { useMessage } from '@/hooks/useMessage' import QSelectBox from '@/components/common/select/QSelectBox' import { useModuleSelection } from '@/hooks/module/useModuleSelection' import ModuleTabContents from './ModuleTabContents' import { useDebounceValue } from 'usehooks-ts' import { moduleSelectionDataState } from '@/store/selectedModuleOptions' import { useCanvasPopupStatusController } from '@/hooks/common/useCanvasPopupStatusController' import { isObjectNotEmpty } from '@/util/common-utils' import { normalizeDecimal} from '@/util/input-utils' import { CalculatorInput } from '@/components/common/input/CalcInput' export default function Module({ setTabNum }) { const { getMessage } = useMessage() const [addedRoofs, setAddedRoofs] = useRecoilState(addedRoofsState) //지붕재 선택 const [roofTab, setRoofTab] = useState(0) //지붕재 탭 const { moduleSelectionInitParams, selectedModules, roughnessCodes, windSpeedCodes, managementState, moduleList, selectedSurfaceType, installHeight, standardWindSpeed, verticalSnowCover, handleChangeModule, handleChangeSurfaceType, handleChangeWindSpeed, handleChangeInstallHeight, handleChangeVerticalSnowCover, } = useModuleSelection({ addedRoofs }) const [inputInstallHeight, setInputInstallHeight] = useState() const [inputVerticalSnowCover, setInputVerticalSnowCover] = useState() const [debouncedInstallHeight] = useDebounceValue(inputInstallHeight, 500) const [debouncedVerticalSnowCover] = useDebounceValue(inputVerticalSnowCover, 500) const [moduleSelectionData, setModuleSelectionData] = useRecoilState(moduleSelectionDataState) //다음으로 넘어가는 최종 데이터 const [tempModuleSelectionData, setTempModuleSelectionData] = useReducer((prevState, nextState) => { return { ...prevState, ...nextState } }, moduleSelectionData) useEffect(() => { if (installHeight) { setInputInstallHeight(installHeight) } if (verticalSnowCover) { setInputVerticalSnowCover(verticalSnowCover) } }, [installHeight, verticalSnowCover]) useEffect(() => { if (isObjectNotEmpty(tempModuleSelectionData)) { if (tempModuleSelectionData.roofConstructions.length > 0) { if (tempModuleSelectionData.common.moduleItemId && isObjectNotEmpty(tempModuleSelectionData.module)) { //저장된 temp데이터가 지붕재(addedRoofs) 개수와 같으면 모듈 선택 저장 setModuleSelectionData(tempModuleSelectionData) if (tempModuleSelectionData.roofConstructions.length === addedRoofs.length) { moduleSelectedDataTrigger(tempModuleSelectionData) } } } } }, [tempModuleSelectionData]) useEffect(() => { if (debouncedInstallHeight) { handleChangeInstallHeight(debouncedInstallHeight) } }, [debouncedInstallHeight]) useEffect(() => { if (debouncedVerticalSnowCover) { handleChangeVerticalSnowCover(debouncedVerticalSnowCover) } }, [debouncedVerticalSnowCover]) const moduleData = { header: [ { name: getMessage('module'), width: 150, prop: 'module', type: 'color-box' }, { name: `${getMessage('height')} (mm)`, prop: 'height', }, { name: `${getMessage('width')} (mm)`, prop: 'width' }, { name: `${getMessage('output')} (W)`, prop: 'output' }, ], rows: [], } const handleRoofTab = (tab) => { setRoofTab(tab) } const { trigger: moduleSelectedDataTrigger } = useCanvasPopupStatusController(2) return ( <>
| {header.name} | ) })}|||
|---|---|---|---|
|
{row.itemNm}
|
{Number(row.shortAxis).toFixed(0)} | {Number(row.longAxis).toFixed(0)} | {Number(row.wpOut).toFixed(0)} |