diff --git a/frontend/src/components/Notifications.tsx b/frontend/src/components/Notifications.tsx index e05037f8..33eb58fa 100644 --- a/frontend/src/components/Notifications.tsx +++ b/frontend/src/components/Notifications.tsx @@ -1,101 +1,101 @@ -import { Fragment, useEffect, useState } from 'react'; -import loadNotifications, { NotificationPages } from '../api/loader/loadNotifications'; -import iconStop from '/img/icon-stop.svg'; -import stopTaskByName from '../api/actions/stopTaskByName'; - -type NotificationType = { - title: string; - group: string; - api_stop: boolean; - level: string; - id: string; - command: boolean | string; - messages: string[]; - progress: number; -}; - -type NotificationResponseType = NotificationType[]; - -type NotificationsProps = { - pageName: NotificationPages; - includeReindex?: boolean; - update?: boolean; - setShouldRefresh?: (isDone: boolean) => void; -}; - -const Notifications = ({ - pageName, - includeReindex = false, - update, - setShouldRefresh, -}: NotificationsProps) => { - const [notificationResponse, setNotificationResponse] = useState([]); - - useEffect(() => { - const intervalId = setInterval(async () => { - const notifications = await loadNotifications(pageName, includeReindex); - - if (notifications.length === 0) { - setNotificationResponse(notifications); - clearInterval(intervalId); - setShouldRefresh?.(true); - return; - } else { - setShouldRefresh?.(false); - } - - setNotificationResponse(notifications); - }, 500); - - return () => { - clearInterval(intervalId); - }; - }, [pageName, update, setShouldRefresh, includeReindex]); - - if (notificationResponse.length === 0) { - return []; - } - - return ( - <> - {notificationResponse.map(notification => ( -
-

{notification.title}

-

- {notification.messages.map(message => { - return ( - - {message} -
-
- ); - })} -

-
- {notification['api_stop'] && notification.command !== 'STOP' && ( - stop icon { - await stopTaskByName(notification.id); - }} - /> - )} -
-
-
- ))} - - ); -}; - -export default Notifications; +import { Fragment, useEffect, useState } from 'react'; +import loadNotifications, { NotificationPages } from '../api/loader/loadNotifications'; +import iconStop from '/img/icon-stop.svg'; +import stopTaskByName from '../api/actions/stopTaskByName'; + +type NotificationType = { + title: string; + group: string; + api_stop: boolean; + level: string; + id: string; + command: boolean | string; + messages: string[]; + progress: number; +}; + +type NotificationResponseType = NotificationType[]; + +type NotificationsProps = { + pageName: NotificationPages; + includeReindex?: boolean; + update?: boolean; + setShouldRefresh?: (isDone: boolean) => void; +}; + +const Notifications = ({ + pageName, + includeReindex = false, + update, + setShouldRefresh, +}: NotificationsProps) => { + const [notificationResponse, setNotificationResponse] = useState([]); + + useEffect(() => { + const intervalId = setInterval(async () => { + const notifications = await loadNotifications(pageName, includeReindex); + + if (notifications.length === 0) { + setNotificationResponse(notifications); + clearInterval(intervalId); + setShouldRefresh?.(true); + return; + } else { + setShouldRefresh?.(false); + } + + setNotificationResponse(notifications); + }, 500); + + return () => { + clearInterval(intervalId); + }; + }, [pageName, update, setShouldRefresh, includeReindex]); + + if (notificationResponse.length === 0) { + return []; + } + + return ( + <> + {notificationResponse.map(notification => ( +
+

{notification.title}

+

+ {notification.messages.map?.(message => { + return ( + + {message} +
+
+ ); + }) || notification.messages} +

+
+ {notification['api_stop'] && notification.command !== 'STOP' && ( + stop icon { + await stopTaskByName(notification.id); + }} + /> + )} +
+
+
+ ))} + + ); +}; + +export default Notifications;