@@ -12,6 +12,7 @@ import { MarkAsUnread } from '../../icons/MarkAsUnread';
12
12
import { Snooze } from '../../icons/Snooze' ;
13
13
import { Unsnooze } from '../../icons/Unsnooze' ;
14
14
import {
15
+ LocalizationKey ,
15
16
NotificationStatus ,
16
17
type BodyRenderer ,
17
18
type NotificationActionClickHandler ,
@@ -25,6 +26,38 @@ import { Badge } from '../primitives/Badge';
25
26
import { Tooltip } from '../primitives/Tooltip' ;
26
27
import { SnoozeDateTimePicker } from './SnoozeDateTimePicker' ;
27
28
29
+ const SNOOZE_PRESETS = [
30
+ {
31
+ key : 'snooze.options.inOneHour' ,
32
+ hours : 1 ,
33
+ getDate : ( ) => new Date ( Date . now ( ) + 1 * 60 * 60 * 1000 ) ,
34
+ } ,
35
+ {
36
+ key : 'snooze.options.inTwoHours' ,
37
+ hours : 2 ,
38
+ getDate : ( ) => new Date ( Date . now ( ) + 2 * 60 * 60 * 1000 ) ,
39
+ } ,
40
+ {
41
+ key : 'snooze.options.inTwelveHours' ,
42
+ hours : 12 ,
43
+ getDate : ( ) => new Date ( Date . now ( ) + 12 * 60 * 60 * 1000 ) ,
44
+ } ,
45
+ {
46
+ key : 'snooze.options.inOneDay' ,
47
+ hours : 24 ,
48
+ getDate : ( ) => new Date ( Date . now ( ) + 1 * 24 * 60 * 60 * 1000 ) ,
49
+ } ,
50
+ {
51
+ key : 'snooze.options.inOneWeek' ,
52
+ hours : 168 ,
53
+ getDate : ( ) => new Date ( Date . now ( ) + 7 * 24 * 60 * 60 * 1000 ) ,
54
+ } ,
55
+ ] satisfies {
56
+ key : LocalizationKey ;
57
+ hours : number ;
58
+ getDate : ( ) => Date ;
59
+ } [ ] ;
60
+
28
61
type DefaultNotificationProps = {
29
62
notification : Notification ;
30
63
renderSubject ?: SubjectRenderer ;
@@ -65,6 +98,12 @@ export const DefaultNotification = (props: DefaultNotificationProps) => {
65
98
) ;
66
99
} ) ;
67
100
101
+ const availableSnoozePresets = createMemo ( ( ) => {
102
+ if ( ! maxSnoozeDurationHours ( ) ) return SNOOZE_PRESETS ;
103
+
104
+ return SNOOZE_PRESETS . filter ( ( preset ) => preset . hours <= maxSnoozeDurationHours ( ) ) ;
105
+ } ) ;
106
+
68
107
createEffect ( ( ) => {
69
108
const interval = setInterval ( ( ) => {
70
109
setMinutesPassed ( ( prev ) => prev + 1 ) ;
@@ -242,55 +281,26 @@ export const DefaultNotification = (props: DefaultNotificationProps) => {
242
281
) }
243
282
/>
244
283
< Dropdown . Content portal appearanceKey = "notificationSnooze__dropdownContent" >
245
- < Dropdown . Item
246
- appearanceKey = "notificationSnooze__dropdownItem"
247
- onClick = { async ( e ) => {
248
- e . stopPropagation ( ) ;
249
- await props . notification . snooze ( new Date ( Date . now ( ) + 2 * 60 * 1000 ) . toISOString ( ) ) ;
250
- } }
251
- >
252
- < Clock
253
- class = { style (
254
- 'notificationSnooze__dropdownItem__icon' ,
255
- 'nt-size-3 nt-text-foreground-alpha-400'
256
- ) }
257
- />
258
- { t ( 'snooze.options.anHourFromNow' ) }
259
- </ Dropdown . Item >
260
- < Dropdown . Item
261
- appearanceKey = "notificationSnooze__dropdownItem"
262
- onClick = { async ( e ) => {
263
- e . stopPropagation ( ) ;
264
- await props . notification . snooze (
265
- new Date ( Date . now ( ) + 1 * 24 * 60 * 60 * 1000 ) . toISOString ( )
266
- ) ;
267
- } }
268
- >
269
- < Clock
270
- class = { style (
271
- 'notificationSnooze__dropdownItem__icon' ,
272
- 'nt-size-3 nt-text-foreground-alpha-400'
273
- ) }
274
- />
275
- { new Date ( Date . now ( ) + 1 * 24 * 60 * 60 * 1000 ) . toLocaleString ( ) }
276
- </ Dropdown . Item >
277
- < Dropdown . Item
278
- appearanceKey = "notificationSnooze__dropdownItem"
279
- onClick = { async ( e ) => {
280
- e . stopPropagation ( ) ;
281
- await props . notification . snooze (
282
- new Date ( Date . now ( ) + 7 * 24 * 60 * 60 * 1000 ) . toISOString ( )
283
- ) ;
284
- } }
285
- >
286
- < Clock
287
- class = { style (
288
- 'notificationSnooze__dropdownItem__icon' ,
289
- 'nt-size-3 nt-text-foreground-alpha-400'
290
- ) }
291
- />
292
- { new Date ( Date . now ( ) + 7 * 24 * 60 * 60 * 1000 ) . toLocaleString ( ) }
293
- </ Dropdown . Item >
284
+ < For each = { availableSnoozePresets ( ) } >
285
+ { ( preset ) => (
286
+ < Dropdown . Item
287
+ appearanceKey = "notificationSnooze__dropdownItem"
288
+ onClick = { async ( e ) => {
289
+ e . stopPropagation ( ) ;
290
+ await props . notification . snooze ( preset . getDate ( ) . toISOString ( ) ) ;
291
+ } }
292
+ >
293
+ < Clock
294
+ class = { style (
295
+ 'notificationSnooze__dropdownItem__icon' ,
296
+ 'nt-size-3 nt-text-foreground-alpha-400'
297
+ ) }
298
+ />
299
+ { t ( preset . key ) }
300
+ </ Dropdown . Item >
301
+ ) }
302
+ </ For >
303
+
294
304
< Popover . Root open = { isSnoozeDateTimePickerOpen ( ) } onOpenChange = { setIsSnoozeDateTimePickerOpen } >
295
305
< Dropdown . Item
296
306
asChild = { ( props ) => (
@@ -304,7 +314,7 @@ export const DefaultNotification = (props: DefaultNotificationProps) => {
304
314
'nt-size-3 nt-text-foreground-alpha-400'
305
315
) }
306
316
/>
307
- Custom time...
317
+ { t ( 'snooze.options.customTime' ) }
308
318
</ Popover . Trigger >
309
319
) }
310
320
/>
0 commit comments