Skip to content

Commit

Permalink
Avoid many snackbar messages
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Aug 27, 2024
1 parent ceccbd6 commit 0ccff32
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions packages/core/ui/SnackbarModel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { NotificationLevel, SnackAction } from '../util/types'
import Report from '@mui/icons-material/Report'

// lazies

const ErrorMessageStackTraceDialog = lazy(
() => import('@jbrowse/core/ui/ErrorMessageStackTraceDialog'),
)
Expand All @@ -28,8 +27,19 @@ export default function SnackbarModel() {
return types
.model({})
.volatile(() => ({
/**
* #volatile
*/
snackbarMessages: observable.array<SnackbarMessage>(),
}))
.views(self => ({
/**
* #getter
*/
get snackbarMessageSet() {
return new Map(self.snackbarMessages.map(s => [s.message, s]))
},
}))
.actions(self => ({
/**
* #action
Expand All @@ -42,6 +52,10 @@ export default function SnackbarModel() {
}, 5000)
}
},

/**
* #action
*/
notifyError(errorMessage: string, error?: unknown, extra?: unknown) {
this.notify(errorMessage, 'error', {
name: <Report />,
Expand All @@ -66,7 +80,9 @@ export default function SnackbarModel() {
level?: NotificationLevel,
action?: SnackAction,
) {
return self.snackbarMessages.push({ message, level, action })
if (action || !self.snackbarMessageSet.has(message)) {
self.snackbarMessages.push({ message, level, action })
}
},
/**
* #action
Expand All @@ -78,8 +94,8 @@ export default function SnackbarModel() {
* #action
*/
removeSnackbarMessage(message: string) {
const element = self.snackbarMessages.find(f => f.message === message)
if (element) {
const element = self.snackbarMessageSet.get(message)
if (element !== undefined) {
self.snackbarMessages.remove(element)
}
},
Expand Down

0 comments on commit 0ccff32

Please sign in to comment.