Skip to content

Commit 656f1d1

Browse files
committed
Add a dismiss button to close snackBar.
close #9527
1 parent b7ee82b commit 656f1d1

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/common/gui/base/SnackBar.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { LayerType } from "../../../RootView"
1010
import type { ClickHandler } from "./GuiUtils"
1111
import { assertMainOrNode } from "../../api/common/Env"
1212
import { debounce, isEmpty, remove } from "@tutao/tutanota-utils"
13+
import { IconButton, IconButtonAttrs } from "./IconButton"
1314

1415
assertMainOrNode()
1516
const SNACKBAR_SHOW_TIME = 6000
@@ -21,6 +22,7 @@ export type SnackBarButtonAttrs = {
2122
type SnackBarAttrs = {
2223
message: MaybeTranslation
2324
button: ButtonAttrs | null
25+
dismissButton?: IconButtonAttrs
2426
}
2527
type QueueItem = SnackBarAttrs & {
2628
onClose: ((timedOut: boolean) => unknown) | null
@@ -39,6 +41,7 @@ class SnackBar implements Component<SnackBarAttrs> {
3941
return m(".snackbar-content.flex.flex-space-between.border-radius.plr.pb-xs.pt-xs", [
4042
m(".flex.center-vertically.smaller", lang.getTranslationText(vnode.attrs.message)),
4143
vnode.attrs.button ? m(".flex-end.center-vertically.pl", m(Button, vnode.attrs.button)) : null,
44+
vnode.attrs.dismissButton ? m(".flex.items-center.justify-right", [m(IconButton, vnode.attrs.dismissButton)]) : null,
4245
])
4346
}
4447
}
@@ -66,13 +69,14 @@ function makeButtonAttrsForSnackBar(button: SnackBarButtonAttrs): ButtonAttrs {
6669
export function showSnackBar(args: {
6770
message: MaybeTranslation
6871
button: SnackBarButtonAttrs
72+
dismissButton?: IconButtonAttrs
6973
onShow?: () => unknown
7074
onClose?: (timedOut: boolean) => unknown
7175
waitingTime?: number
7276
showingTime?: number
7377
replace?: boolean
7478
}): () => void {
75-
const { message, button, onClose, onShow, waitingTime, showingTime = SNACKBAR_SHOW_TIME, replace = false } = args
79+
const { message, button, dismissButton, onClose, onShow, waitingTime, showingTime = SNACKBAR_SHOW_TIME, replace = false } = args
7680

7781
let cancelled = false
7882
const doCancel = {
@@ -82,9 +86,11 @@ export function showSnackBar(args: {
8286
}
8387

8488
const buttonAttrs = makeButtonAttrsForSnackBar(button)
89+
8590
const queueEntry: QueueItem = {
8691
message: message,
8792
button: buttonAttrs,
93+
dismissButton: dismissButton,
8894
onClose: onClose ?? null,
8995
onShow: onShow ?? null,
9096
doCancel,
@@ -144,7 +150,7 @@ function getSnackBarPosition() {
144150
}
145151

146152
function showNextNotification() {
147-
const { message, button, onClose, onShow, doCancel, showingTime } = notificationQueue[0] //we shift later because it is still shown
153+
const { message, button, dismissButton, onClose, onShow, doCancel, showingTime } = notificationQueue[0] //we shift later because it is still shown
148154
clearTimeout(currentAnimationTimeout)
149155
currentAnimationTimeout = null
150156
const closeFunction = displayOverlay(
@@ -154,6 +160,7 @@ function showNextNotification() {
154160
m(SnackBar, {
155161
message,
156162
button,
163+
dismissButton: dismissButton,
157164
}),
158165
},
159166
"slide-bottom",

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ async function showUndoMoveMailSnackbar(
163163
clearUndoAction()
164164
},
165165
},
166+
dismissButton: {
167+
title: "close_alt",
168+
click: () => cancelSnackbar(),
169+
icon: Icons.Cancel,
170+
},
166171
onShow: () => {
167172
// we don't want to immediately set the undo action, as the user might be looking at a different snackbar
168173
// than this one momentarily

0 commit comments

Comments
 (0)