Skip to content

Commit 7c37443

Browse files
hrb-hubBijinDev
andcommitted
(wip)
Co-authored-by: bir <[email protected]>
1 parent 846bab0 commit 7c37443

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

src/common/gui/base/SnackBar.ts

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { styles } from "../styles"
99
import { LayerType } from "../../../RootView"
1010
import type { ClickHandler } from "./GuiUtils"
1111
import { assertMainOrNode } from "../../api/common/Env"
12-
import { debounce, isEmpty, remove } from "@tutao/tutanota-utils"
12+
import { isEmpty, isNotEmpty, remove } from "@tutao/tutanota-utils"
1313

1414
assertMainOrNode()
1515
const SNACKBAR_SHOW_TIME = 6000
@@ -26,7 +26,8 @@ type SnackBarAttrs = {
2626
type QueueItem = Omit<SnackBarAttrs, "onHoverChange"> & {
2727
onClose: ((timedOut: boolean) => unknown) | null
2828
onShow: (() => unknown) | null
29-
doCancel: { cancel: () => unknown }
29+
// doCancel: { cancel: () => unknown }
30+
onCancel: () => unknown
3031
/** display time in ms */
3132
showingTime: number
3233
}
@@ -87,10 +88,15 @@ export function showSnackBar(args: {
8788
const { message, button, onClose, onShow, waitingTime, showingTime = SNACKBAR_SHOW_TIME, replace = false } = args
8889

8990
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()
94100
}
95101

96102
const buttonAttrs = makeButtonAttrsForSnackBar(button)
@@ -99,23 +105,19 @@ export function showSnackBar(args: {
99105
button: buttonAttrs,
100106
onClose: onClose ?? null,
101107
onShow: onShow ?? null,
102-
doCancel,
108+
onCancel: cancelSnackbar,
109+
// doCancel,
103110
showingTime,
104111
}
105112

106-
const cancelSnackbar = () => {
107-
cancelled = true
108-
doCancel.cancel()
109-
}
110-
111113
const triggerSnackbar = () => {
112114
if (cancelled) {
113115
return
114116
}
115117

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
119121
notificationQueue.splice(1, 0, queueEntry)
120122
if (cancelCurrentSnackbar) {
121123
cancelCurrentSnackbar()
@@ -133,7 +135,7 @@ export function showSnackBar(args: {
133135
}
134136

135137
if (waitingTime) {
136-
debounce(waitingTime, triggerSnackbar)()
138+
setTimeout(() => triggerSnackbar(), waitingTime)
137139
} else {
138140
triggerSnackbar()
139141
}
@@ -156,7 +158,7 @@ function getSnackBarPosition() {
156158
}
157159

158160
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
160162
clearTimeout(currentAnimationTimeout)
161163
currentAnimationTimeout = null
162164
let hovered = false
@@ -179,10 +181,12 @@ function showNextNotification() {
179181
)
180182

181183
let closed = false
184+
let hoveredTimeoutId: TimeoutID | null = null
182185

183186
const closeAndOpenNext = (timedOut: boolean) => {
187+
console.log("closeAndOpenNext..............................")
184188
if (timedOut && hovered) {
185-
debounce(1000, closeAndOpenNext)(true)
189+
hoveredTimeoutId = setTimeout(() => closeAndOpenNext(true), 3000)
186190
return
187191
}
188192

@@ -209,6 +213,7 @@ function showNextNotification() {
209213
const originClickHandler: ClickHandler | undefined = button.click
210214

211215
button.click = (e, dom) => {
216+
clearTimeout(hoveredTimeoutId)
212217
clearTimeout(autoRemoveTimer)
213218
originClickHandler?.(e, dom)
214219
closeAndOpenNext(false)
@@ -219,6 +224,7 @@ function showNextNotification() {
219224
doCancel.cancel = () => {
220225
if (!closed) {
221226
closed = true
227+
clearTimeout(hoveredTimeoutId)
222228
clearTimeout(autoRemoveTimer)
223229
closeAndOpenNext(false)
224230
}

src/mail-app/mail/view/MailGuiUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ async function showUndoMoveMailSnackbar(
131131
result = MoveMailSnackbarResult.Undo
132132
resolve(result)
133133

134-
cancelSnackbar?.()
134+
// cancelSnackbar?.()
135135
const mails = await resolveMails()
136136
await mailModel.moveMails(getIds(mails), undoFolder, MoveMode.Mails)
137137
},

0 commit comments

Comments
 (0)