@@ -21,10 +21,22 @@ function displayAssignedHomework() {
2121 }
2222
2323 const container = document . getElementById ( 'uncompleted-homework' ) ;
24+ // Store previous IDs to detect new items
25+ const prevItems = Array . from ( container . querySelectorAll ( '.homework-item' ) ) ;
26+ const prevIds = prevItems . map ( div => div . dataset . id ) ;
27+
2428 container . innerHTML = '' ;
2529
2630 if ( homework . length === 0 ) {
27- container . innerHTML = '<h1 style="text-align: center;">No homework assigned.</h1>' ;
31+ const msgDiv = document . createElement ( 'div' ) ;
32+ msgDiv . innerHTML = '<h1 style="text-align: center;">No homework assigned.</h1>' ;
33+ msgDiv . style . opacity = '0' ;
34+ msgDiv . style . height = '60px' ;
35+ container . appendChild ( msgDiv ) ;
36+ setTimeout ( ( ) => {
37+ msgDiv . style . transition = 'opacity 0.5s' ;
38+ msgDiv . style . opacity = '1' ;
39+ } , 10 ) ;
2840 return ;
2941 }
3042
@@ -33,8 +45,6 @@ function displayAssignedHomework() {
3345 div . classList . add ( 'homework-item' ) ;
3446 div . dataset . id = hw . id ;
3547
36-
37-
3848 div . innerHTML = `
3949 <button class="complete-btn material-symbols-rounded">check</button>
4050 <div>
@@ -48,7 +58,18 @@ function displayAssignedHomework() {
4858 if ( new Date ( hw . dueDate ) < new Date ( ) ) {
4959 div . getElementsByClassName ( 'hw-dueDate' ) [ 0 ] . style . color = '#ffcccc' ;
5060 }
51- container . appendChild ( div ) ;
61+
62+ // Fade in if it's a new item
63+ if ( ! prevIds . includes ( String ( hw . id ) ) ) {
64+ div . style . opacity = '0' ;
65+ div . style . transition = 'opacity 0.5s' ;
66+ container . appendChild ( div ) ;
67+ setTimeout ( ( ) => {
68+ div . style . opacity = '1' ;
69+ } , 500 ) ;
70+ } else {
71+ container . appendChild ( div ) ;
72+ }
5273 } ) ;
5374}
5475
@@ -66,11 +87,39 @@ function displayCompletedHomework() {
6687 }
6788
6889 const container = document . getElementById ( 'completed-homework' ) ;
90+ // Store previous IDs to detect new items
91+ const prevItems = Array . from ( container . querySelectorAll ( '.completed-item' ) ) ;
92+ const prevIds = prevItems . map ( div => div . dataset . id ) ;
93+ const wasHidden = prevItems . length && prevItems [ 0 ] . classList . contains ( 'hidden-item' ) ;
94+
95+ // Fade out if toggled off
96+ if ( showCompleted === false && prevItems . length ) {
97+ prevItems . forEach ( div => {
98+ div . style . transition = 'opacity 0.5s' ;
99+ div . style . opacity = '0' ;
100+ } ) ;
101+ setTimeout ( ( ) => {
102+ container . innerHTML = '' ;
103+ } , 500 ) ;
104+ return ;
105+ }
106+
69107 container . innerHTML = '' ;
70108
71109 if ( finishedHomework . length === 0 ) {
72110 if ( showCompleted == true ) {
73- document . getElementById ( 'completed-homework' ) . innerHTML = '<h1 style="text-align: center;">No homework completed.</h1>' ;
111+ const completedContainer = document . getElementById ( 'completed-homework' ) ;
112+ const msgDiv = document . createElement ( 'div' ) ;
113+ msgDiv . innerHTML = '<h1 style="text-align: center;">No homework completed.</h1>' ;
114+ msgDiv . style . opacity = '0' ;
115+ msgDiv . style . height = '60px' ;
116+ completedContainer . innerHTML = '' ;
117+ completedContainer . appendChild ( msgDiv ) ;
118+ setTimeout ( ( ) => {
119+ msgDiv . style . transition = 'opacity 0.5s' ;
120+ msgDiv . style . opacity = '1' ;
121+ } , 10 ) ;
122+
74123 }
75124 return ;
76125 }
@@ -84,15 +133,32 @@ function displayCompletedHomework() {
84133 }
85134 div . innerHTML = `
86135 <button class="restore-btn material-symbols-rounded">refresh</button>
87- <button class="delete-btn material-symbols-rounded">delete</button>
136+ <button class="delete-btn material-symbols-rounded">delete</button>
88137 <div>
89138 <strong class="hw-name">${ hw . name } </strong>
90139 <p class="hw-subject">${ hw . class } </p>
91140 </div>
92141 <p class="hw-desc">${ hw . description } </p>
93142 <p class="hw-dueDate">${ formatDateTime ( hw . dueDate ) } </p>
94143 ` ;
95- container . appendChild ( div ) ;
144+ // Fade in if toggled on
145+ if ( showCompleted == true && wasHidden ) {
146+ div . style . opacity = '0' ;
147+ container . appendChild ( div ) ;
148+ setTimeout ( ( ) => {
149+ div . style . transition = 'opacity 0.5s' ;
150+ div . style . opacity = '1' ;
151+ } , 10 ) ;
152+ } else if ( ! prevIds . includes ( String ( hw . id ) ) && showCompleted == true ) {
153+ div . style . opacity = '0' ;
154+ container . appendChild ( div ) ;
155+ setTimeout ( ( ) => {
156+ div . style . transition = 'opacity 0.5s' ;
157+ div . style . opacity = '1' ;
158+ } , 500 ) ;
159+ } else {
160+ container . appendChild ( div ) ;
161+ }
96162 } ) ;
97163}
98164
@@ -138,8 +204,20 @@ document.getElementById('homework-container').addEventListener('click', event =>
138204 finishedHomework . push ( completed ) ;
139205 localStorage . setItem ( 'homework' , JSON . stringify ( homework ) ) ;
140206 localStorage . setItem ( 'finishedHomework' , JSON . stringify ( finishedHomework ) ) ;
141- displayAssignedHomework ( ) ;
142- displayCompletedHomework ( ) ;
207+ item . style . opacity = '0' ;
208+ for ( let i = idx ; i < homework . length ; i ++ ) {
209+ const itemDiv = document . querySelector ( `.homework-item[data-id="${ homework [ i ] . id } "]` ) ;
210+ if ( itemDiv ) {
211+ itemDiv . style . transform = 'translateY(-60px)' ;
212+ setTimeout ( ( ) => {
213+ itemDiv . style . transform = '' ;
214+ } , 500 ) ;
215+ }
216+ }
217+ setTimeout ( ( ) => {
218+ displayAssignedHomework ( ) ;
219+ displayCompletedHomework ( ) ;
220+ } , 300 ) ;
143221 }
144222 return ;
145223 }
@@ -156,8 +234,20 @@ document.getElementById('homework-container').addEventListener('click', event =>
156234 homework . push ( restored ) ;
157235 localStorage . setItem ( 'homework' , JSON . stringify ( homework ) ) ;
158236 localStorage . setItem ( 'finishedHomework' , JSON . stringify ( finishedHomework ) ) ;
159- displayAssignedHomework ( ) ;
160- displayCompletedHomework ( ) ;
237+ item . style . opacity = '0' ;
238+ for ( let i = idx ; i < finishedHomework . length ; i ++ ) {
239+ const itemDiv = document . querySelector ( `.completed-item[data-id="${ finishedHomework [ i ] . id } "]` ) ;
240+ if ( itemDiv ) {
241+ itemDiv . style . transform = 'translateY(-60px)' ;
242+ setTimeout ( ( ) => {
243+ itemDiv . style . transform = '' ;
244+ } , 500 ) ;
245+ }
246+ }
247+ setTimeout ( ( ) => {
248+ displayAssignedHomework ( ) ;
249+ displayCompletedHomework ( ) ;
250+ } , 500 ) ;
161251 }
162252 return ;
163253 }
0 commit comments