Browse Source

검색조건 값 변경 함수 추가

pull/2/head
hhjk00 11 months ago
parent
commit
aa439c31a9
  1. 71
      src/containers/statistics/FlightContainer.js

71
src/containers/statistics/FlightContainer.js

@ -15,7 +15,7 @@ import {
import { Search } from 'react-feather'; import { Search } from 'react-feather';
import { FcAlarmClock, FcWorkflow, FcBarChart } from 'react-icons/fc'; import { FcAlarmClock, FcWorkflow, FcBarChart } from 'react-icons/fc';
import { Bar, Doughnut } from 'react-chartjs-2'; import { Bar, Doughnut } from 'react-chartjs-2';
import { useState } from 'react'; import { useCallback, useEffect, useState } from 'react';
export default function FlightContainer({ export default function FlightContainer({
tooltipShadow, tooltipShadow,
@ -23,22 +23,37 @@ export default function FlightContainer({
labelColor labelColor
}) { }) {
const [searchType, setSearchType] = useState({ const [searchType, setSearchType] = useState({
type: 'year', flightType: 'time',
dateType: 'year',
year: new Date().getFullYear(), year: new Date().getFullYear(),
month: new Date().getMonth() + 1, month: new Date().getMonth() + 1,
day: new Date().getDate() day: new Date().getDate()
}); });
const [dateLists, setDateLists] = useState({
console.log(searchType); month: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
day: []
});
const titleName = '비행 통계'; const titleName = '비행 통계';
const handleChangeSearchType = (type, val) => { useEffect(() => {
const { year, month } = searchType;
const lastDay = new Date(year, month, 0).getDate();
const dayList = Array.from({ length: lastDay }, (_, index) => index + 1);
setDateLists({ ...dateLists, day: dayList });
}, [searchType.month]);
// 검색조건 handler
const handleChangeSearchType = useCallback(
(type, val) => {
setSearchType({ setSearchType({
...searchType, ...searchType,
[type]: type === 'type' ? val : Number(val) [type]: type === 'dateType' || type === 'flightType' ? val : Number(val)
}); });
}; },
[searchType]
);
const options = { const options = {
elements: { elements: {
@ -308,10 +323,16 @@ export default function FlightContainer({
type='select' type='select'
id='' id=''
bsSize='sm' bsSize='sm'
onChange={e =>
handleChangeSearchType(
'flightType',
e.target.value
)
}
> >
<option>비행시간</option> <option value={'time'}>비행시간</option>
<option>비행거리</option> <option value={'distance'}>비행거리</option>
<option>비행횟수</option> <option value={'count'}>비행횟수</option>
</CustomInput> </CustomInput>
</Col> </Col>
</Row> </Row>
@ -342,7 +363,7 @@ export default function FlightContainer({
bsSize='sm' bsSize='sm'
value={searchType.type} value={searchType.type}
onChange={e => onChange={e =>
handleChangeSearchType('type', e.target.value) handleChangeSearchType('dateType', e.target.value)
} }
> >
<option value='year'></option> <option value='year'></option>
@ -352,9 +373,9 @@ export default function FlightContainer({
</CustomInput> </CustomInput>
</div> </div>
{searchType.type === 'month' || {searchType.dateType === 'month' ||
searchType.type === 'day' || searchType.dateType === 'day' ||
searchType.type === 'time' ? ( searchType.dateType === 'time' ? (
<> <>
<div className='select-date'> <div className='select-date'>
<CustomInput <CustomInput
@ -370,8 +391,8 @@ export default function FlightContainer({
<option>2023</option> <option>2023</option>
</CustomInput> </CustomInput>
</div> </div>
{searchType.type === 'day' || {searchType.dateType === 'day' ||
searchType.type === 'time' ? ( searchType.dateType === 'time' ? (
<div className='select-date'> <div className='select-date'>
<CustomInput <CustomInput
inline inline
@ -386,13 +407,15 @@ export default function FlightContainer({
) )
} }
> >
<option value={1}>1</option> {dateLists.month.map(i => (
<option value={2}>2</option> <option value={i} key={i}>
<option value={11}>11</option> {i}
</option>
))}
</CustomInput> </CustomInput>
</div> </div>
) : null} ) : null}
{searchType.type === 'time' ? ( {searchType.dateType === 'time' ? (
<div className='select-date'> <div className='select-date'>
<CustomInput <CustomInput
inline inline
@ -404,9 +427,11 @@ export default function FlightContainer({
handleChangeSearchType('day', e.target.value) handleChangeSearchType('day', e.target.value)
} }
> >
<option value={1}>1</option> {dateLists.day.map(i => (
<option value={2}>2</option> <option value={i} key={i}>
<option value={7}>7</option> {i}
</option>
))}
</CustomInput> </CustomInput>
</div> </div>
) : null} ) : null}

Loading…
Cancel
Save