From 786ef505b45ac5464a46ea9fd5c791106bfd62a1 Mon Sep 17 00:00:00 2001 From: ajnart Date: Sat, 17 Dec 2022 00:28:46 +0900 Subject: [PATCH] Linting and fixint errors --- .../ChangeIntegrationPositionModal.tsx | 7 +---- .../Tabs/IntegrationTab/IntegrationTab.tsx | 3 +- .../Dashboard/Modals/EditService/Tabs/type.ts | 7 ++++- .../Components/Shared/SelectorBackArrow.tsx | 22 +++++++------- .../Tiles/DashDot/DashDotCompactNetwork.tsx | 13 ++++++-- .../Tiles/DashDot/DashDotCompactStorage.tsx | 17 +++++------ .../Dashboard/Tiles/DashDot/DashDotTile.tsx | 27 +++-------------- .../Dashboard/Tiles/HomarrCardWrapper.tsx | 10 ++++++- .../Tiles/Integrations/IntegrationsMenu.tsx | 6 +++- .../Dashboard/Tiles/IntegrationsEditModal.tsx | 30 +++++++++---------- .../Dashboard/Tiles/Weather/WeatherTile.tsx | 7 ++--- .../Wrappers/gridstack/use-gridstack.ts | 1 - .../Settings/Common/Config/ConfigActions.tsx | 5 ++-- .../SearchEngine/SearchNewTabSwitch.tsx | 6 +--- src/modules/docker/DockerTable.tsx | 11 ++++++- src/modules/torrents/TotalDownloadsModule.tsx | 4 +-- src/pages/api/modules/calendar.ts | 13 ++++---- src/pages/api/modules/usenet/history.ts | 2 -- src/tools/hooks/useRepositoryIconsQuery.ts | 7 +++-- src/types/integration.ts | 4 +-- 20 files changed, 99 insertions(+), 103 deletions(-) diff --git a/src/components/Dashboard/Modals/ChangePosition/ChangeIntegrationPositionModal.tsx b/src/components/Dashboard/Modals/ChangePosition/ChangeIntegrationPositionModal.tsx index fddde2e01..a9d2217b2 100644 --- a/src/components/Dashboard/Modals/ChangePosition/ChangeIntegrationPositionModal.tsx +++ b/src/components/Dashboard/Modals/ChangePosition/ChangeIntegrationPositionModal.tsx @@ -3,15 +3,10 @@ import { closeModal, ContextModalProps } from '@mantine/modals'; import { useConfigContext } from '../../../../config/provider'; import { useConfigStore } from '../../../../config/store'; import { IntegrationsType } from '../../../../types/integration'; -import { TileBaseType } from '../../../../types/tile'; +import { IntegrationChangePositionModalInnerProps } from '../../Tiles/Integrations/IntegrationsMenu'; import { Tiles } from '../../Tiles/tilesDefinitions'; import { ChangePositionModal } from './ChangePositionModal'; -export type IntegrationChangePositionModalInnerProps = { - integration: keyof IntegrationsType; - module: TileBaseType; -}; - export const ChangeIntegrationPositionModal = ({ context, id, diff --git a/src/components/Dashboard/Modals/EditService/Tabs/IntegrationTab/IntegrationTab.tsx b/src/components/Dashboard/Modals/EditService/Tabs/IntegrationTab/IntegrationTab.tsx index 5b617d5aa..9d6b1abef 100644 --- a/src/components/Dashboard/Modals/EditService/Tabs/IntegrationTab/IntegrationTab.tsx +++ b/src/components/Dashboard/Modals/EditService/Tabs/IntegrationTab/IntegrationTab.tsx @@ -12,8 +12,7 @@ interface IntegrationTabProps { export const IntegrationTab = ({ form }: IntegrationTabProps) => { const { t } = useTranslation(''); - const hasIntegrationSelected = - form.values.integration?.type; + const hasIntegrationSelected = form.values.integration?.type; return ( diff --git a/src/components/Dashboard/Modals/EditService/Tabs/type.ts b/src/components/Dashboard/Modals/EditService/Tabs/type.ts index 583e84abf..0545d189f 100644 --- a/src/components/Dashboard/Modals/EditService/Tabs/type.ts +++ b/src/components/Dashboard/Modals/EditService/Tabs/type.ts @@ -1 +1,6 @@ -export type EditServiceModalTab = 'general' | 'behaviour' | 'network' | 'appereance' | 'integration'; +export type EditServiceModalTab = + | 'general' + | 'behaviour' + | 'network' + | 'appereance' + | 'integration'; diff --git a/src/components/Dashboard/Modals/SelectElement/Components/Shared/SelectorBackArrow.tsx b/src/components/Dashboard/Modals/SelectElement/Components/Shared/SelectorBackArrow.tsx index 66accdfd6..4e0ab603b 100644 --- a/src/components/Dashboard/Modals/SelectElement/Components/Shared/SelectorBackArrow.tsx +++ b/src/components/Dashboard/Modals/SelectElement/Components/Shared/SelectorBackArrow.tsx @@ -6,14 +6,14 @@ interface SelectorBackArrowProps { } export const SelectorBackArrow = ({ onClickBack }: SelectorBackArrowProps) => ( - - ); + +); diff --git a/src/components/Dashboard/Tiles/DashDot/DashDotCompactNetwork.tsx b/src/components/Dashboard/Tiles/DashDot/DashDotCompactNetwork.tsx index 1acb64909..a329e3f8c 100644 --- a/src/components/Dashboard/Tiles/DashDot/DashDotCompactNetwork.tsx +++ b/src/components/Dashboard/Tiles/DashDot/DashDotCompactNetwork.tsx @@ -2,12 +2,21 @@ import { Group, Stack, Text } from '@mantine/core'; import { IconArrowNarrowDown, IconArrowNarrowUp } from '@tabler/icons'; import { useTranslation } from 'next-i18next'; import { bytes } from '../../../../tools/bytesHelper'; -import { DashDotInfo } from './DashDotTile'; interface DashDotCompactNetworkProps { info: DashDotInfo; } +export interface DashDotInfo { + storage: { + layout: { size: number }[]; + }; + network: { + speedUp: number; + speedDown: number; + }; +} + export const DashDotCompactNetwork = ({ info }: DashDotCompactNetworkProps) => { const { t } = useTranslation('modules/dashdot'); @@ -15,7 +24,7 @@ export const DashDotCompactNetwork = ({ info }: DashDotCompactNetworkProps) => { const downSpeed = bytes.toPerSecondString(info?.network?.speedDown); return ( - + {t('card.graphs.network.label')} diff --git a/src/components/Dashboard/Tiles/DashDot/DashDotCompactStorage.tsx b/src/components/Dashboard/Tiles/DashDot/DashDotCompactStorage.tsx index 967c81a68..b76b61183 100644 --- a/src/components/Dashboard/Tiles/DashDot/DashDotCompactStorage.tsx +++ b/src/components/Dashboard/Tiles/DashDot/DashDotCompactStorage.tsx @@ -25,7 +25,7 @@ export const DashDotCompactStorage = ({ info }: DashDotCompactStorageProps) => { }); return ( - + {t('card.graphs.storage.label')} @@ -42,11 +42,8 @@ export const DashDotCompactStorage = ({ info }: DashDotCompactStorageProps) => { const calculateTotalLayoutSize = ({ layout, key, -}: CalculateTotalLayoutSizeProps) => { - return layout.reduce((total, current) => { - return total + (current[key] as number); - }, 0); -}; +}: CalculateTotalLayoutSizeProps) => + layout.reduce((total, current) => total + (current[key] as number), 0); interface CalculateTotalLayoutSizeProps { layout: TLayoutItem[]; @@ -68,13 +65,13 @@ const useDashDotStorage = () => { }); }; -const fetchDashDotStorageLoad = async (configName: string | undefined) => { - console.log('storage request: ' + configName); - if (!configName) return; +async function fetchDashDotStorageLoad(configName: string | undefined) { + console.log(`storage request: ${configName}`); + if (!configName) throw new Error('configName is undefined'); return (await ( await axios.get('/api/modules/dashdot/storage', { params: { configName } }) ).data) as DashDotStorageLoad; -}; +} interface DashDotStorageLoad { layout: { load: number }[]; diff --git a/src/components/Dashboard/Tiles/DashDot/DashDotTile.tsx b/src/components/Dashboard/Tiles/DashDot/DashDotTile.tsx index e3c7535ba..4d61c4de2 100644 --- a/src/components/Dashboard/Tiles/DashDot/DashDotTile.tsx +++ b/src/components/Dashboard/Tiles/DashDot/DashDotTile.tsx @@ -1,24 +1,15 @@ -import { - Card, - createStyles, - Flex, - Grid, - Group, - Stack, - Title, - useMantineTheme, -} from '@mantine/core'; +import { createStyles, Group, Title } from '@mantine/core'; import { useQuery } from '@tanstack/react-query'; import axios from 'axios'; import { useTranslation } from 'next-i18next'; -import { DashDotCompactNetwork } from './DashDotCompactNetwork'; -import { DashDotCompactStorage } from './DashDotCompactStorage'; +import { DashDotCompactNetwork, DashDotInfo } from './DashDotCompactNetwork'; import { BaseTileProps } from '../type'; import { DashDotGraph } from './DashDotGraph'; import { DashDotIntegrationType } from '../../../../types/integration'; import { IntegrationsMenu } from '../Integrations/IntegrationsMenu'; import { useConfigContext } from '../../../../config/provider'; import { HomarrCardWrapper } from '../HomarrCardWrapper'; +import { DashDotCompactStorage } from './DashDotCompactStorage'; interface DashDotTileProps extends BaseTileProps { module: DashDotIntegrationType | undefined; @@ -132,16 +123,6 @@ const fetchDashDotInfo = async (configName: string | undefined) => { ).data) as DashDotInfo; }; -export interface DashDotInfo { - storage: { - layout: { size: number }[]; - }; - network: { - speedUp: number; - speedDown: number; - }; -} - export const useDashDotTileStyles = createStyles(() => ({ graphsContainer: { display: 'flex', @@ -151,7 +132,7 @@ export const useDashDotTileStyles = createStyles(() => ({ columnGap: 10, }, graphsWrapper: { - [`& > *:nth-child(odd):last-child`]: { + '& > *:nth-child(odd):last-child': { width: '100% !important', maxWidth: '100% !important', }, diff --git a/src/components/Dashboard/Tiles/HomarrCardWrapper.tsx b/src/components/Dashboard/Tiles/HomarrCardWrapper.tsx index 1f6450ab2..6b24b0975 100644 --- a/src/components/Dashboard/Tiles/HomarrCardWrapper.tsx +++ b/src/components/Dashboard/Tiles/HomarrCardWrapper.tsx @@ -11,5 +11,13 @@ export const HomarrCardWrapper = ({ ...props }: HomarrCardWrapperProps) => { cx, classes: { card: cardClass }, } = useCardStyles(); - return ; + return ( + + ); }; diff --git a/src/components/Dashboard/Tiles/Integrations/IntegrationsMenu.tsx b/src/components/Dashboard/Tiles/Integrations/IntegrationsMenu.tsx index 3455bd340..822454409 100644 --- a/src/components/Dashboard/Tiles/Integrations/IntegrationsMenu.tsx +++ b/src/components/Dashboard/Tiles/Integrations/IntegrationsMenu.tsx @@ -4,7 +4,6 @@ import { openContextModalGeneric } from '../../../../tools/mantineModalManagerEx import { IntegrationsType } from '../../../../types/integration'; import { TileBaseType } from '../../../../types/tile'; import { GenericTileMenu } from '../GenericTileMenu'; -import { IntegrationChangePositionModalInnerProps } from '../../Modals/ChangePosition/ChangeIntegrationPositionModal'; import { IntegrationRemoveModalInnerProps } from '../IntegrationRemoveModal'; import { IntegrationEditModalInnerProps, @@ -13,6 +12,11 @@ import { IntegrationOptions, } from '../IntegrationsEditModal'; +export type IntegrationChangePositionModalInnerProps = { + integration: keyof IntegrationsType; + module: TileBaseType; +}; + interface IntegrationsMenuProps { integration: TIntegrationKey; module: TileBaseType | undefined; diff --git a/src/components/Dashboard/Tiles/IntegrationsEditModal.tsx b/src/components/Dashboard/Tiles/IntegrationsEditModal.tsx index f301e1a67..738fcfd53 100644 --- a/src/components/Dashboard/Tiles/IntegrationsEditModal.tsx +++ b/src/components/Dashboard/Tiles/IntegrationsEditModal.tsx @@ -34,28 +34,26 @@ export const IntegrationsEditModal = ({ const handleChange = (key: string, value: IntegrationOptionsValueType) => { setModuleProperties((prev) => { - let copyOfPrev: any = { ...prev }; + const copyOfPrev: any = { ...prev }; copyOfPrev[key] = value; return copyOfPrev; }); }; const handleSave = () => { - updateConfig(configName, (prev) => { - return { - ...prev, - integrations: { - ...prev.integrations, - [innerProps.integration]: - 'properties' in (prev.integrations[innerProps.integration] ?? {}) - ? { - ...prev.integrations[innerProps.integration], - properties: moduleProperties, - } - : prev.integrations[innerProps.integration], - }, - }; - }); + updateConfig(configName, (prev) => ({ + ...prev, + integrations: { + ...prev.integrations, + [innerProps.integration]: + 'properties' in (prev.integrations[innerProps.integration] ?? {}) + ? { + ...prev.integrations[innerProps.integration], + properties: moduleProperties, + } + : prev.integrations[innerProps.integration], + }, + })); context.closeModal(id); }; diff --git a/src/components/Dashboard/Tiles/Weather/WeatherTile.tsx b/src/components/Dashboard/Tiles/Weather/WeatherTile.tsx index 281ed7fd6..5ebd814e5 100644 --- a/src/components/Dashboard/Tiles/Weather/WeatherTile.tsx +++ b/src/components/Dashboard/Tiles/Weather/WeatherTile.tsx @@ -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 { WeatherIcon } from './WeatherIcon'; import { BaseTileProps } from '../type'; @@ -91,6 +91,5 @@ export const WeatherTile = ({ className, module }: WeatherTileProps) => { ); }; -const getPerferedUnit = (value: number, isFahrenheit: boolean = false): string => { - return isFahrenheit ? `${(value * (9 / 5) + 32).toFixed(1)}°F` : `${value.toFixed(1)}°C`; -}; +const getPerferedUnit = (value: number, isFahrenheit = false): string => + isFahrenheit ? `${(value * (9 / 5) + 32).toFixed(1)}°F` : `${value.toFixed(1)}°C`; diff --git a/src/components/Dashboard/Wrappers/gridstack/use-gridstack.ts b/src/components/Dashboard/Wrappers/gridstack/use-gridstack.ts index 39564945c..89309c42a 100644 --- a/src/components/Dashboard/Wrappers/gridstack/use-gridstack.ts +++ b/src/components/Dashboard/Wrappers/gridstack/use-gridstack.ts @@ -1,7 +1,6 @@ import { GridStack, GridStackNode } from 'fily-publish-gridstack'; import { createRef, - LegacyRef, MutableRefObject, RefObject, useEffect, diff --git a/src/components/Settings/Common/Config/ConfigActions.tsx b/src/components/Settings/Common/Config/ConfigActions.tsx index b045ff030..17249ce75 100644 --- a/src/components/Settings/Common/Config/ConfigActions.tsx +++ b/src/components/Settings/Common/Config/ConfigActions.tsx @@ -110,6 +110,5 @@ const useDeleteConfigMutation = (configName: string) => { }); }; -const fetchDeletion = async (configName: string) => { - return await (await fetch(`/api/configs/${configName}`)).json(); -}; +const fetchDeletion = async (configName: string) => + (await fetch(`/api/configs/${configName}`)).json(); diff --git a/src/components/Settings/Common/SearchEngine/SearchNewTabSwitch.tsx b/src/components/Settings/Common/SearchEngine/SearchNewTabSwitch.tsx index 7391841cc..46ae6988a 100644 --- a/src/components/Settings/Common/SearchEngine/SearchNewTabSwitch.tsx +++ b/src/components/Settings/Common/SearchEngine/SearchNewTabSwitch.tsx @@ -39,10 +39,6 @@ export function SearchNewTabSwitch({ defaultValue }: SearchNewTabSwitchProps) { }; return ( - + ); } diff --git a/src/modules/docker/DockerTable.tsx b/src/modules/docker/DockerTable.tsx index 10196ac5c..6f525d49e 100644 --- a/src/modules/docker/DockerTable.tsx +++ b/src/modules/docker/DockerTable.tsx @@ -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 { IconSearch } from '@tabler/icons'; import Dockerode from 'dockerode'; diff --git a/src/modules/torrents/TotalDownloadsModule.tsx b/src/modules/torrents/TotalDownloadsModule.tsx index a0fda21cc..afa6d2b6e 100644 --- a/src/modules/torrents/TotalDownloadsModule.tsx +++ b/src/modules/torrents/TotalDownloadsModule.tsx @@ -82,9 +82,7 @@ export default function TotalDownloadsComponent() { return ( {t('card.errors.noDownloadClients.title')} -
- {t('card.errors.noDownloadClients.text')} -
+
{t('card.errors.noDownloadClients.text')}
); } diff --git a/src/pages/api/modules/calendar.ts b/src/pages/api/modules/calendar.ts index 60b7ba113..fc966bd88 100644 --- a/src/pages/api/modules/calendar.ts +++ b/src/pages/api/modules/calendar.ts @@ -1,7 +1,7 @@ import axios from 'axios'; import { NextApiRequest, NextApiResponse } from 'next'; import { getConfig } from '../../../tools/config/getConfig'; -import { ServiceIntegrationType, ServiceType } from '../../../types/service'; +import { ServiceIntegrationType } from '../../../types/service'; export default async (req: NextApiRequest, res: NextApiResponse) => { // Filter out if the reuqest is a POST or a GET @@ -22,10 +22,10 @@ async function Get(req: NextApiRequest, res: NextApiResponse) { configName, } = req.query as { month: string; year: string; configName: string }; - const month = parseInt(monthString); - const year = parseInt(yearString); + const month = parseInt(monthString, 10); + const year = parseInt(yearString, 10); - if (isNaN(month) || isNaN(year) || !configName) { + if (Number.isNaN(month) || Number.isNaN(year) || !configName) { return res.status(400).json({ statusCode: 400, 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) => { const integration = service.integration!; const endpoint = IntegrationTypeEndpointMap.get(integration.type); - if (!endpoint) + if (!endpoint) { return { type: integration.type, items: [], }; + } // Get the origin 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; if (!apiKey) return { type: integration.type, items: [] }; - return await axios + return axios .get( `${origin}${endpoint}?apiKey=${apiKey}&end=${end.toISOString()}&start=${start.toISOString()}` ) diff --git a/src/pages/api/modules/usenet/history.ts b/src/pages/api/modules/usenet/history.ts index 99ae6f774..c724ac973 100644 --- a/src/pages/api/modules/usenet/history.ts +++ b/src/pages/api/modules/usenet/history.ts @@ -3,8 +3,6 @@ import dayjs from 'dayjs'; import duration from 'dayjs/plugin/duration'; import { NextApiRequest, NextApiResponse } from 'next'; import { Client } from 'sabnzbd-api'; -import { getServiceById } from '../../../../tools/hooks/useGetServiceByType'; -import { Config } from '../../../../tools/types'; import { NzbgetHistoryItem } from './nzbget/types'; import { NzbgetClient } from './nzbget/nzbget-client'; import { getConfig } from '../../../../tools/config/getConfig'; diff --git a/src/tools/hooks/useRepositoryIconsQuery.ts b/src/tools/hooks/useRepositoryIconsQuery.ts index e08e096ad..15ce5d06e 100644 --- a/src/tools/hooks/useRepositoryIconsQuery.ts +++ b/src/tools/hooks/useRepositoryIconsQuery.ts @@ -12,13 +12,14 @@ export const useRepositoryIconsQuery = ({ queryKey: ['repository-icons', { url }], queryFn: async () => fetchRepositoryIcons(url), select(data) { - return data.map(x => converter(x)); + return data.map((x) => converter(x)); }, refetchOnWindowFocus: false, }); -const fetchRepositoryIcons = - async (url: string): Promise => { +const fetchRepositoryIcons = async ( + url: string +): Promise => { const response = await fetch( 'https://api.github.com/repos/walkxcode/Dashboard-Icons/contents/png' ); diff --git a/src/types/integration.ts b/src/types/integration.ts index c5f50573c..cddd9ca26 100644 --- a/src/types/integration.ts +++ b/src/types/integration.ts @@ -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;