mirror of
https://github.com/ajnart/homarr.git
synced 2026-01-14 19:42:16 +01:00
♻️ Migrate dns-hole widget to board database
This commit is contained in:
@@ -173,11 +173,11 @@ const collectAdGuardSummary = async (app: ConfigAppType) => {
|
||||
|
||||
const blockedQueriesToday =
|
||||
stats.time_units === 'days'
|
||||
? stats.blocked_filtering[stats.blocked_filtering.length - 1]
|
||||
? stats.blocked_filtering[stats.blocked_filtering.length - 1] ?? 0
|
||||
: stats.blocked_filtering.reduce((prev, sum) => prev + sum, 0);
|
||||
const queriesToday =
|
||||
stats.time_units === 'days'
|
||||
? stats.dns_queries[stats.dns_queries.length - 1]
|
||||
? stats.dns_queries[stats.dns_queries.length - 1] ?? 0
|
||||
: stats.dns_queries.reduce((prev, sum) => prev + sum, 0);
|
||||
|
||||
return {
|
||||
|
||||
@@ -8,7 +8,7 @@ export type NormalizedDownloadQueueResponse = {
|
||||
|
||||
export type NormalizedDownloadAppStat = {
|
||||
success: boolean;
|
||||
appId: string;
|
||||
integrationId: string;
|
||||
} & (TorrentTotalDownload | UsenetTotalDownloas);
|
||||
|
||||
export type TorrentTotalDownload = {
|
||||
|
||||
@@ -21,7 +21,7 @@ import { api } from '~/utils/api';
|
||||
|
||||
import { defineWidget } from '../helper';
|
||||
import { WidgetLoading } from '../loading';
|
||||
import { IWidget, InferWidget } from '../widgets';
|
||||
import { InferWidget } from '../widgets';
|
||||
import { useDnsHoleSummeryQuery } from './DnsHoleSummary';
|
||||
|
||||
const definition = defineWidget({
|
||||
@@ -71,7 +71,7 @@ function DnsHoleControlsWidgetTile({ widget }: DnsHoleControlsWidgetProps) {
|
||||
const utils = api.useContext();
|
||||
const { data: sessionData } = useSession();
|
||||
const { isInitialLoading, data, isFetching: fetchingDnsSummary } = useDnsHoleSummeryQuery();
|
||||
const { mutateAsync, isLoading: changingStatus } = useDnsHoleControlMutation();
|
||||
const { mutateAsync, isLoading: changingStatus } = api.dnsHole.control.useMutation();
|
||||
const { width, ref } = useElementSize();
|
||||
const { t } = useTranslation(['common', 'modules/dns-hole-controls']);
|
||||
|
||||
@@ -265,6 +265,5 @@ function DnsHoleControlsWidgetTile({ widget }: DnsHoleControlsWidgetProps) {
|
||||
</Stack>
|
||||
);
|
||||
}
|
||||
const useDnsHoleControlMutation = () => api.dnsHole.control.useMutation();
|
||||
|
||||
export default definition;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Box, Card, Center, Container, Flex, Text } from '@mantine/core';
|
||||
import { Card, Center, Container, Flex, Text } from '@mantine/core';
|
||||
import { useElementSize } from '@mantine/hooks';
|
||||
import {
|
||||
IconAd,
|
||||
@@ -9,13 +9,12 @@ import {
|
||||
TablerIconsProps,
|
||||
} from '@tabler/icons-react';
|
||||
import { useTranslation } from 'next-i18next';
|
||||
import { useConfigContext } from '~/config/provider';
|
||||
import { formatNumber, formatPercentage } from '~/tools/client/math';
|
||||
import { RouterOutputs, api } from '~/utils/api';
|
||||
|
||||
import { defineWidget } from '../helper';
|
||||
import { WidgetLoading } from '../loading';
|
||||
import { IWidget, InferWidget } from '../widgets';
|
||||
import { InferWidget } from '../widgets';
|
||||
|
||||
const availableLayouts = ['grid', 'row', 'column'] as const;
|
||||
type AvailableLayout = (typeof availableLayouts)[number];
|
||||
@@ -50,12 +49,20 @@ interface DnsHoleSummaryWidgetProps {
|
||||
}
|
||||
|
||||
function DnsHoleSummaryWidgetTile({ widget }: DnsHoleSummaryWidgetProps) {
|
||||
const { isInitialLoading, data } = useDnsHoleSummeryQuery();
|
||||
const firstIntegration = widget.integrations[0];
|
||||
const { isInitialLoading, data } = useDnsHoleSummeryQuery({
|
||||
integrationId: firstIntegration?.id,
|
||||
});
|
||||
|
||||
if (isInitialLoading || !data) {
|
||||
return <WidgetLoading />;
|
||||
}
|
||||
|
||||
// TODO: Add no integration notice
|
||||
if (!firstIntegration) {
|
||||
return <></>;
|
||||
}
|
||||
|
||||
return (
|
||||
<Container h="100%" p={0} style={constructContainerStyle(widget.options.layout)}>
|
||||
{stats.map((item, index) => (
|
||||
@@ -104,15 +111,14 @@ type StatItem = {
|
||||
color: string;
|
||||
};
|
||||
|
||||
export const useDnsHoleSummeryQuery = () => {
|
||||
const { name: configName } = useConfigContext();
|
||||
|
||||
export const useDnsHoleSummeryQuery = ({ integrationId }: { integrationId?: string }) => {
|
||||
return api.dnsHole.summary.useQuery(
|
||||
{
|
||||
configName: configName!,
|
||||
integrationId: integrationId!,
|
||||
},
|
||||
{
|
||||
staleTime: 1000 * 60 * 2,
|
||||
enabled: !!integrationId,
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user