From 6b19ad2ec36f7dac63adbd707aaebc870d01edee Mon Sep 17 00:00:00 2001 From: Andrei Dekterev Date: Wed, 1 Mar 2023 16:37:14 +0700 Subject: [PATCH] refactor(eslint): remove any types --- src/components/ItemInfo/ItemInfo.tsx | 1 + src/config/clients/types.tsx | 1 + src/config/index.tsx | 1 + src/config/queries.tsx | 2 +- src/features/AirPlay/index.tsx | 1 + src/features/ChromeCast/index.tsx | 1 + src/features/Combobox/helpers/index.tsx | 1 + .../HeaderFilters/store/hooks/index.tsx | 2 +- src/features/Icon/index.tsx | 5 ++-- .../CardFrontside/MatchCardMobile/index.tsx | 9 ++++-- .../MatchCard/CardFrontside/index.tsx | 4 ++- .../components/FavouriteTeam/hooks.tsx | 17 ++++++----- .../components/MatchDescription/index.tsx | 10 ++++--- src/features/MatchesGrid/index.tsx | 5 ++-- .../components/ProgressBar/hooks.tsx | 1 + src/features/Name/index.tsx | 2 ++ .../components/SelectSportPopup/index.tsx | 2 +- .../components/ProgressBar/hooks.tsx | 1 + src/features/StreamPlayer/hooks/useSlider.tsx | 2 ++ .../components/PageSubscriptions/hooks.tsx | 8 +++-- src/helpers/callApi/types.tsx | 1 + src/hooks/useEventListener.tsx | 1 + src/hooks/useLocalStorage.tsx | 29 ------------------- src/hooks/useObjectState.tsx | 2 ++ src/hooks/useRequest.tsx | 1 + src/hooks/useStorage/index.tsx | 1 + .../components/FormHighlights/hooks.tsx | 4 ++- src/requests/getSound.tsx | 2 ++ src/requests/getSounds.tsx | 1 + src/requests/getUserSubscribes.tsx | 2 +- src/requests/index.tsx | 1 + 31 files changed, 66 insertions(+), 55 deletions(-) delete mode 100644 src/hooks/useLocalStorage.tsx diff --git a/src/components/ItemInfo/ItemInfo.tsx b/src/components/ItemInfo/ItemInfo.tsx index e5814204..36f04847 100644 --- a/src/components/ItemInfo/ItemInfo.tsx +++ b/src/components/ItemInfo/ItemInfo.tsx @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { ProfileTypes, PROFILE_NAMES, diff --git a/src/config/clients/types.tsx b/src/config/clients/types.tsx index 88a59a2d..fc31fa6e 100644 --- a/src/config/clients/types.tsx +++ b/src/config/clients/types.tsx @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { css } from 'styled-components/macro' type ProcedureName = string diff --git a/src/config/index.tsx b/src/config/index.tsx index 87f53711..357bcd8f 100644 --- a/src/config/index.tsx +++ b/src/config/index.tsx @@ -10,3 +10,4 @@ export * from './currencies' export * from './dashes' export * from './env' export * from './userAgent' +export * from './queries' diff --git a/src/config/queries.tsx b/src/config/queries.tsx index c6726457..c90d0f0f 100644 --- a/src/config/queries.tsx +++ b/src/config/queries.tsx @@ -1,4 +1,4 @@ export const querieKeys = { - matchScore: 'matchScore', liveMatchScores: 'liveMatchScores', + matchScore: 'matchScore', } diff --git a/src/features/AirPlay/index.tsx b/src/features/AirPlay/index.tsx index 13d9459e..627fe641 100644 --- a/src/features/AirPlay/index.tsx +++ b/src/features/AirPlay/index.tsx @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { useEffect } from 'react' import includes from 'lodash/includes' diff --git a/src/features/ChromeCast/index.tsx b/src/features/ChromeCast/index.tsx index ec632b8e..0a038712 100644 --- a/src/features/ChromeCast/index.tsx +++ b/src/features/ChromeCast/index.tsx @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { Fragment, memo, diff --git a/src/features/Combobox/helpers/index.tsx b/src/features/Combobox/helpers/index.tsx index e891445b..4233601d 100644 --- a/src/features/Combobox/helpers/index.tsx +++ b/src/features/Combobox/helpers/index.tsx @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import startsWith from 'lodash/startsWith' import orderBy from 'lodash/orderBy' import toLower from 'lodash/toLower' diff --git a/src/features/HeaderFilters/store/hooks/index.tsx b/src/features/HeaderFilters/store/hooks/index.tsx index 524cf521..f2089981 100644 --- a/src/features/HeaderFilters/store/hooks/index.tsx +++ b/src/features/HeaderFilters/store/hooks/index.tsx @@ -34,7 +34,7 @@ export const useFilters = () => { const [selectedFilters, setSelectedFilters] = useState>([]) const [isShowTournament, setIsShowTournament] = useState(true) const [selectTournament, setSelectTournament] = useState() - const [sportIds, setSportIds] = useState() + const [sportIds, setSportIds] = useState>([]) const isTodaySelected = isToday(selectedDate) const compareSport = useCallback((match: Match, sportNames: Array) => { diff --git a/src/features/Icon/index.tsx b/src/features/Icon/index.tsx index 9cfc61dc..d6fd2300 100644 --- a/src/features/Icon/index.tsx +++ b/src/features/Icon/index.tsx @@ -1,4 +1,5 @@ -import React from 'react' +/* eslint-disable @typescript-eslint/no-explicit-any */ +import React, { CSSProperties } from 'react' import * as icons from '../../libs/index' export type IconProps = { @@ -8,7 +9,7 @@ export type IconProps = { onClick?: () => void, refIcon: any, size?: number | string, - styles?: any, + styles?: CSSProperties, } export const Icon: React.FC = ({ diff --git a/src/features/MatchCard/CardFrontside/MatchCardMobile/index.tsx b/src/features/MatchCard/CardFrontside/MatchCardMobile/index.tsx index 00b5037c..6034f830 100644 --- a/src/features/MatchCard/CardFrontside/MatchCardMobile/index.tsx +++ b/src/features/MatchCard/CardFrontside/MatchCardMobile/index.tsx @@ -12,8 +12,11 @@ import { useName } from 'features/Name' import { T9n } from 'features/T9n' import { MatchAccess } from 'features/Matches/helpers/getMatchClickAction' import { useUserFavoritesStore } from 'features/UserFavorites/store' + import { getCardColor } from 'helpers/getCardColor' +import type { LiveScore } from 'requests' + import { NoAccessMessage } from '../../NoAccessMessage' import { getPrepareTimeFormat } from '../../helpers' import { getPrepareDateFormat } from '../../helpers/getPrepareDateFormat' @@ -50,6 +53,7 @@ type Props = { match: Match, onClick: () => void, onKeyPress: (e: KeyboardEvent) => void, + score?: LiveScore, } export const CardFrontsideMobile = ({ @@ -58,6 +62,7 @@ export const CardFrontsideMobile = ({ match, onClick, onKeyPress, + score, }: Props) => { const location = useLocation() const { @@ -150,14 +155,14 @@ export const CardFrontsideMobile = ({ {team1InFavorites && } - {showScore && {team1.score}} + {showScore && {score?.team1.score ?? team1.score}} {team2InFavorites && } - {showScore && {team2.score}} + {showScore && {score?.team2.score ?? team2.score}} diff --git a/src/features/MatchCard/CardFrontside/index.tsx b/src/features/MatchCard/CardFrontside/index.tsx index 2379a6a2..78445d08 100644 --- a/src/features/MatchCard/CardFrontside/index.tsx +++ b/src/features/MatchCard/CardFrontside/index.tsx @@ -6,7 +6,10 @@ import getUnixTime from 'date-fns/getUnixTime' import { ProfileTypes, PAGES } from 'config' import { isLffClient } from 'config/clients' +import type { LiveScore } from 'requests' + import { getCardColor } from 'helpers/getCardColor' + import type { Match } from 'features/Matches' import { useMatchSwitchesStore } from 'features/MatchSwitches' import { useName } from 'features/Name' @@ -41,7 +44,6 @@ import { import { useCardPreview } from './hooks' import { getPrepareTimeFormat } from '../helpers' import { getPrepareDateFormat } from '../helpers/getPrepareDateFormat' -import { LiveScore } from '../../../requests/getLiveScores' type Props = { isNeedFormatTimeChanged: boolean, diff --git a/src/features/MatchPage/components/FavouriteTeam/hooks.tsx b/src/features/MatchPage/components/FavouriteTeam/hooks.tsx index b65e2688..e336acfe 100644 --- a/src/features/MatchPage/components/FavouriteTeam/hooks.tsx +++ b/src/features/MatchPage/components/FavouriteTeam/hooks.tsx @@ -13,14 +13,15 @@ export const useFavouriteTeam = () => { const [group1, setGroup1] = useState>([]) const [group2, setGroup2] = useState>([]) - const sortTeam = (teams: Array) => teams.sort((n1:FavouriteTeams, n2: FavouriteTeams) => { - if (n1.name_en > n2.name_en) { - return 1 - } if (n1.name_en < n2.name_en) { - return -1 - } - return 0 - }) + const sortTeam = (teams: Array) => ( + teams.sort((n1:FavouriteTeams, n2: FavouriteTeams) => { + if (n1.name_en > n2.name_en) { + return 1 + } if (n1.name_en < n2.name_en) { + return -1 + } + return 0 + })) const changeActive = (team: FavouriteTeams) => { setActiveId((prev) => (prev === team.id ? null : team.id)) } diff --git a/src/features/MatchPage/components/MatchDescription/index.tsx b/src/features/MatchPage/components/MatchDescription/index.tsx index 91671e1f..cc69648e 100644 --- a/src/features/MatchPage/components/MatchDescription/index.tsx +++ b/src/features/MatchPage/components/MatchDescription/index.tsx @@ -18,13 +18,15 @@ import { useMatchPageStore } from 'features/MatchPage/store' import { parseDate } from 'helpers/parseDate' -import { ProfileTypes } from 'config' -import { isMobileDevice } from 'config/userAgent' -import { querieKeys } from 'config/queries' +import { + ProfileTypes, + querieKeys, + isMobileDevice, +} from 'config' import { usePageParams } from 'hooks/usePageParams' -import { getMatchScore } from 'requests/getMatchScore' +import { getMatchScore } from 'requests' import { Description, diff --git a/src/features/MatchesGrid/index.tsx b/src/features/MatchesGrid/index.tsx index 1a2b5b58..90270aa2 100644 --- a/src/features/MatchesGrid/index.tsx +++ b/src/features/MatchesGrid/index.tsx @@ -4,7 +4,8 @@ import { useQuery } from 'react-query' import { PAGES } from 'config/pages' -import { getLiveScores, LiveScore } from 'requests/getLiveScores' +import type { LiveScore } from 'requests' +import { getLiveScores } from 'requests' import { MatchCard } from 'features/MatchCard' import { TournamentList } from 'features/TournamentList' @@ -13,7 +14,7 @@ import { useHeaderFiltersStore } from 'features/HeaderFilters' import { Wrapper } from './styled' import { useMatchSwitchesStore } from '../MatchSwitches' -import { querieKeys } from '../../config/queries' +import { querieKeys } from '../../config' type MatchesGridProps = { matches: Array, diff --git a/src/features/MultiSourcePlayer/components/ProgressBar/hooks.tsx b/src/features/MultiSourcePlayer/components/ProgressBar/hooks.tsx index b080af87..0a63ff12 100644 --- a/src/features/MultiSourcePlayer/components/ProgressBar/hooks.tsx +++ b/src/features/MultiSourcePlayer/components/ProgressBar/hooks.tsx @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { useMemo } from 'react' import { secondsToHms } from 'helpers' diff --git a/src/features/Name/index.tsx b/src/features/Name/index.tsx index a93bc2ce..a2099b82 100644 --- a/src/features/Name/index.tsx +++ b/src/features/Name/index.tsx @@ -1,3 +1,5 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + import styled from 'styled-components/macro' import { useLexicsStore } from 'features/LexicsStore' diff --git a/src/features/SportsFilter/components/SelectSportPopup/index.tsx b/src/features/SportsFilter/components/SelectSportPopup/index.tsx index 9545543b..a57fea77 100644 --- a/src/features/SportsFilter/components/SelectSportPopup/index.tsx +++ b/src/features/SportsFilter/components/SelectSportPopup/index.tsx @@ -19,7 +19,7 @@ type Props = { onModalClose: () => void, onSportClick: (sport: string) => void, selectedSport: Array, - sportIds: Array, + sportIds: Array, sports: SportsType, } export const SelectSportPopup = ({ diff --git a/src/features/StreamPlayer/components/ProgressBar/hooks.tsx b/src/features/StreamPlayer/components/ProgressBar/hooks.tsx index 5fced27e..43b2b41c 100644 --- a/src/features/StreamPlayer/components/ProgressBar/hooks.tsx +++ b/src/features/StreamPlayer/components/ProgressBar/hooks.tsx @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { useMemo, RefObject } from 'react' import { secondsToHms } from 'helpers' diff --git a/src/features/StreamPlayer/hooks/useSlider.tsx b/src/features/StreamPlayer/hooks/useSlider.tsx index 8c3971e9..873bb68a 100644 --- a/src/features/StreamPlayer/hooks/useSlider.tsx +++ b/src/features/StreamPlayer/hooks/useSlider.tsx @@ -1,3 +1,5 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + import { useRef } from 'react' import { useEventListener, useToggle } from 'hooks' diff --git a/src/features/UserAccount/components/PageSubscriptions/hooks.tsx b/src/features/UserAccount/components/PageSubscriptions/hooks.tsx index b43eee04..9f34704e 100644 --- a/src/features/UserAccount/components/PageSubscriptions/hooks.tsx +++ b/src/features/UserAccount/components/PageSubscriptions/hooks.tsx @@ -1,6 +1,10 @@ import { useEffect, useState } from 'react' -import { getUserSubscribes, Subscribe } from 'requests/getUserSubscribes' +import { + getUserSubscribes, + Subscribe, + Subscribes, +} from 'requests/getUserSubscribes' import { cancelSubscribe } from 'requests/cancelSubscribe' import { useLexicsStore } from 'features/LexicsStore' @@ -10,7 +14,7 @@ export const useUserSubscribes = () => { const { addLexicsConfig } = useLexicsStore() const [selectedSubscribe, setSelectedSubscribe] = useState({} as Subscribe) - const [subscribes, setSubscribes] = useState([]) + const [subscribes, setSubscribes] = useState([]) const [isCancelPopupOpen, setIsCancelPopupOpen] = useState(false) const [changeCardPopupOpen, setChangeCardPopupOpen] = useState(false) const [isSubCanceled, setSubCanceled] = useState(false) diff --git a/src/helpers/callApi/types.tsx b/src/helpers/callApi/types.tsx index 446b630e..c1ee90ad 100644 --- a/src/helpers/callApi/types.tsx +++ b/src/helpers/callApi/types.tsx @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ export type RequestConfig = { body?: any, headers?: Headers, diff --git a/src/hooks/useEventListener.tsx b/src/hooks/useEventListener.tsx index ad34bfc2..3d0e4680 100644 --- a/src/hooks/useEventListener.tsx +++ b/src/hooks/useEventListener.tsx @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import type { RefObject } from 'react' import { useEffect, useRef } from 'react' diff --git a/src/hooks/useLocalStorage.tsx b/src/hooks/useLocalStorage.tsx deleted file mode 100644 index b583164f..00000000 --- a/src/hooks/useLocalStorage.tsx +++ /dev/null @@ -1,29 +0,0 @@ -import { useState } from 'react' - -export const useLocalStorage = (keyName: string, defaultValue?: any) => { - const [storedValue, setStoredValue] = useState(() => { - try { - const value = localStorage.getItem(keyName) - - if (value) { - return JSON.parse(value) - } - localStorage.setItem(keyName, JSON.stringify(defaultValue)) - return defaultValue - } catch (err) { - return defaultValue - } - }) - - const setValue = (newValue: any) => { - try { - localStorage.setItem(keyName, JSON.stringify(newValue)) - } catch (err) { - /* eslint-disable-next-line */ - console.log(err) - } - setStoredValue(newValue) - } - - return [storedValue, setValue] -} diff --git a/src/hooks/useObjectState.tsx b/src/hooks/useObjectState.tsx index 6b46897e..db256368 100644 --- a/src/hooks/useObjectState.tsx +++ b/src/hooks/useObjectState.tsx @@ -1,3 +1,5 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + import type { Dispatch } from 'react' import { useCallback, useState } from 'react' diff --git a/src/hooks/useRequest.tsx b/src/hooks/useRequest.tsx index cf091a2c..4dabde22 100644 --- a/src/hooks/useRequest.tsx +++ b/src/hooks/useRequest.tsx @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { useState, useCallback } from 'react' /** diff --git a/src/hooks/useStorage/index.tsx b/src/hooks/useStorage/index.tsx index 96fe4a6a..e28fae3e 100644 --- a/src/hooks/useStorage/index.tsx +++ b/src/hooks/useStorage/index.tsx @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { useState, useEffect } from 'react' import { queryParamStorage } from 'features/QueryParamsStorage' diff --git a/src/pages/HighlightsPage/components/FormHighlights/hooks.tsx b/src/pages/HighlightsPage/components/FormHighlights/hooks.tsx index a83b35cf..3428f2c6 100644 --- a/src/pages/HighlightsPage/components/FormHighlights/hooks.tsx +++ b/src/pages/HighlightsPage/components/FormHighlights/hooks.tsx @@ -123,7 +123,7 @@ export const useHighlightsForm = () => { const { playerHighlight } = useUserFavoritesStore() const [sports, setSports] = useState>([]) - const [sounds, setSounds] = useState([]) + const [sounds, setSounds] = useState>([]) const [isFetchingTeams, setIsFetchingTeams] = useState(false) const [teams, setTeams] = useState>([]) const [playersData, setPlayersData] = useState>([]) @@ -301,6 +301,8 @@ export const useHighlightsForm = () => { useEffect(() => { if (playerHighlight?.sportType && playerHighlight?.profile) { + // TODO: исправить any + // eslint-disable-next-line setFormState((state: any) => ({ ...state, selectedPlayer: { diff --git a/src/requests/getSound.tsx b/src/requests/getSound.tsx index 318ff00b..df5ff02d 100644 --- a/src/requests/getSound.tsx +++ b/src/requests/getSound.tsx @@ -3,6 +3,8 @@ import { API_ROOT } from 'config' type ResponseSound = { asset: string, + id: number, + name: string, } export const getSound = async (id: number | string): Promise => { diff --git a/src/requests/getSounds.tsx b/src/requests/getSounds.tsx index b1110a57..92b19ae4 100644 --- a/src/requests/getSounds.tsx +++ b/src/requests/getSounds.tsx @@ -3,6 +3,7 @@ import { API_ROOT } from 'config' type ResponseSound = { asset: string, + id: number, name: string, } diff --git a/src/requests/getUserSubscribes.tsx b/src/requests/getUserSubscribes.tsx index 3154e129..9c0aee8b 100644 --- a/src/requests/getUserSubscribes.tsx +++ b/src/requests/getUserSubscribes.tsx @@ -35,7 +35,7 @@ type Team = { name_ru: string, } -type Subscribes = Array +export type Subscribes = Array export const getUserSubscribes = ( _p_email: string, diff --git a/src/requests/index.tsx b/src/requests/index.tsx index c4bb276f..347d9f29 100644 --- a/src/requests/index.tsx +++ b/src/requests/index.tsx @@ -28,3 +28,4 @@ export * from './saveMatchStats' export * from './getGeoInfo' export * from './getTokenVirtualUser' export * from './getMatchScore' +export * from './getLiveScores'