Skip to content

Commit

Permalink
fix: relative hours for email reset in notifications overview
Browse files Browse the repository at this point in the history
`Tooltip` of `Email Notifications` showed timestamp instead of `relative time`

BEDS-941
  • Loading branch information
marcel-bitfly committed Dec 9, 2024
1 parent fc27dc0 commit f875e7d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
7 changes: 5 additions & 2 deletions frontend/components/notifications/NotificationsOverview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ const notificationsTotal = computed(() => {
const { user } = useUserStore()
const mailLimit = computed(() => user.value?.premium_perks.email_notifications_per_day ?? 0)
const resetHours = computed(() => overview.value?.next_email_count_reset_timestamp ?? 0)
const resetHours = computed(
() => getRelativeTime(overview.value?.next_email_count_reset_timestamp ?? 0),
)
const tooltipEmail = computed(() => {
return $t('notifications.overview.email_tooltip', {
hours: resetHours.value,
in_x_hours: resetHours.value,
limit: mailLimit.value,
})
})
Expand Down
2 changes: 1 addition & 1 deletion frontend/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@
},
"overview": {
"email_activate": "Click here to activate Email notifications",
"email_tooltip": "Your current limit is { limit } emails per day. Your email limit resets in { hours } hours. Upgrade to premium for more.",
"email_tooltip": "Your current limit is { limit } emails per day. Your email limit resets { in_x_hours }. Upgrade to premium for more.",
"headers": {
"account_groups": "Most notified account groups",
"email_notifications": "Email Notifications",
Expand Down
18 changes: 18 additions & 0 deletions frontend/utils/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,21 @@ export const formatSecondsTo = (seconds: number,
minutes,
}
}

export const getRelativeTime = (timestampInSeconds: number, {
locale = 'en-US',
}: {
locale?: string,
} = {}) => {
const seconds = timestampInSeconds - (Date.now() / 1000)
const minutes = (seconds / 60)
const hours = (minutes / 60)

if (hours >= 1 || hours <= -1) {
return new Intl.RelativeTimeFormat(locale).format(Math.round(hours), 'hours')
}
if (minutes >= 1 || minutes <= -1) {
return new Intl.RelativeTimeFormat(locale).format(Math.round(minutes), 'minutes')
}
return new Intl.RelativeTimeFormat(locale).format(Math.round(seconds), 'seconds')
}

0 comments on commit f875e7d

Please sign in to comment.