forked from processing/p5.js-web-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoast.js
39 lines (36 loc) · 1009 Bytes
/
toast.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import * as ActionTypes from '../../../constants';
export function hideToast() {
return {
type: ActionTypes.HIDE_TOAST
};
}
/**
* Temporary fix until #2206 is merged.
* Supports legacy two-action syntax:
* dispatch(setToastText('Toast.SketchFailedSave'));
* dispatch(showToast(6000));
* And also supports proposed single-action syntax with message and optional timeout.
* dispatch(showToast('Toast.SketchFailedSave'));
* dispatch(showToast('Toast.SketchSaved', 6000));
*/
export function showToast(textOrTime, timeout = 6000) {
return (dispatch) => {
let time = timeout;
if (typeof textOrTime === 'string') {
// eslint-disable-next-line no-use-before-define
dispatch(setToastText(textOrTime));
} else {
time = textOrTime;
}
dispatch({
type: ActionTypes.SHOW_TOAST
});
setTimeout(() => dispatch(hideToast()), time);
};
}
export function setToastText(text) {
return {
type: ActionTypes.SET_TOAST_TEXT,
text
};
}