Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix visible toast messages flickering when one disappears #4749

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/renderer/components/ft-toast/ft-toast.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { defineComponent } from 'vue'
import FtToastEvents from './ft-toast-events.js'

let id = 0

export default defineComponent({
name: 'FtToast',
data: function () {
Expand All @@ -15,7 +17,9 @@ export default defineComponent({
FtToastEvents.removeEventListener('toast-open', this.open)
},
methods: {
performAction: function (index) {
performAction: function (id) {
const index = this.toasts.findIndex(toast => id === toast.id)

this.toasts[index].action()
this.remove(index)
},
Expand All @@ -26,7 +30,13 @@ export default defineComponent({
toast.isOpen = false
},
open: function ({ detail: { message, time, action } }) {
const toast = { message: message, action: action || (() => { }), isOpen: false, timeout: null }
const toast = {
message: message,
action: action || (() => { }),
isOpen: false,
timeout: null,
id: id++
}
toast.timeout = setTimeout(this.close, time || 3000, toast)
setTimeout(() => { toast.isOpen = true })
if (this.toasts.length > 4) {
Expand Down
10 changes: 5 additions & 5 deletions src/renderer/components/ft-toast/ft-toast.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<template>
<div class="toast-holder">
<div
v-for="(toast, index) in toasts"
:key="'toast-' + index"
v-for="toast in toasts"
:key="toast.id"
class="toast"
:class="{ closed: !toast.isOpen, open: toast.isOpen }"
tabindex="0"
role="status"
@click="performAction(index)"
@keydown.enter.prevent="performAction(index)"
@keydown.space.prevent="performAction(index)"
@click="performAction(toast.id)"
@keydown.enter.prevent="performAction(toast.id)"
@keydown.space.prevent="performAction(toast.id)"
>
<p class="message">
{{ toast.message }}
Expand Down
Loading