Skip to content

Commit 700c518

Browse files
committed
display the timeout label
1 parent 5090ae6 commit 700c518

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

src/features/settings/components/DNDSettings.tsx

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useState } from 'react'
22
import Select, { SingleValue } from 'react-select'
33
import { trackDNDEnable } from 'src/lib/analytics'
44
import { useUserPreferences } from 'src/stores/preferences'
5+
import { diffBetweenTwoDatesInMinutes } from 'src/utils/DateUtils'
56

67
type DndOption = {
78
value: number | 'always'
@@ -30,10 +31,11 @@ export const DNDSettings = ({ setShowSettings }: DNDSettingsProps) => {
3031
}
3132

3233
if (typeof selectedDNDDuration === 'string') {
33-
setDNDDuration('always')
34+
setDNDDuration(selectedDNDDuration)
3435
} else {
3536
const value = selectedDNDDuration as number
36-
const futureDate = new Date(new Date().getTime() + value * 60000)
37+
const futureDate = new Date()
38+
futureDate.setMinutes(futureDate.getMinutes() + value)
3739
setDNDDuration({
3840
value: selectedDNDDuration,
3941
countdown: futureDate.getTime(),
@@ -64,6 +66,22 @@ export const DNDSettings = ({ setShowSettings }: DNDSettingsProps) => {
6466
}
6567
}
6668

69+
const timeoutLabel = (): string | undefined => {
70+
if (typeof DNDDuration === 'object') {
71+
const DNDDurationObject = DNDDuration as {
72+
value: number
73+
countdown: number
74+
}
75+
const futureDate = new Date(DNDDurationObject.countdown)
76+
const now = new Date()
77+
return `DND will become inactive in ${diffBetweenTwoDatesInMinutes(
78+
futureDate.getTime(),
79+
now.getTime()
80+
)} Minutes`
81+
}
82+
83+
return undefined
84+
}
6785
return (
6886
<div className="settingRow">
6987
<p className="settingTitle">
@@ -88,6 +106,11 @@ export const DNDSettings = ({ setShowSettings }: DNDSettingsProps) => {
88106

89107
<button onClick={onApplyClicked}>Apply</button>
90108
</div>
109+
{timeoutLabel() && (
110+
<div className="settingHint">
111+
<p>{timeoutLabel()}</p>
112+
</div>
113+
)}
91114
</div>
92115
</div>
93116
)

src/utils/DateUtils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
export const diffBetweenTwoDatesInDays = (oldestDate: number, newestDate: number) => {
22
return Math.floor((newestDate - oldestDate) / (1000 * 60 * 60 * 24));
3+
}
4+
5+
export const diffBetweenTwoDatesInMinutes = (oldestDate: number, newestDate: number) => {
6+
return Math.floor((oldestDate - newestDate) / (1000 * 60 ));
37
}

0 commit comments

Comments
 (0)