feat: updating useNotification hook

- automatically generates id and timestamp
- components just have to provide a message
This commit is contained in:
Mose Müller
2023-08-10 11:04:43 +02:00
parent 6e4909ece5
commit 04e0e9e8b2
9 changed files with 23 additions and 34 deletions

View File

@ -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);
}