Linting and fixint errors

This commit is contained in:
ajnart
2022-12-17 00:28:46 +09:00
parent 63f9949475
commit 786ef505b4
20 changed files with 99 additions and 103 deletions

View File

@@ -3,15 +3,10 @@ import { closeModal, ContextModalProps } from '@mantine/modals';
import { useConfigContext } from '../../../../config/provider'; import { useConfigContext } from '../../../../config/provider';
import { useConfigStore } from '../../../../config/store'; import { useConfigStore } from '../../../../config/store';
import { IntegrationsType } from '../../../../types/integration'; import { IntegrationsType } from '../../../../types/integration';
import { TileBaseType } from '../../../../types/tile'; import { IntegrationChangePositionModalInnerProps } from '../../Tiles/Integrations/IntegrationsMenu';
import { Tiles } from '../../Tiles/tilesDefinitions'; import { Tiles } from '../../Tiles/tilesDefinitions';
import { ChangePositionModal } from './ChangePositionModal'; import { ChangePositionModal } from './ChangePositionModal';
export type IntegrationChangePositionModalInnerProps = {
integration: keyof IntegrationsType;
module: TileBaseType;
};
export const ChangeIntegrationPositionModal = ({ export const ChangeIntegrationPositionModal = ({
context, context,
id, id,

View File

@@ -12,8 +12,7 @@ interface IntegrationTabProps {
export const IntegrationTab = ({ form }: IntegrationTabProps) => { export const IntegrationTab = ({ form }: IntegrationTabProps) => {
const { t } = useTranslation(''); const { t } = useTranslation('');
const hasIntegrationSelected = const hasIntegrationSelected = form.values.integration?.type;
form.values.integration?.type;
return ( return (
<Tabs.Panel value="integration" pt="lg"> <Tabs.Panel value="integration" pt="lg">

View File

@@ -1 +1,6 @@
export type EditServiceModalTab = 'general' | 'behaviour' | 'network' | 'appereance' | 'integration'; export type EditServiceModalTab =
| 'general'
| 'behaviour'
| 'network'
| 'appereance'
| 'integration';

View File

@@ -6,14 +6,14 @@ interface SelectorBackArrowProps {
} }
export const SelectorBackArrow = ({ onClickBack }: SelectorBackArrowProps) => ( export const SelectorBackArrow = ({ onClickBack }: SelectorBackArrowProps) => (
<Button <Button
leftIcon={<IconArrowNarrowLeft />} leftIcon={<IconArrowNarrowLeft />}
onClick={onClickBack} onClick={onClickBack}
styles={{ inner: { width: 'fit-content' } }} styles={{ inner: { width: 'fit-content' } }}
fullWidth fullWidth
variant='default' variant="default"
mb="md" mb="md"
> >
<Text>See all available elements</Text> <Text>See all available elements</Text>
</Button> </Button>
); );

View File

@@ -2,12 +2,21 @@ import { Group, Stack, Text } from '@mantine/core';
import { IconArrowNarrowDown, IconArrowNarrowUp } from '@tabler/icons'; import { IconArrowNarrowDown, IconArrowNarrowUp } from '@tabler/icons';
import { useTranslation } from 'next-i18next'; import { useTranslation } from 'next-i18next';
import { bytes } from '../../../../tools/bytesHelper'; import { bytes } from '../../../../tools/bytesHelper';
import { DashDotInfo } from './DashDotTile';
interface DashDotCompactNetworkProps { interface DashDotCompactNetworkProps {
info: DashDotInfo; info: DashDotInfo;
} }
export interface DashDotInfo {
storage: {
layout: { size: number }[];
};
network: {
speedUp: number;
speedDown: number;
};
}
export const DashDotCompactNetwork = ({ info }: DashDotCompactNetworkProps) => { export const DashDotCompactNetwork = ({ info }: DashDotCompactNetworkProps) => {
const { t } = useTranslation('modules/dashdot'); const { t } = useTranslation('modules/dashdot');
@@ -15,7 +24,7 @@ export const DashDotCompactNetwork = ({ info }: DashDotCompactNetworkProps) => {
const downSpeed = bytes.toPerSecondString(info?.network?.speedDown); const downSpeed = bytes.toPerSecondString(info?.network?.speedDown);
return ( return (
<Group noWrap align="start" position="apart" w={'100%'} maw={'251px'}> <Group noWrap align="start" position="apart" w="100%" maw="251px">
<Text weight={500}>{t('card.graphs.network.label')}</Text> <Text weight={500}>{t('card.graphs.network.label')}</Text>
<Stack align="end" spacing={0}> <Stack align="end" spacing={0}>
<Group spacing={0}> <Group spacing={0}>

View File

@@ -25,7 +25,7 @@ export const DashDotCompactStorage = ({ info }: DashDotCompactStorageProps) => {
}); });
return ( return (
<Group noWrap align="start" position="apart" w={'100%'} maw={'251px'}> <Group noWrap align="start" position="apart" w="100%" maw="251px">
<Text weight={500}>{t('card.graphs.storage.label')}</Text> <Text weight={500}>{t('card.graphs.storage.label')}</Text>
<Stack align="end" spacing={0}> <Stack align="end" spacing={0}>
<Text color="dimmed" size="xs"> <Text color="dimmed" size="xs">
@@ -42,11 +42,8 @@ export const DashDotCompactStorage = ({ info }: DashDotCompactStorageProps) => {
const calculateTotalLayoutSize = <TLayoutItem,>({ const calculateTotalLayoutSize = <TLayoutItem,>({
layout, layout,
key, key,
}: CalculateTotalLayoutSizeProps<TLayoutItem>) => { }: CalculateTotalLayoutSizeProps<TLayoutItem>) =>
return layout.reduce((total, current) => { layout.reduce((total, current) => total + (current[key] as number), 0);
return total + (current[key] as number);
}, 0);
};
interface CalculateTotalLayoutSizeProps<TLayoutItem> { interface CalculateTotalLayoutSizeProps<TLayoutItem> {
layout: TLayoutItem[]; layout: TLayoutItem[];
@@ -68,13 +65,13 @@ const useDashDotStorage = () => {
}); });
}; };
const fetchDashDotStorageLoad = async (configName: string | undefined) => { async function fetchDashDotStorageLoad(configName: string | undefined) {
console.log('storage request: ' + configName); console.log(`storage request: ${configName}`);
if (!configName) return; if (!configName) throw new Error('configName is undefined');
return (await ( return (await (
await axios.get('/api/modules/dashdot/storage', { params: { configName } }) await axios.get('/api/modules/dashdot/storage', { params: { configName } })
).data) as DashDotStorageLoad; ).data) as DashDotStorageLoad;
}; }
interface DashDotStorageLoad { interface DashDotStorageLoad {
layout: { load: number }[]; layout: { load: number }[];

View File

@@ -1,24 +1,15 @@
import { import { createStyles, Group, Title } from '@mantine/core';
Card,
createStyles,
Flex,
Grid,
Group,
Stack,
Title,
useMantineTheme,
} from '@mantine/core';
import { useQuery } from '@tanstack/react-query'; import { useQuery } from '@tanstack/react-query';
import axios from 'axios'; import axios from 'axios';
import { useTranslation } from 'next-i18next'; import { useTranslation } from 'next-i18next';
import { DashDotCompactNetwork } from './DashDotCompactNetwork'; import { DashDotCompactNetwork, DashDotInfo } from './DashDotCompactNetwork';
import { DashDotCompactStorage } from './DashDotCompactStorage';
import { BaseTileProps } from '../type'; import { BaseTileProps } from '../type';
import { DashDotGraph } from './DashDotGraph'; import { DashDotGraph } from './DashDotGraph';
import { DashDotIntegrationType } from '../../../../types/integration'; import { DashDotIntegrationType } from '../../../../types/integration';
import { IntegrationsMenu } from '../Integrations/IntegrationsMenu'; import { IntegrationsMenu } from '../Integrations/IntegrationsMenu';
import { useConfigContext } from '../../../../config/provider'; import { useConfigContext } from '../../../../config/provider';
import { HomarrCardWrapper } from '../HomarrCardWrapper'; import { HomarrCardWrapper } from '../HomarrCardWrapper';
import { DashDotCompactStorage } from './DashDotCompactStorage';
interface DashDotTileProps extends BaseTileProps { interface DashDotTileProps extends BaseTileProps {
module: DashDotIntegrationType | undefined; module: DashDotIntegrationType | undefined;
@@ -132,16 +123,6 @@ const fetchDashDotInfo = async (configName: string | undefined) => {
).data) as DashDotInfo; ).data) as DashDotInfo;
}; };
export interface DashDotInfo {
storage: {
layout: { size: number }[];
};
network: {
speedUp: number;
speedDown: number;
};
}
export const useDashDotTileStyles = createStyles(() => ({ export const useDashDotTileStyles = createStyles(() => ({
graphsContainer: { graphsContainer: {
display: 'flex', display: 'flex',
@@ -151,7 +132,7 @@ export const useDashDotTileStyles = createStyles(() => ({
columnGap: 10, columnGap: 10,
}, },
graphsWrapper: { graphsWrapper: {
[`& > *:nth-child(odd):last-child`]: { '& > *:nth-child(odd):last-child': {
width: '100% !important', width: '100% !important',
maxWidth: '100% !important', maxWidth: '100% !important',
}, },

View File

@@ -11,5 +11,13 @@ export const HomarrCardWrapper = ({ ...props }: HomarrCardWrapperProps) => {
cx, cx,
classes: { card: cardClass }, classes: { card: cardClass },
} = useCardStyles(); } = useCardStyles();
return <Card {...props} className={cx(props.className, cardClass)} withBorder radius="lg" shadow="md" />; return (
<Card
{...props}
className={cx(props.className, cardClass)}
withBorder
radius="lg"
shadow="md"
/>
);
}; };

View File

@@ -4,7 +4,6 @@ import { openContextModalGeneric } from '../../../../tools/mantineModalManagerEx
import { IntegrationsType } from '../../../../types/integration'; import { IntegrationsType } from '../../../../types/integration';
import { TileBaseType } from '../../../../types/tile'; import { TileBaseType } from '../../../../types/tile';
import { GenericTileMenu } from '../GenericTileMenu'; import { GenericTileMenu } from '../GenericTileMenu';
import { IntegrationChangePositionModalInnerProps } from '../../Modals/ChangePosition/ChangeIntegrationPositionModal';
import { IntegrationRemoveModalInnerProps } from '../IntegrationRemoveModal'; import { IntegrationRemoveModalInnerProps } from '../IntegrationRemoveModal';
import { import {
IntegrationEditModalInnerProps, IntegrationEditModalInnerProps,
@@ -13,6 +12,11 @@ import {
IntegrationOptions, IntegrationOptions,
} from '../IntegrationsEditModal'; } from '../IntegrationsEditModal';
export type IntegrationChangePositionModalInnerProps = {
integration: keyof IntegrationsType;
module: TileBaseType;
};
interface IntegrationsMenuProps<TIntegrationKey extends keyof IntegrationsType> { interface IntegrationsMenuProps<TIntegrationKey extends keyof IntegrationsType> {
integration: TIntegrationKey; integration: TIntegrationKey;
module: TileBaseType | undefined; module: TileBaseType | undefined;

View File

@@ -34,28 +34,26 @@ export const IntegrationsEditModal = ({
const handleChange = (key: string, value: IntegrationOptionsValueType) => { const handleChange = (key: string, value: IntegrationOptionsValueType) => {
setModuleProperties((prev) => { setModuleProperties((prev) => {
let copyOfPrev: any = { ...prev }; const copyOfPrev: any = { ...prev };
copyOfPrev[key] = value; copyOfPrev[key] = value;
return copyOfPrev; return copyOfPrev;
}); });
}; };
const handleSave = () => { const handleSave = () => {
updateConfig(configName, (prev) => { updateConfig(configName, (prev) => ({
return { ...prev,
...prev, integrations: {
integrations: { ...prev.integrations,
...prev.integrations, [innerProps.integration]:
[innerProps.integration]: 'properties' in (prev.integrations[innerProps.integration] ?? {})
'properties' in (prev.integrations[innerProps.integration] ?? {}) ? {
? { ...prev.integrations[innerProps.integration],
...prev.integrations[innerProps.integration], properties: moduleProperties,
properties: moduleProperties, }
} : prev.integrations[innerProps.integration],
: prev.integrations[innerProps.integration], },
}, }));
};
});
context.closeModal(id); context.closeModal(id);
}; };

View File

@@ -1,4 +1,4 @@
import { Card, Center, Group, Skeleton, Stack, Text, Title } from '@mantine/core'; import { Center, Group, Skeleton, Stack, Text, Title } from '@mantine/core';
import { IconArrowDownRight, IconArrowUpRight } from '@tabler/icons'; import { IconArrowDownRight, IconArrowUpRight } from '@tabler/icons';
import { WeatherIcon } from './WeatherIcon'; import { WeatherIcon } from './WeatherIcon';
import { BaseTileProps } from '../type'; import { BaseTileProps } from '../type';
@@ -91,6 +91,5 @@ export const WeatherTile = ({ className, module }: WeatherTileProps) => {
); );
}; };
const getPerferedUnit = (value: number, isFahrenheit: boolean = false): string => { const getPerferedUnit = (value: number, isFahrenheit = false): string =>
return isFahrenheit ? `${(value * (9 / 5) + 32).toFixed(1)}°F` : `${value.toFixed(1)}°C`; isFahrenheit ? `${(value * (9 / 5) + 32).toFixed(1)}°F` : `${value.toFixed(1)}°C`;
};

View File

@@ -1,7 +1,6 @@
import { GridStack, GridStackNode } from 'fily-publish-gridstack'; import { GridStack, GridStackNode } from 'fily-publish-gridstack';
import { import {
createRef, createRef,
LegacyRef,
MutableRefObject, MutableRefObject,
RefObject, RefObject,
useEffect, useEffect,

View File

@@ -110,6 +110,5 @@ const useDeleteConfigMutation = (configName: string) => {
}); });
}; };
const fetchDeletion = async (configName: string) => { const fetchDeletion = async (configName: string) =>
return await (await fetch(`/api/configs/${configName}`)).json(); (await fetch(`/api/configs/${configName}`)).json();
};

View File

@@ -39,10 +39,6 @@ export function SearchNewTabSwitch({ defaultValue }: SearchNewTabSwitchProps) {
}; };
return ( return (
<Switch <Switch checked={openInNewTab} onChange={toggleOpenInNewTab} label={t('searchNewTab.label')} />
checked={openInNewTab}
onChange={toggleOpenInNewTab}
label={t('searchNewTab.label')}
/>
); );
} }

View File

@@ -1,4 +1,13 @@
import { Table, Checkbox, Group, Badge, createStyles, ScrollArea, TextInput, useMantineTheme } from '@mantine/core'; import {
Table,
Checkbox,
Group,
Badge,
createStyles,
ScrollArea,
TextInput,
useMantineTheme,
} from '@mantine/core';
import { useElementSize } from '@mantine/hooks'; import { useElementSize } from '@mantine/hooks';
import { IconSearch } from '@tabler/icons'; import { IconSearch } from '@tabler/icons';
import Dockerode from 'dockerode'; import Dockerode from 'dockerode';

View File

@@ -82,9 +82,7 @@ export default function TotalDownloadsComponent() {
return ( return (
<Group> <Group>
<Title order={4}>{t('card.errors.noDownloadClients.title')}</Title> <Title order={4}>{t('card.errors.noDownloadClients.title')}</Title>
<div> <div>{t('card.errors.noDownloadClients.text')}</div>
{t('card.errors.noDownloadClients.text')}
</div>
</Group> </Group>
); );
} }

View File

@@ -1,7 +1,7 @@
import axios from 'axios'; import axios from 'axios';
import { NextApiRequest, NextApiResponse } from 'next'; import { NextApiRequest, NextApiResponse } from 'next';
import { getConfig } from '../../../tools/config/getConfig'; import { getConfig } from '../../../tools/config/getConfig';
import { ServiceIntegrationType, ServiceType } from '../../../types/service'; import { ServiceIntegrationType } from '../../../types/service';
export default async (req: NextApiRequest, res: NextApiResponse) => { export default async (req: NextApiRequest, res: NextApiResponse) => {
// Filter out if the reuqest is a POST or a GET // Filter out if the reuqest is a POST or a GET
@@ -22,10 +22,10 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
configName, configName,
} = req.query as { month: string; year: string; configName: string }; } = req.query as { month: string; year: string; configName: string };
const month = parseInt(monthString); const month = parseInt(monthString, 10);
const year = parseInt(yearString); const year = parseInt(yearString, 10);
if (isNaN(month) || isNaN(year) || !configName) { if (Number.isNaN(month) || Number.isNaN(year) || !configName) {
return res.status(400).json({ return res.status(400).json({
statusCode: 400, statusCode: 400,
message: 'Missing required parameter in url: year, month or configName', message: 'Missing required parameter in url: year, month or configName',
@@ -49,11 +49,12 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
await mediaServices.map(async (service) => { await mediaServices.map(async (service) => {
const integration = service.integration!; const integration = service.integration!;
const endpoint = IntegrationTypeEndpointMap.get(integration.type); const endpoint = IntegrationTypeEndpointMap.get(integration.type);
if (!endpoint) if (!endpoint) {
return { return {
type: integration.type, type: integration.type,
items: [], items: [],
}; };
}
// Get the origin URL // Get the origin URL
let { href: origin } = new URL(service.url); let { href: origin } = new URL(service.url);
@@ -66,7 +67,7 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
const apiKey = integration.properties.find((x) => x.field === 'apiKey')?.value; const apiKey = integration.properties.find((x) => x.field === 'apiKey')?.value;
if (!apiKey) return { type: integration.type, items: [] }; if (!apiKey) return { type: integration.type, items: [] };
return await axios return axios
.get( .get(
`${origin}${endpoint}?apiKey=${apiKey}&end=${end.toISOString()}&start=${start.toISOString()}` `${origin}${endpoint}?apiKey=${apiKey}&end=${end.toISOString()}&start=${start.toISOString()}`
) )

View File

@@ -3,8 +3,6 @@ import dayjs from 'dayjs';
import duration from 'dayjs/plugin/duration'; import duration from 'dayjs/plugin/duration';
import { NextApiRequest, NextApiResponse } from 'next'; import { NextApiRequest, NextApiResponse } from 'next';
import { Client } from 'sabnzbd-api'; import { Client } from 'sabnzbd-api';
import { getServiceById } from '../../../../tools/hooks/useGetServiceByType';
import { Config } from '../../../../tools/types';
import { NzbgetHistoryItem } from './nzbget/types'; import { NzbgetHistoryItem } from './nzbget/types';
import { NzbgetClient } from './nzbget/nzbget-client'; import { NzbgetClient } from './nzbget/nzbget-client';
import { getConfig } from '../../../../tools/config/getConfig'; import { getConfig } from '../../../../tools/config/getConfig';

View File

@@ -12,13 +12,14 @@ export const useRepositoryIconsQuery = <TRepositoryIcon extends object>({
queryKey: ['repository-icons', { url }], queryKey: ['repository-icons', { url }],
queryFn: async () => fetchRepositoryIcons<TRepositoryIcon>(url), queryFn: async () => fetchRepositoryIcons<TRepositoryIcon>(url),
select(data) { select(data) {
return data.map(x => converter(x)); return data.map((x) => converter(x));
}, },
refetchOnWindowFocus: false, refetchOnWindowFocus: false,
}); });
const fetchRepositoryIcons = const fetchRepositoryIcons = async <TRepositoryIcon extends object>(
async <TRepositoryIcon extends object>(url: string): Promise<TRepositoryIcon[]> => { url: string
): Promise<TRepositoryIcon[]> => {
const response = await fetch( const response = await fetch(
'https://api.github.com/repos/walkxcode/Dashboard-Icons/contents/png' 'https://api.github.com/repos/walkxcode/Dashboard-Icons/contents/png'
); );

View File

@@ -47,6 +47,6 @@ export interface BitTorrentIntegrationType extends TileBaseType {
}; };
} }
export interface UseNetIntegrationType extends TileBaseType {} export type UseNetIntegrationType = TileBaseType;
export interface TorrentNetworkTrafficIntegrationType extends TileBaseType {} export type TorrentNetworkTrafficIntegrationType = TileBaseType;