@@ -26,13 +26,18 @@ type CursorPaginationsButtonsProps = PaginatedResponse<ItemWithId> & {
26
26
hideBoundaries ?: boolean ;
27
27
} ;
28
28
29
- function getStartAndEndFormatted (
30
- startTs : string | undefined ,
31
- endTs : string | undefined ,
32
- language : string ,
33
- ) {
29
+ function FormattedDatesRange ( {
30
+ startTs,
31
+ endTs,
32
+ language,
33
+ } : {
34
+ startTs : string | undefined ;
35
+ endTs : string | undefined ;
36
+ language : string ;
37
+ } ) {
38
+ const { t } = useTranslation ( [ 'common' ] ) ;
34
39
if ( ! startTs || ! endTs ) {
35
- return { startFormatted : '' , endFormatted : '' } ;
40
+ return null ;
36
41
}
37
42
38
43
const startDate = new Date ( startTs ) ;
@@ -47,23 +52,73 @@ function getStartAndEndFormatted(
47
52
isSameLocalDay &&
48
53
startDate . getHours ( ) === endDate . getHours ( ) &&
49
54
startDate . getMinutes ( ) === endDate . getMinutes ( ) ;
50
- const isSameSecond = isSameMinute && startDate . getSeconds ( ) === endDate . getSeconds ( ) ;
51
-
52
- const startFormatted = formatDateTime ( startTs , {
53
- language,
54
- dateStyle : 'medium' ,
55
- timeStyle : isSameMinute ? 'medium' : 'short' ,
56
- } ) ;
57
-
58
- const endFormatted = ! isSameSecond
59
- ? formatDateTime ( endTs , {
60
- language,
61
- dateStyle : isSameLocalDay ? undefined : 'medium' ,
62
- timeStyle : isSameMinute ? 'medium' : 'short' ,
63
- } )
64
- : null ;
65
-
66
- return { startFormatted, endFormatted } ;
55
+
56
+ if ( isSameMinute && startDate . getSeconds ( ) === endDate . getSeconds ( ) )
57
+ return (
58
+ < Trans
59
+ t = { t }
60
+ i18nKey = "common:items_displayed_same_datetime"
61
+ components = { { StartToEnd : < span /> } }
62
+ values = { {
63
+ date : formatDateTime ( startDate , {
64
+ language,
65
+ dateStyle : 'medium' ,
66
+ timeStyle : undefined ,
67
+ } ) ,
68
+ time : formatDateTime ( startDate , {
69
+ language,
70
+ dateStyle : undefined ,
71
+ timeStyle : 'short' ,
72
+ } ) ,
73
+ } }
74
+ />
75
+ ) ;
76
+
77
+ if ( isSameLocalDay || isSameMinute )
78
+ return (
79
+ < Trans
80
+ t = { t }
81
+ i18nKey = "common:items_displayed_same_date"
82
+ components = { { StartToEnd : < span /> } }
83
+ values = { {
84
+ date : formatDateTime ( startDate , {
85
+ language,
86
+ dateStyle : 'medium' ,
87
+ timeStyle : undefined ,
88
+ } ) ,
89
+ start : formatDateTime ( startTs , {
90
+ language,
91
+ dateStyle : undefined ,
92
+ timeStyle : isSameMinute ? 'medium' : 'short' ,
93
+ } ) ,
94
+ end : formatDateTime ( endTs , {
95
+ language,
96
+ dateStyle : undefined ,
97
+ timeStyle : isSameMinute ? 'medium' : 'short' ,
98
+ } ) ,
99
+ } }
100
+ />
101
+ ) ;
102
+
103
+ return (
104
+ < Trans
105
+ t = { t }
106
+ i18nKey = "common:items_displayed_dates"
107
+ components = { { StartToEnd : < span /> } }
108
+ values = { {
109
+ start : formatDateTime ( startTs , {
110
+ language,
111
+ dateStyle : 'medium' ,
112
+ timeStyle : 'short' ,
113
+ } ) ,
114
+ end : formatDateTime ( endTs , {
115
+ language,
116
+ dateStyle : 'medium' ,
117
+ timeStyle : 'short' ,
118
+ } ) ,
119
+ } }
120
+ />
121
+ ) ;
67
122
}
68
123
69
124
export function CursorPaginationButtons ( {
@@ -73,7 +128,6 @@ export function CursorPaginationButtons({
73
128
onPaginationChange,
74
129
hideBoundaries,
75
130
} : CursorPaginationsButtonsProps ) {
76
- const { t } = useTranslation ( [ 'common' ] ) ;
77
131
const language = useFormatLanguage ( ) ;
78
132
79
133
const startTs = items [ 0 ] ?. createdAt ;
@@ -95,38 +149,12 @@ export function CursorPaginationButtons({
95
149
onPaginationChange ( pagination ) ;
96
150
} ;
97
151
98
- const { startFormatted, endFormatted } = getStartAndEndFormatted ( startTs , endTs , language ) ;
99
-
100
152
const previousDisabled = ! hasPreviousPage ;
101
153
const nextDisabled = ! hasNextPage ;
102
154
103
- const sameSecondBoundaries = (
104
- < span >
105
- { t ( 'common:items_displayed' , {
106
- time : startFormatted ,
107
- } ) }
108
- </ span >
109
- ) ;
110
- const defaultBoundaries = (
111
- < Trans
112
- t = { t }
113
- i18nKey = "common:items_displayed_datetime"
114
- components = { { StartToEnd : < span /> } }
115
- values = { {
116
- start : startFormatted ,
117
- end : endFormatted ,
118
- } }
119
- />
120
- ) ;
121
-
122
155
return (
123
156
< div className = "flex items-center justify-end gap-2" >
124
- { hideBoundaries || ( startFormatted === '' && endFormatted === '' )
125
- ? null
126
- : endFormatted === null
127
- ? sameSecondBoundaries
128
- : defaultBoundaries }
129
-
157
+ { hideBoundaries ? null : < FormattedDatesRange { ...{ startTs, endTs, language } } /> }
130
158
< Button onClick = { fetchPrevious } variant = "secondary" disabled = { previousDisabled } >
131
159
< Icon icon = "arrow-left" className = "size-4" />
132
160
</ Button >
0 commit comments