@@ -5,10 +5,8 @@ const plugin = {
55 "Bulk Reset Overdue Tasks" : {
66 run : async function ( app , noteUUID ) {
77 try {
8- // Get today's date at midnight for comparison
9- const today = new Date ( ) ;
10- today . setHours ( 0 , 0 , 0 , 0 ) ;
11- const todayTimestamp = Math . floor ( today . getTime ( ) / 1000 ) ;
8+ // Get current time minus 1 hour
9+ const oneHourAgo = Math . floor ( Date . now ( ) / 1000 ) - 3600 ; // 3600 seconds = 1 hour
1210
1311 // Get all task domains
1412 const taskDomains = await app . getTaskDomains ( ) ;
@@ -18,15 +16,16 @@ const plugin = {
1816 return ;
1917 }
2018
21- // Get all tasks from all task domains and filter for overdue
19+ // Get all tasks from all task domains and filter for overdue by more than 1 hour
2220 const overdueTasks = [ ] ;
2321 const tasksByDomain = { } ; // Track tasks per domain
2422
2523 for ( const taskDomain of taskDomains ) {
2624 const domainTasks = [ ] ;
2725 for await ( const task of app . getTaskDomainTasks ( taskDomain . uuid ) ) {
2826 const taskDate = task . startAt || task . endAt ;
29- if ( taskDate && taskDate < todayTimestamp ) {
27+ // Task is overdue if it's older than 1 hour ago
28+ if ( taskDate && taskDate < oneHourAgo ) {
3029 overdueTasks . push ( task ) ;
3130 domainTasks . push ( task ) ;
3231 }
@@ -67,37 +66,73 @@ const plugin = {
6766 const confirmed = await app . alert ( confirmMessage , {
6867 actions : [
6968 { label : "Cancel" , icon : "cancel" } ,
70- { label : "Reset All " , icon : "check" } ,
69+ { label : "Remove from calendar " , icon : "check" } ,
7170 ] ,
7271 } ) ;
7372
7473 // User chose "Reset All" (index 1)
7574 if ( confirmed === 1 ) {
7675 let successCount = 0 ;
7776 let failCount = 0 ;
77+ const errors = [ ] ;
7878
7979 // Remove calendar date from each overdue task
8080 for ( const task of overdueTasks ) {
8181 try {
82- await app . updateTask ( task . uuid , {
83- startAt : null ,
84- endAt : null ,
85- hideUntil : null ,
86- } ) ;
87- successCount ++ ;
82+ // Remove all calendar-related fields to take task off calendar
83+ const updates = { } ;
84+
85+ // Log what we're about to do
86+ console . log ( `Processing task ${ task . uuid } :` ) ;
87+ console . log ( ` startAt: ${ task . startAt } ` ) ;
88+ console . log ( ` endAt: ${ task . endAt } ` ) ;
89+ console . log ( ` hideUntil: ${ task . hideUntil } ` ) ;
90+
91+ // Only set fields to null if they exist on the task
92+ if ( task . startAt !== null && task . startAt !== undefined ) {
93+ delete updates . startAt ;
94+ }
95+ if ( task . endAt !== null && task . endAt !== undefined ) {
96+ delete updates . endAt ;
97+ }
98+ if ( task . hideUntil !== null && task . hideUntil !== undefined ) {
99+ delete updates . hideUntil ;
100+ }
101+
102+ console . log ( ` Updates to apply:` , updates ) ;
103+
104+ if ( Object . keys ( updates ) . length > 0 ) {
105+ await app . updateTask ( task . uuid , updates ) ;
106+ console . log ( ` ✓ Successfully updated task ${ task . uuid } ` ) ;
107+ successCount ++ ;
108+ } else {
109+ console . log (
110+ ` ⚠ Task ${ task . uuid } has no calendar dates to remove`
111+ ) ;
112+ successCount ++ ;
113+ }
88114 } catch ( error ) {
115+ const errorMsg = `Task "${ task . content || task . uuid } ": ${
116+ error . message
117+ } `;
89118 console . error ( `Failed to reset task ${ task . uuid } :` , error ) ;
119+ console . error ( `Task data:` , JSON . stringify ( task ) ) ;
120+ errors . push ( errorMsg ) ;
90121 failCount ++ ;
91122 }
92123 }
93124
94- const resultMessage =
95- `Successfully reset ${ successCount } task${
96- successCount !== 1 ? "s" : ""
97- } .` +
98- ( failCount > 0
99- ? ` ${ failCount } task${ failCount !== 1 ? "s" : "" } failed.`
100- : "" ) ;
125+ let resultMessage = `Successfully reset ${ successCount } task${
126+ successCount !== 1 ? "s" : ""
127+ } .`;
128+
129+ if ( failCount > 0 ) {
130+ resultMessage += `\n\n${ failCount } task${
131+ failCount !== 1 ? "s" : ""
132+ } failed:\n`;
133+ resultMessage += errors . map ( ( e ) => `• ${ e } ` ) . join ( "\n" ) ;
134+ }
135+
101136 await app . alert ( resultMessage ) ;
102137 }
103138 } catch ( error ) {
0 commit comments