Skip to content

Commit

Permalink
Fix : 현재 년도에서 +1 년 -4년까지 학기를 선택할 수 있도록 학기와 관련된 select, dropdown 등을 자동…
Browse files Browse the repository at this point in the history
…화시킴(#65)
  • Loading branch information
ohinhyuk committed Oct 11, 2023
1 parent 3603350 commit ddcb719
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 53 deletions.
38 changes: 20 additions & 18 deletions src/components/common/Filter/SemesterDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,29 @@ import { Box, FormControl, InputLabel, MenuItem, Select, styled } from '@mui/mat
import { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { setSemester } from 'src/redux/slices/filter';
import { generateSemesters, currentYear } from 'src/utils/semesterAutoGenerate';
// const SEMESTERS = [
// '전체',

const SEMESTERS = [
'전체',

'2020-01',
'2020-02',
'2021-01',
'2021-02',
'2022-01',
'2022-02',
'2023-01',
'2023-02',
'2024-01',
'2024-02',
'2025-01',
'2025-02',
'2026-01',
'2026-02',
];
// '2020-01',
// '2020-02',
// '2021-01',
// '2021-02',
// '2022-01',
// '2022-02',
// '2023-01',
// '2023-02',
// '2024-01',
// '2024-02',
// '2025-01',
// '2025-02',
// '2026-01',
// '2026-02',
// ];

export default function SemesterDropdown() {
const SEMESTERS = generateSemesters(currentYear);

const semester = useSelector((state) => state.filter.semester);
const dispatch = useDispatch();

Expand Down
39 changes: 20 additions & 19 deletions src/components/common/Select/SemesterMagicianSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,27 @@ import { FormControl, InputLabel, MenuItem, Select } from '@mui/material';
import { ErrorMessage, Field } from 'formik';
import { useSelector } from 'react-redux';
import { CATEGORYID, SEMESTER } from 'src/assets/data/fields';

import { generateSemesters, currentYear } from 'src/utils/semesterAutoGenerate';
export default function SemesterMagicianSelect({ semester, setSemester }) {
const semesters = [
'2020-01',
'2020-02',
'2021-01',
'2021-02',
'2022-01',
'2022-02',
'2023-01',
'2023-02',
'2024-01',
'2024-02',
'2025-01',
'2025-02',
'2026-01',
'2026-02',
'2027-01',
'2027-02',
];
// const semesters = [
// '2020-01',
// '2020-02',
// '2021-01',
// '2021-02',
// '2022-01',
// '2022-02',
// '2023-01',
// '2023-02',
// '2024-01',
// '2024-02',
// '2025-01',
// '2025-02',
// '2026-01',
// '2026-02',
// '2027-01',
// '2027-02',
// ];
const semesters = generateSemesters(currentYear);

return (
<Select
Expand Down
17 changes: 1 addition & 16 deletions src/components/common/Select/SemesterSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,7 @@ import { FormControl, InputLabel, MenuItem, Select } from '@mui/material';
import { ErrorMessage, Field } from 'formik';
import { useSelector } from 'react-redux';
import { CATEGORYID, SEMESTER } from 'src/assets/data/fields';

const generateSemesters = (currentYear) => {
const startYear = currentYear - 4;
const endYear = currentYear + 4;
const semesters = [];

for (let year = startYear; year <= endYear; year++) {
semesters.push(`${year}-01`);
semesters.push(`${year}-02`);
}

return semesters;
};

const currentDate = new Date();
const currentYear = currentDate.getFullYear();
import { generateSemesters, currentYear } from 'src/utils/semesterAutoGenerate';

export default function SemesterSelect() {
// const semesters = [
Expand Down
15 changes: 15 additions & 0 deletions src/utils/semesterAutoGenerate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export const generateSemesters = (currentYear) => {
const startYear = currentYear - 4;
const endYear = currentYear + 1;
const semesters = [];

for (let year = startYear; year <= endYear; year += 1) {
semesters.push(`${year}-01`);
semesters.push(`${year}-02`);
}

return semesters;
};

const currentDate = new Date();
export const currentYear = currentDate.getFullYear();

0 comments on commit ddcb719

Please sign in to comment.