From d2c22b83a0e0962ca14e886a930d80e7d39cdb8f Mon Sep 17 00:00:00 2001 From: kylerpan Date: Wed, 18 Oct 2023 16:54:50 -0700 Subject: [PATCH] Added renaming year on roadmap --- site/src/pages/RoadmapPage/AddYearPopup.tsx | 31 ++++++++++++++++++-- site/src/pages/RoadmapPage/Planner.tsx | 7 +++-- site/src/pages/RoadmapPage/Year.tsx | 31 ++++++++++++++++++-- site/src/store/slices/roadmapSlice.ts | 32 ++++++++++++++++++++- site/src/types/types.ts | 2 ++ 5 files changed, 94 insertions(+), 9 deletions(-) diff --git a/site/src/pages/RoadmapPage/AddYearPopup.tsx b/site/src/pages/RoadmapPage/AddYearPopup.tsx index 147349b1..7026b919 100644 --- a/site/src/pages/RoadmapPage/AddYearPopup.tsx +++ b/site/src/pages/RoadmapPage/AddYearPopup.tsx @@ -6,16 +6,21 @@ import { addYear } from '../../store/slices/roadmapSlice'; import { useAppDispatch } from '../../store/hooks'; interface AddYearPopupProps { + placeholderName: string; placeholderYear: number; } -const AddYearPopup: FC = ({ placeholderYear }) => { +const AddYearPopup: FC = ({ placeholderName, placeholderYear }) => { const dispatch = useAppDispatch(); + const [name, setName] = useState(placeholderName); const [year, setYear] = useState(placeholderYear); const [show, setShow] = useState(false); const target = useRef(null); - useEffect(() => { setYear(placeholderYear) }, [placeholderYear]); + useEffect(() => { + setYear(placeholderYear); + setName(placeholderName); + }, [placeholderYear, placeholderName]); const handleClick = (event: React.MouseEvent) => { setShow(!show); @@ -31,6 +36,26 @@ const AddYearPopup: FC = ({ placeholderYear }) => {
+ + + Name + + { + setName(e.target.value); + }} + onKeyDown={(e: React.KeyboardEvent) => { + // prevent submitting form (reloads the page) + if (e.key === 'Enter') { + e.preventDefault(); + } + }} + placeholder={placeholderName} + > + Start Year @@ -61,11 +86,13 @@ const AddYearPopup: FC = ({ placeholderYear }) => { { yearData: { startYear: year, + name: name.trim(), quarters: ['fall', 'winter', 'spring'].map(quarter => { return { name: quarter, courses: [] } }) } } )); setYear(placeholderYear); + setName(placeholderName); }} > Add Year diff --git a/site/src/pages/RoadmapPage/Planner.tsx b/site/src/pages/RoadmapPage/Planner.tsx index ce15540e..f285ca20 100644 --- a/site/src/pages/RoadmapPage/Planner.tsx +++ b/site/src/pages/RoadmapPage/Planner.tsx @@ -36,7 +36,7 @@ const Planner: FC = () => { const collapsePlanner = (planner: PlannerData): SavedPlannerData => { let savedPlanner: SavedPlannerData = []; planner.forEach(year => { - let savedYear: SavedPlannerYearData = { startYear: year.startYear, quarters: [] }; + let savedYear: SavedPlannerYearData = { startYear: year.startYear, name: year.name, quarters: [] }; year.quarters.forEach(quarter => { let savedQuarter: SavedPlannerQuarterData = { name: quarter.name, courses: [] }; savedQuarter.courses = quarter.courses.map(course => course.id); @@ -61,7 +61,7 @@ const Planner: FC = () => { } let planner: PlannerData = []; savedPlanner.forEach(savedYear => { - let year: PlannerYearData = { startYear: savedYear.startYear, quarters: [] }; + let year: PlannerYearData = { startYear: savedYear.startYear, name: savedYear.name, quarters: [] }; savedYear.quarters.forEach(savedQuarter => { let quarter: PlannerQuarterData = { name: savedQuarter.name, courses: [] }; quarter.courses = savedQuarter.courses.map(course => courseLookup[course]); @@ -256,6 +256,7 @@ const Planner: FC = () => { { yearData: { startYear: new Date().getFullYear(), + name: "Year 1", quarters: ['fall', 'winter', 'spring'].map(quarter => { return { name: quarter, courses: [] } }) } } @@ -280,7 +281,7 @@ const Planner: FC = () => {
{initializePlanner()}
- + ); }; diff --git a/site/src/pages/RoadmapPage/Year.tsx b/site/src/pages/RoadmapPage/Year.tsx index 3aafe29f..cad66e3b 100644 --- a/site/src/pages/RoadmapPage/Year.tsx +++ b/site/src/pages/RoadmapPage/Year.tsx @@ -8,7 +8,7 @@ import { } from "react-bootstrap-icons"; import Quarter from "./Quarter"; import { useAppDispatch } from '../../store/hooks'; -import { addQuarter, editYear, deleteYear, clearYear } from '../../store/slices/roadmapSlice'; +import { addQuarter, editYear, editName, deleteYear, clearYear } from '../../store/slices/roadmapSlice'; import { PlannerYearData } from '../../types/types'; @@ -27,6 +27,7 @@ const Year: FC = ({ yearIndex, data }) => { const [addQuarterTarget, setAddQuarterTarget] = useState(null!); const [editYearTarget, setEditYearTarget] = useState(null!); const [placeholderYear, setPlaceholderYear] = useState(data.startYear); + const [placeholderName, setPlaceholderName] = useState(data.name); const handleEditClick = (event: React.MouseEvent) => { if (showAddQuarter) { @@ -90,7 +91,7 @@ const Year: FC = ({ yearIndex, data }) => { ) : ( )} - Year {yearIndex + 1} + {data.name} ({data.startYear} - {data.startYear + 1}) @@ -160,6 +161,26 @@ const Year: FC = ({ yearIndex, data }) => { + + + Name + + { + setPlaceholderName(e.target.value); + }} + onKeyDown={(e: React.KeyboardEvent) => { + // prevent submitting form (reloads the page) + if (e.key === 'Enter') { + e.preventDefault(); + } + }} + placeholder={placeholderName} + > + Start Year @@ -185,11 +206,15 @@ const Year: FC = ({ yearIndex, data }) => {