mirror of
https://github.com/Sonarr/Sonarr.git
synced 2026-04-21 22:05:38 -04:00
49 lines
1.1 KiB
TypeScript
49 lines
1.1 KiB
TypeScript
import React, { useEffect, useMemo } from 'react';
|
|
import { useAppValues } from 'App/appStore';
|
|
import PageSidebarStatus from 'Components/Page/Sidebar/PageSidebarStatus';
|
|
import usePrevious from 'Helpers/Hooks/usePrevious';
|
|
import useHealth from './useHealth';
|
|
|
|
function HealthStatus() {
|
|
const { isConnected, isReconnecting } = useAppValues(
|
|
'isConnected',
|
|
'isReconnecting'
|
|
);
|
|
const { data, refetch } = useHealth();
|
|
|
|
const wasReconnecting = usePrevious(isReconnecting);
|
|
|
|
const { count, errors, warnings } = useMemo(() => {
|
|
let errors = false;
|
|
let warnings = false;
|
|
|
|
data.forEach((item) => {
|
|
if (item.type === 'error') {
|
|
errors = true;
|
|
}
|
|
|
|
if (item.type === 'warning') {
|
|
warnings = true;
|
|
}
|
|
});
|
|
|
|
return {
|
|
count: data.length,
|
|
errors,
|
|
warnings,
|
|
};
|
|
}, [data]);
|
|
|
|
useEffect(() => {
|
|
if (isConnected && wasReconnecting) {
|
|
refetch();
|
|
}
|
|
}, [isConnected, wasReconnecting, refetch]);
|
|
|
|
return (
|
|
<PageSidebarStatus count={count} errors={errors} warnings={warnings} />
|
|
);
|
|
}
|
|
|
|
export default HealthStatus;
|