@@ -36,31 +36,40 @@ interface ReminderOption {
3636 label : string
3737 ariaLabel : string
3838 dateString ?: string
39+ verboseDateString ?: string
3940 action ?: ( ) => Promise < void >
4041}
4142
4243const laterToday : ReminderOption = {
4344 dateTimePreset : DateTimePreset . LaterToday ,
4445 label : t ( 'files_reminders' , 'Later today' ) ,
4546 ariaLabel : t ( 'files_reminders' , 'Set reminder for later today' ) ,
47+ dateString : '' ,
48+ verboseDateString : ''
4649}
4750
4851const tomorrow : ReminderOption = {
4952 dateTimePreset : DateTimePreset . Tomorrow ,
5053 label : t ( 'files_reminders' , 'Tomorrow' ) ,
5154 ariaLabel : t ( 'files_reminders' , 'Set reminder for tomorrow' ) ,
55+ dateString : '' ,
56+ verboseDateString : ''
5257}
5358
5459const thisWeekend : ReminderOption = {
5560 dateTimePreset : DateTimePreset . ThisWeekend ,
5661 label : t ( 'files_reminders' , 'This weekend' ) ,
5762 ariaLabel : t ( 'files_reminders' , 'Set reminder for this weekend' ) ,
63+ dateString : '' ,
64+ verboseDateString : ''
5865}
5966
6067const nextWeek : ReminderOption = {
6168 dateTimePreset : DateTimePreset . NextWeek ,
6269 label : t ( 'files_reminders' , 'Next week' ) ,
6370 ariaLabel : t ( 'files_reminders' , 'Set reminder for next week' ) ,
71+ dateString : '' ,
72+ verboseDateString : ''
6473}
6574
6675/**
@@ -69,21 +78,17 @@ const nextWeek: ReminderOption = {
6978 * @param option The option to generate the action for
7079 * @return The file action or null if the option should not be shown
7180 */
72- const generateFileAction = ( option ) : FileAction | null => {
73- const dateTime = getDateTime ( option . dateTimePreset )
74- if ( ! dateTime ) {
75- return null
76- }
81+ const generateFileAction = ( option : ReminderOption ) : FileAction | null => {
7782
7883 return new FileAction ( {
7984 id : `set-reminder-${ option . dateTimePreset } ` ,
80- displayName : ( ) => `${ option . label } – ${ getDateString ( dateTime ) } ` ,
81- title : ( ) => `${ option . ariaLabel } – ${ getVerboseDateString ( dateTime ) } ` ,
85+ displayName : ( ) => `${ option . label } – ${ option . dateString } ` ,
86+ title : ( ) => `${ option . ariaLabel } – ${ option . verboseDateString } ` ,
8287
8388 // Empty svg to hide the icon
8489 iconSvgInline : ( ) => '<svg></svg>' ,
8590
86- enabled : ( ) => true ,
91+ enabled : ( ) => Boolean ( getDateTime ( option . dateTimePreset ) ) ,
8792 parent : SET_REMINDER_MENU_ID ,
8893
8994 async exec ( node : Node ) {
@@ -96,7 +101,7 @@ const generateFileAction = (option): FileAction|null => {
96101
97102 // Set the reminder
98103 try {
99- await setReminder ( node . fileid , dateTime )
104+ await setReminder ( node . fileid , getDateTime ( option . dateTimePreset ) ! )
100105 showSuccess ( t ( 'files_reminders' , 'Reminder set for "{fileName}"' , { fileName : node . basename } ) )
101106 } catch ( error ) {
102107 logger . error ( 'Failed to set reminder' , { error } )
@@ -110,7 +115,27 @@ const generateFileAction = (option): FileAction|null => {
110115 } )
111116}
112117
118+ [ laterToday , tomorrow , thisWeekend , nextWeek ] . forEach ( ( option ) => {
119+ // Generate the initial date string
120+ const dateTime = getDateTime ( option . dateTimePreset )
121+ if ( ! dateTime ) {
122+ return
123+ }
124+ option . dateString = getDateString ( dateTime )
125+ option . verboseDateString = getVerboseDateString ( dateTime )
126+ +
127+ // Update the date string every 30 minutes
128+ setInterval ( ( ) => {
129+ const dateTime = getDateTime ( option . dateTimePreset )
130+ if ( ! dateTime ) {
131+ return
132+ }
133+
134+ option . dateString = getDateString ( dateTime )
135+ option . verboseDateString = getVerboseDateString ( dateTime )
136+ } , 1000 * 30 * 60 )
137+ } )
138+
113139// Generate the default preset actions
114140export const actions = [ laterToday , tomorrow , thisWeekend , nextWeek ]
115- . map ( generateFileAction )
116- . filter ( Boolean ) as FileAction [ ]
141+ . map ( generateFileAction ) as FileAction [ ]
0 commit comments