Browse Source

Toaster - add an auto close param (true by default)

all-modes
petitPapillon 8 years ago
parent
commit
bd24c1459f
  1. 3
      react/src/actions/actionCreators.js
  2. 7
      react/src/components/toaster/toaster-item.js
  3. 4
      react/src/components/toaster/toaster.js

3
react/src/actions/actionCreators.js

@ -190,13 +190,14 @@ export function toggleSendReceiveCoinFormsState() {
} }
} }
export function triggerToaster(display, message, title, _type) { export function triggerToaster(display, message, title, _type, autoClose = true) {
return { return {
type: ADD_TOASTER_MESSAGE, type: ADD_TOASTER_MESSAGE,
display, display,
message, message,
title, title,
_type, _type,
autoClose
} }
} }

7
react/src/components/toaster/toaster-item.js

@ -16,7 +16,8 @@ class ToasterItem extends React.Component {
display: false, display: false,
message: null, message: null,
type: null, type: null,
title: null title: null,
autoClose: true
}; };
this.dismissToast = this.dismissToast.bind(this); this.dismissToast = this.dismissToast.bind(this);
@ -33,6 +34,7 @@ class ToasterItem extends React.Component {
display: props.display, display: props.display,
type: props._type, type: props._type,
title: props.title, title: props.title,
autoClose: props.autoClose,
toastId: props.toastId toastId: props.toastId
}); });
} else { } else {
@ -41,6 +43,7 @@ class ToasterItem extends React.Component {
message: null, message: null,
type: null, type: null,
title: null, title: null,
autoClose: true,
toastId: null toastId: null
}); });
} }
@ -52,7 +55,7 @@ class ToasterItem extends React.Component {
renderToast() { renderToast() {
// ensure that setTimeout is called only once for each toast message // ensure that setTimeout is called only once for each toast message
if (!this.timeoutHandler) { if (this.state.autoClose && !this.timeoutHandler) {
this.timeoutHandler = setTimeout(() => { this.timeoutHandler = setTimeout(() => {
this.dismissToast(this.state.toastId); this.dismissToast(this.state.toastId);
}, DISPLAY_LENGTH_MILLIS); }, DISPLAY_LENGTH_MILLIS);

4
react/src/components/toaster/toaster.js

@ -27,10 +27,6 @@ class Toaster extends React.Component {
} }
} }
dismissToast(toastId) {
Store.dispatch(dismissToasterMessage(toastId));
}
renderToasts() { renderToasts() {
if (this.state.toasts && if (this.state.toasts &&
this.state.toasts.length) { this.state.toasts.length) {

Loading…
Cancel
Save