diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 892981a..fc2b1f7 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -132,9 +132,6 @@ const App = () => { // Extracting data from the notification const { parent_path, name, value: newValue } = value.data; - // Getting the current time in the required format - const timeString = new Date().toISOString().substring(11, 19); - // Dispatching the update to the reducer dispatch({ type: 'UPDATE_ATTRIBUTE', @@ -153,25 +150,13 @@ const App = () => { } // Creating a new notification - const newNotification = { - id: Math.random(), - time: timeString, - text: `${parent_path}.${name} changed to ${notificationMsg}.` - }; - + const newNotification = `${parent_path}.${name} changed to ${notificationMsg}.`; // Adding the new notification to the list notify(newNotification); } function onException(value: ExceptionMessage) { - const currentTime = new Date(); - const timeString = currentTime.toISOString().substr(11, 8); - - const newNotification = { - id: Math.random(), - time: timeString, - text: `${value.data.type}: ${value.data.exception}.` - }; + const newNotification = `${value.data.type}: ${value.data.exception}.`; notifyException(newNotification); } diff --git a/frontend/src/components/NotificationsComponent.tsx b/frontend/src/components/NotificationsComponent.tsx index bc5ddd5..990f541 100644 --- a/frontend/src/components/NotificationsComponent.tsx +++ b/frontend/src/components/NotificationsComponent.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { ToastContainer, Toast } from 'react-bootstrap'; -type Notification = { +export type Notification = { id: number; time: string; text: string; diff --git a/frontend/src/hooks/useNotification.ts b/frontend/src/hooks/useNotification.ts index 3553dce..3684f54 100644 --- a/frontend/src/hooks/useNotification.ts +++ b/frontend/src/hooks/useNotification.ts @@ -1,16 +1,20 @@ import { useState } from 'react'; -type NotificationMsg = { - id: number; - time: string; - text: string; -}; +import { Notification } from '../components/NotificationsComponent'; export const useNotification = () => { - const [notifications, setNotifications] = useState([]); + const [notifications, setNotifications] = useState([]); + + const notify = (text: string) => { + // Getting the current time in the required format + const timeString = new Date().toISOString().substring(11, 19); + // Adding an id to the notification to provide a way of removing it + const id = Math.random(); - const notify = (message: NotificationMsg) => { // Custom logic for notifications - setNotifications((prevNotifications) => [message, ...prevNotifications]); + setNotifications((prevNotifications) => [ + { id, text, time: timeString }, + ...prevNotifications + ]); }; const removeNotificationById = (id: number) => { diff --git a/src/pydase/frontend/asset-manifest.json b/src/pydase/frontend/asset-manifest.json index 2529c97..49d8354 100644 --- a/src/pydase/frontend/asset-manifest.json +++ b/src/pydase/frontend/asset-manifest.json @@ -1,13 +1,13 @@ { "files": { "main.css": "/static/css/main.398bc7f8.css", - "main.js": "/static/js/main.95543987.js", + "main.js": "/static/js/main.799e0879.js", "index.html": "/index.html", "main.398bc7f8.css.map": "/static/css/main.398bc7f8.css.map", - "main.95543987.js.map": "/static/js/main.95543987.js.map" + "main.799e0879.js.map": "/static/js/main.799e0879.js.map" }, "entrypoints": [ "static/css/main.398bc7f8.css", - "static/js/main.95543987.js" + "static/js/main.799e0879.js" ] } \ No newline at end of file diff --git a/src/pydase/frontend/index.html b/src/pydase/frontend/index.html index 9d68e4a..52a1353 100644 --- a/src/pydase/frontend/index.html +++ b/src/pydase/frontend/index.html @@ -1 +1 @@ -pydase App
\ No newline at end of file +pydase App
\ No newline at end of file diff --git a/src/pydase/frontend/static/js/main.95543987.js b/src/pydase/frontend/static/js/main.799e0879.js similarity index 97% rename from src/pydase/frontend/static/js/main.95543987.js rename to src/pydase/frontend/static/js/main.799e0879.js index 9233c7e..0c58260 100644 --- a/src/pydase/frontend/static/js/main.95543987.js +++ b/src/pydase/frontend/static/js/main.799e0879.js @@ -1,3 +1,3 @@ -/*! For license information please see main.95543987.js.LICENSE.txt */ -!function(){var e={694:function(e,t){var n;!function(){"use strict";var r={}.hasOwnProperty;function a(){for(var e=[],t=0;t