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

[Bug] Backdrop not removed when 2 notifications with same timeout #57

Open
Meshz opened this issue Aug 20, 2018 · 6 comments
Open

[Bug] Backdrop not removed when 2 notifications with same timeout #57

Meshz opened this issue Aug 20, 2018 · 6 comments

Comments

@Meshz
Copy link

Meshz commented Aug 20, 2018

Hello,

First of all, thank you for this package. I noticed that when you programatically call 2 notifications with the same timeout, the backdrop is not removed. Do you have any solution for this problem?

Thank you!

@alekstar79
Copy link

I have the same problem when I call a notification with the backdrop enabled, the following notification calls also work with the backdrop enabled, ignoring the configuration settings. Does not help even a forced call to vm.$snotify.setDefaults(config: SnotifyDefaults)

@Meshz
Copy link
Author

Meshz commented Oct 23, 2018

Hello,

As I had many problems with this bug, I tweaked your package by adding an initTime to each toast (timestamp divided by 100 and rounded for precision purposes): this.toast.initTime = Math.round(+new Date()/100) in initToast method. Then in stateChanged method, I loop through each toast and group them by initTime. So when 2 toasts are launched at the same time, they are seen as one.

For some reason I had to change the template to (_vm.backdrop > 0) instead of (_vm.backdrop >= 0) because the line setTimeout(function () { return _this.$snotify.remove(_this.toast.id, true); }, _this.toast.config.animation.time / 2) in onRemove method seems to recreate a backdrop with 0 opacity.

HTH you finding a way to fix this. Thank you again!

@Mornney
Copy link

Mornney commented Oct 26, 2018

I am having a similar issue with the backdrop not being removed.

I found this in the JS file:
// TODO: fix backdrop if more than one toast called in a row

Any news on when this will be fixed? Does anyone know a work around, at the moment the backdrop dosesnt get removed which then prevents users being able to access the form behind the backdrop

@Meshz
Copy link
Author

Meshz commented Oct 26, 2018

Basically, my fix is explained in my previous post. But here is what I did for now in vue-snotify.esm.js (kinda ugly but it works). HTH!

// --- Line 323
initToast: function () {
	this.toast.initTime = Math.round(+new Date()/100); // Added initTime
	if (this.toast.config.timeout > 0) {
		this.startTimeout(0);
	}
}
// --- Line 634
stateChanged: function (event) {
	let toastShown = []
	if (!this.withBackdrop.length) {
		return;
	} else {
		// --- Group toasts by initTime
		for (let i=0; i<this.withBackdrop.length; i++) {
			if(toastShown.indexOf(this.withBackdrop[i].initTime) == -1){
				toastShown.push(this.withBackdrop[i].initTime);
			}
		}
	}
	switch (event) {
		case 'mounted':
			if (this.backdrop < 0) {
				this.backdrop = 0;
			}
			break;
		case 'beforeShow':
			this.backdrop = this.withBackdrop[this.withBackdrop.length - 1].config.backdrop;
			break;
		case 'beforeHide':
			// --- Use groups to determine if one or more toasts shown
			if (toastShown.length === 1) {
				this.backdrop = 0;
			}
			break;
		case 'hidden':
			// --- Same as beforeHide
			if (toastShown.length === 1) {
				this.backdrop = -1;
			}
			break;
		}
	}
}
// --- Line 695
// --- Changed condition _vm.backdrop >= 0 to _vm.backdrop > 0 because backdrop is recreated with 0 opacity by second timeout in onRemove (line 400)
var __vue_render__$3 = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',[(_vm.backdrop > 0)?_c('div',{staticClass:"snotify-backdrop",style:({opacity: _vm.backdrop})}):_vm._e(),_vm._v(" "),_vm._l((_vm.notifications),function(position,index){return _c('div',{staticClass:"snotify",class:'snotify-' + index},_vm._l((_vm.notifications[index].slice(_vm.blockSize_a, _vm.blockSize_b)),function(toast){return _c('toast',{key:toast.id,attrs:{"toastData":toast},on:{"stateChanged":_vm.stateChanged}})}))})],2)};

@Mornney
Copy link

Mornney commented Oct 29, 2018

Thank you, will have a look at trying this.

Its better than my work around :)

@jeffbarretocopam
Copy link

jeffbarretocopam commented May 29, 2019

Basically, my fix is explained in my previous post. But here is what I did for now in vue-snotify.esm.js (kinda ugly but it works). HTH!

// --- Line 323
initToast: function () {
	this.toast.initTime = Math.round(+new Date()/100); // Added initTime
	if (this.toast.config.timeout > 0) {
		this.startTimeout(0);
	}
}
// --- Line 634
stateChanged: function (event) {
	let toastShown = []
	if (!this.withBackdrop.length) {
		return;
	} else {
		// --- Group toasts by initTime
		for (let i=0; i<this.withBackdrop.length; i++) {
			if(toastShown.indexOf(this.withBackdrop[i].initTime) == -1){
				toastShown.push(this.withBackdrop[i].initTime);
			}
		}
	}
	switch (event) {
		case 'mounted':
			if (this.backdrop < 0) {
				this.backdrop = 0;
			}
			break;
		case 'beforeShow':
			this.backdrop = this.withBackdrop[this.withBackdrop.length - 1].config.backdrop;
			break;
		case 'beforeHide':
			// --- Use groups to determine if one or more toasts shown
			if (toastShown.length === 1) {
				this.backdrop = 0;
			}
			break;
		case 'hidden':
			// --- Same as beforeHide
			if (toastShown.length === 1) {
				this.backdrop = -1;
			}
			break;
		}
	}
}
// --- Line 695
// --- Changed condition _vm.backdrop >= 0 to _vm.backdrop > 0 because backdrop is recreated with 0 opacity by second timeout in onRemove (line 400)
var __vue_render__$3 = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',[(_vm.backdrop > 0)?_c('div',{staticClass:"snotify-backdrop",style:({opacity: _vm.backdrop})}):_vm._e(),_vm._v(" "),_vm._l((_vm.notifications),function(position,index){return _c('div',{staticClass:"snotify",class:'snotify-' + index},_vm._l((_vm.notifications[index].slice(_vm.blockSize_a, _vm.blockSize_b)),function(toast){return _c('toast',{key:toast.id,attrs:{"toastData":toast},on:{"stateChanged":_vm.stateChanged}})}))})],2)};

Why you don't create that PR ? This is one of the solution

IronSinew added a commit to IronSinew/vue-snotify that referenced this issue Apr 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants