@@ -17,7 +17,6 @@ import {
1717 Major ,
1818 Minor ,
1919 SeasonEnum ,
20- StatusEnum ,
2120 Whiteboard ,
2221} from "@/lib/graduate/types" ;
2322import {
@@ -28,7 +27,11 @@ import {
2827 collisionAlgorithm ,
2928 nextId ,
3029 DELETE_ZONE_ID ,
30+ addYear ,
31+ deleteYear ,
32+ removeCourse ,
3133} from "@/lib/graduate/planUtils" ;
34+ import { pruneWhiteboard } from "@/lib/graduate/requirementUtils" ;
3235import { CourseNameContext } from "./CourseNameContext" ;
3336import { CourseDetailsContext } from "./CourseDetailsContext" ;
3437import type { CourseDetails } from "@/lib/graduate/types" ;
@@ -79,30 +82,6 @@ export function BasePlanClient({
7982 "whiteboard" ,
8083 ) ;
8184
82- /** Collect all "SUBJECT CLASSID" keys present in a schedule. */
83- function scheduleCourseKeys ( audit : Audit ) : Set < string > {
84- const keys = new Set < string > ( ) ;
85- for ( const y of audit . years ) {
86- for ( const t of [ y . fall , y . spring , y . summer1 , y . summer2 ] ) {
87- for ( const c of t . classes ) keys . add ( `${ c . subject } ${ c . classId } ` ) ;
88- }
89- }
90- return keys ;
91- }
92-
93- /** Remove whiteboard courses that no longer exist in the schedule. */
94- function pruneWhiteboard ( audit : Audit , wb : Whiteboard ) : Whiteboard | null {
95- const valid = scheduleCourseKeys ( audit ) ;
96- let changed = false ;
97- const pruned : Whiteboard = { } ;
98- for ( const [ section , entry ] of Object . entries ( wb ) ) {
99- const filtered = entry . courses . filter ( ( k ) => valid . has ( k ) ) ;
100- if ( filtered . length !== entry . courses . length ) changed = true ;
101- pruned [ section ] = { ...entry , courses : filtered } ;
102- }
103- return changed ? pruned : null ;
104- }
105-
10685 function persist ( updated : Audit ) {
10786 const withIds = assignDndIds ( updated ) ;
10887 setSchedule ( withIds ) ;
@@ -239,32 +218,11 @@ export function BasePlanClient({
239218 season : SeasonEnum ,
240219 courseIndex : number ,
241220 ) {
242- const updated = produce ( schedule , ( draft ) => {
243- const year = draft . years . find ( ( y ) => y . year === yearNum ) ;
244- if ( ! year ) return ;
245- const termMap : Record < string , AuditTerm > = {
246- [ SeasonEnum . FL ] : year . fall ,
247- [ SeasonEnum . SP ] : year . spring ,
248- [ SeasonEnum . S1 ] : year . summer1 ,
249- [ SeasonEnum . S2 ] : year . summer2 ,
250- } ;
251- const term = termMap [ season ] ;
252- if ( term ) {
253- term . classes . splice ( courseIndex , 1 ) ;
254- }
255- } ) ;
256- persist ( updated ) ;
221+ persist ( removeCourse ( schedule , yearNum , season , courseIndex ) ) ;
257222 }
258223
259224 function handleDeleteYear ( yearNum : number ) {
260- const updated = produce ( schedule , ( draft ) => {
261- const idx = yearNum - 1 ;
262- if ( idx >= draft . years . length ) return ;
263- draft . years . splice ( idx , 1 ) ;
264- draft . years . forEach ( ( y , i ) => {
265- y . year = i + 1 ;
266- } ) ;
267- } ) ;
225+ const updated = deleteYear ( schedule , yearNum ) ;
268226 setExpandedYears ( ( prev ) => {
269227 const next = new Set < number > ( ) ;
270228 for ( let i = 1 ; i <= updated . years . length ; i ++ ) {
@@ -277,24 +235,8 @@ export function BasePlanClient({
277235 }
278236
279237 function handleAddYear ( ) {
280- const nextYear = schedule . years . length + 1 ;
281- const emptyTerm = ( season : SeasonEnum ) : AuditTerm => ( {
282- season,
283- status : StatusEnum . CLASSES ,
284- classes : [ ] ,
285- id : `${ nextYear } -${ season } ` ,
286- } ) ;
287- const updated = produce ( schedule , ( draft ) => {
288- draft . years . push ( {
289- year : nextYear ,
290- fall : emptyTerm ( SeasonEnum . FL ) ,
291- spring : emptyTerm ( SeasonEnum . SP ) ,
292- summer1 : emptyTerm ( SeasonEnum . S1 ) ,
293- summer2 : emptyTerm ( SeasonEnum . S2 ) ,
294- isSummerFull : false ,
295- } ) ;
296- } ) ;
297- setExpandedYears ( ( prev ) => new Set ( [ ...prev , nextYear ] ) ) ;
238+ const { schedule : updated , addedYear } = addYear ( schedule ) ;
239+ setExpandedYears ( ( prev ) => new Set ( [ ...prev , addedYear ] ) ) ;
298240 persist ( updated ) ;
299241 }
300242
@@ -308,7 +250,7 @@ export function BasePlanClient({
308250 >
309251 < DeleteDropZone >
310252 < div className = "flex min-h-0 flex-1 overflow-hidden" >
311- < div className = "bg-neu25 w-[360px] flex-shrink-0 overflow-y-auto " >
253+ < div className = "bg-neu25 h-[80vh] w-[360px] flex-shrink-0 pb-10 " >
312254 < div className = "flex justify-center gap-1 px-4 pt-2" >
313255 < button
314256 type = "button"
0 commit comments