EN · DE · RU · FR · ES

#2482: toast.js

projectforge-webapp/src/actions/toast.js Module JavaScript, projectforge-webapp/src/actions/toast.js 37 lignes · 30 code · 0 commentaires · 7 vides
Objectif : Application web React : toast.js. toast.js fait partie de l'application open-source de gestion de projet ProjectForge.

Source (100 premières lignes)

import revisedRandomId from '../utilities/revisedRandomId';

export const TOAST_ADD = 'TOAST_ADD';
export const TOAST_REMOVE = 'TOAST_REMOVE';
export const TOAST_CLEAR_ALL = 'TOAST_CLEAR_ALL';

const add = (id, message, color) => ({
    type: TOAST_ADD,
    payload: {
        id,
        message,
        color,
    },
});

export const removeToast = (id) => ({
    type: TOAST_REMOVE,
    payload: { id },
});

export const clearAllToasts = () => ({
    type: TOAST_CLEAR_ALL,
});

export const addToast = (
    message,
    color = undefined,
    stay = true,
) => (dispatch) => {
    const id = revisedRandomId();

    dispatch(add(id, message, color));

    if (stay === false) {
        window.setTimeout(() => dispatch(removeToast(id)), 10 * 1000);
    }
};

Historique Git

bbd81edc3 es-lint, nouvelles versions js.
30f6d85a8 #98 terminer la page mon compte
993957ec7 implémenter les actions toast

bbd81edc3

es-lint, nouvelles versions js.
bbd81edc3f6b2fd975756421148651d4d75eaf33
diff --git a/projectforge-webapp/src/actions/toast.js b/projectforge-webapp/src/actions/toast.js
index 021f97ea0..9b05ebd7b 100644
--- a/projectforge-webapp/src/actions/toast.js
+++ b/projectforge-webapp/src/actions/toast.js
@@ -13,7 +13,7 @@ const add = (id, message, color) => ({
     },
 });
 
-export const removeToast = id => ({
+export const removeToast = (id) => ({
     type: TOAST_REMOVE,
     payload: { id },
 });

30f6d85a8

#98 terminer la page mon compte
30f6d85a8445d21638d7087bc653ef6352cdab13
diff --git a/projectforge-webapp/src/actions/toast.js b/projectforge-webapp/src/actions/toast.js
index 9ac3a0ab1..021f97ea0 100644
--- a/projectforge-webapp/src/actions/toast.js
+++ b/projectforge-webapp/src/actions/toast.js
@@ -25,7 +25,7 @@ export const clearAllToasts = () => ({
 export const addToast = (
     message,
     color = undefined,
-    stay = false,
+    stay = true,
 ) => (dispatch) => {
     const id = revisedRandomId();
 

993957ec7

implémenter les actions toast
993957ec76a16ce0d45c79ae6ee1dcdefe048a88
diff --git a/projectforge-webapp/src/actions/toast.js b/projectforge-webapp/src/actions/toast.js
new file mode 100644
index 000000000..9ac3a0ab1
--- /dev/null
+++ b/projectforge-webapp/src/actions/toast.js
@@ -0,0 +1,37 @@
+import revisedRandomId from '../utilities/revisedRandomId';
+
+export const TOAST_ADD = 'TOAST_ADD';
+export const TOAST_REMOVE = 'TOAST_REMOVE';
+export const TOAST_CLEAR_ALL = 'TOAST_CLEAR_ALL';
+
+const add = (id, message, color) => ({
+    type: TOAST_ADD,
+    payload: {
+        id,
+        message,
+        color,
+    },
+});
+
+export const removeToast = id => ({
+    type: TOAST_REMOVE,
+    payload: { id },
+});
+
+export const clearAllToasts = () => ({
+    type: TOAST_CLEAR_ALL,
+});
+
+export const addToast = (
+    message,
+    color = undefined,
+    stay = false,
+) => (dispatch) => {
+    const id = revisedRandomId();
+
+    dispatch(add(id, message, color));
+
+    if (stay === false) {
+        window.setTimeout(() => dispatch(removeToast(id)), 10 * 1000);
+    }
+};