@@ -9,7 +9,7 @@ import { styles } from "../styles"
9
9
import { LayerType } from "../../../RootView"
10
10
import type { ClickHandler } from "./GuiUtils"
11
11
import { assertMainOrNode } from "../../api/common/Env"
12
- import { debounce , isEmpty , remove } from "@tutao/tutanota-utils"
12
+ import { isEmpty , isNotEmpty , remove } from "@tutao/tutanota-utils"
13
13
14
14
assertMainOrNode ( )
15
15
const SNACKBAR_SHOW_TIME = 6000
@@ -26,7 +26,8 @@ type SnackBarAttrs = {
26
26
type QueueItem = Omit < SnackBarAttrs , "onHoverChange" > & {
27
27
onClose : ( ( timedOut : boolean ) => unknown ) | null
28
28
onShow : ( ( ) => unknown ) | null
29
- doCancel : { cancel : ( ) => unknown }
29
+ // doCancel: { cancel: () => unknown }
30
+ onCancel : ( ) => unknown
30
31
/** display time in ms */
31
32
showingTime : number
32
33
}
@@ -87,10 +88,15 @@ export function showSnackBar(args: {
87
88
const { message, button, onClose, onShow, waitingTime, showingTime = SNACKBAR_SHOW_TIME , replace = false } = args
88
89
89
90
let cancelled = false
90
- const doCancel = {
91
- cancel : ( ) => {
92
- remove ( notificationQueue , queueEntry )
93
- } ,
91
+ // const doCancel = {
92
+ // cancel: () => {
93
+ // remove(notificationQueue, queueEntry)
94
+ // },
95
+ // }
96
+ const cancelSnackbar = ( ) => {
97
+ cancelled = true
98
+ remove ( notificationQueue , queueEntry )
99
+ // doCancel.cancel()
94
100
}
95
101
96
102
const buttonAttrs = makeButtonAttrsForSnackBar ( button )
@@ -99,23 +105,19 @@ export function showSnackBar(args: {
99
105
button : buttonAttrs ,
100
106
onClose : onClose ?? null ,
101
107
onShow : onShow ?? null ,
102
- doCancel,
108
+ onCancel : cancelSnackbar ,
109
+ // doCancel,
103
110
showingTime,
104
111
}
105
112
106
- const cancelSnackbar = ( ) => {
107
- cancelled = true
108
- doCancel . cancel ( )
109
- }
110
-
111
113
const triggerSnackbar = ( ) => {
112
114
if ( cancelled ) {
113
115
return
114
116
}
115
117
116
- if ( replace && ! isEmpty ( notificationQueue ) ) {
117
- // there is currently a notification being displayed, so we should put this one ahead of it and then run its
118
- // cancel function
118
+ if ( replace && isNotEmpty ( notificationQueue ) ) {
119
+ // there is currently a notification being displayed, so we should put this one after it and then run the
120
+ // currently displayed notification's cancel function
119
121
notificationQueue . splice ( 1 , 0 , queueEntry )
120
122
if ( cancelCurrentSnackbar ) {
121
123
cancelCurrentSnackbar ( )
@@ -133,7 +135,7 @@ export function showSnackBar(args: {
133
135
}
134
136
135
137
if ( waitingTime ) {
136
- debounce ( waitingTime , triggerSnackbar ) ( )
138
+ setTimeout ( ( ) => triggerSnackbar ( ) , waitingTime )
137
139
} else {
138
140
triggerSnackbar ( )
139
141
}
@@ -156,7 +158,7 @@ function getSnackBarPosition() {
156
158
}
157
159
158
160
function showNextNotification ( ) {
159
- const { message, button, onClose, onShow, doCancel , showingTime } = notificationQueue [ 0 ] //we shift later because it is still shown
161
+ const { message, button, onClose, onShow, onCancel , showingTime } = notificationQueue [ 0 ] //we shift later because it is still shown
160
162
clearTimeout ( currentAnimationTimeout )
161
163
currentAnimationTimeout = null
162
164
let hovered = false
@@ -179,10 +181,12 @@ function showNextNotification() {
179
181
)
180
182
181
183
let closed = false
184
+ let hoveredTimeoutId : TimeoutID | null = null
182
185
183
186
const closeAndOpenNext = ( timedOut : boolean ) => {
187
+ console . log ( "closeAndOpenNext.............................." )
184
188
if ( timedOut && hovered ) {
185
- debounce ( 1000 , closeAndOpenNext ) ( true )
189
+ hoveredTimeoutId = setTimeout ( ( ) => closeAndOpenNext ( true ) , 3000 )
186
190
return
187
191
}
188
192
@@ -209,6 +213,7 @@ function showNextNotification() {
209
213
const originClickHandler : ClickHandler | undefined = button . click
210
214
211
215
button . click = ( e , dom ) => {
216
+ clearTimeout ( hoveredTimeoutId )
212
217
clearTimeout ( autoRemoveTimer )
213
218
originClickHandler ?.( e , dom )
214
219
closeAndOpenNext ( false )
@@ -219,6 +224,7 @@ function showNextNotification() {
219
224
doCancel . cancel = ( ) => {
220
225
if ( ! closed ) {
221
226
closed = true
227
+ clearTimeout ( hoveredTimeoutId )
222
228
clearTimeout ( autoRemoveTimer )
223
229
closeAndOpenNext ( false )
224
230
}
0 commit comments