fix($444): remove any request for getSportList and add lexics from sport to lexic store

pull/139/head
Andrei Dekterev 3 years ago
parent f335295dae
commit e43cbc2c02
  1. 4
      src/config/lexics/indexLexics.tsx
  2. 9
      src/config/lexics/procedures.tsx
  3. 18
      src/config/lexics/sportsLexic.tsx
  4. 2
      src/features/App/AuthenticatedApp.tsx
  5. 2
      src/features/App/hooks.tsx
  6. 1
      src/features/Combobox/styled.tsx
  7. 2
      src/features/Common/Input/styled.tsx
  8. 3
      src/features/HeaderFilters/store/hooks/index.tsx
  9. 14
      src/features/LexicsStore/helpers/index.tsx
  10. 5
      src/features/LexicsStore/index.tsx
  11. 10
      src/features/PreferencesPopup/store/hooks/useSports.tsx
  12. 3
      src/features/ProfileLink/helpers/index.tsx
  13. 1
      src/features/SportsFilter/components/SelectSportPopup/index.tsx
  14. 4
      src/helpers/getLocalStorage/index.tsx
  15. 35
      src/pages/HighlightsPage/components/FormHighlights/hooks.tsx

@ -1,8 +1,8 @@
import { paymentLexics } from './payment' import { paymentLexics } from './payment'
import { proceduresLexics } from './procedures'
import { publicLexics } from './public' import { publicLexics } from './public'
import { highlightsPageLexic } from './highlightsPageLexic' import { highlightsPageLexic } from './highlightsPageLexic'
import { mailingsLexics } from './mailings' import { mailingsLexics } from './mailings'
import { sportsLexic } from './sportsLexic'
const matchPopupLexics = { const matchPopupLexics = {
actions: 1020, actions: 1020,
@ -194,11 +194,11 @@ export const indexLexics = {
...highlightsPageLexic, ...highlightsPageLexic,
...mailingsLexics, ...mailingsLexics,
...preferencesPopupLexics, ...preferencesPopupLexics,
...proceduresLexics,
...matchPopupLexics, ...matchPopupLexics,
...newDevicePopup, ...newDevicePopup,
...buyMatchPopupLexics, ...buyMatchPopupLexics,
...publicLexics, ...publicLexics,
...paymentLexics, ...paymentLexics,
...sportsLexic,
...sportsPopup, ...sportsPopup,
} }

@ -1,9 +0,0 @@
export const proceduresLexics = {
3556: 3556,
6959: 6959,
9759: 9759,
9760: 9760,
9761: 9761,
12980: 12980,
20091: 20091,
}

@ -0,0 +1,18 @@
export const sportsLexic = {
1: 1,
18: 18,
3556: 3556,
6959: 6959,
9759: 9759,
9760: 9760,
9761: 9761,
12980: 12980,
17670: 17670,
19816: 19816,
19956: 19956,
19957: 19957,
20000: 20000,
20051: 20051,
20091: 20091,
}
// TODO: убрать хардкод и брать лексики при загрузке из локалсторадж

@ -43,8 +43,8 @@ const Mailings = lazy(() => import('pages/Mailings'))
const FailedPaymeePage = lazy(() => import('pages/FailedPaymeePage')) const FailedPaymeePage = lazy(() => import('pages/FailedPaymeePage'))
export const AuthenticatedApp = () => { export const AuthenticatedApp = () => {
useLexicsConfig(indexLexics)
useSportList() useSportList()
useLexicsConfig(indexLexics)
return ( return (
<StripeElements> <StripeElements>
<NewDevicePopup /> <NewDevicePopup />

@ -15,7 +15,7 @@ export const useSportList = () => {
const [sportsList, setSportsList] = useLocalStore<SportsType>({ const [sportsList, setSportsList] = useLocalStore<SportsType>({
defaultValue: {} as Sport, defaultValue: {} as Sport,
key: querieKeys.sportsList, key: querieKeys.sportsList,
validator: (val) => !!val, validator: Boolean,
}) })
useQuery({ useQuery({

@ -36,6 +36,7 @@ export const ListOption = styled.li.attrs(() => ({
padding-left: 24px; padding-left: 24px;
color: ${({ theme }) => theme.colors.white70}; color: ${({ theme }) => theme.colors.white70};
background-color: transparent; background-color: transparent;
text-transform: capitalize;
${({ isHighlighted }) => isHighlighted && css` ${({ isHighlighted }) => isHighlighted && css`
color: ${({ theme }) => theme.colors.white}; color: ${({ theme }) => theme.colors.white};

@ -129,6 +129,8 @@ const inputStyles = css<InputProps>`
export const InputStyled = styled.input<InputProps>` export const InputStyled = styled.input<InputProps>`
${inputStyles} ${inputStyles}
opacity: ${({ disabled }) => (disabled ? 0.5 : 1)}; opacity: ${({ disabled }) => (disabled ? 0.5 : 1)};
text-transform: capitalize;
::placeholder { ::placeholder {
opacity: 0; opacity: 0;
} }

@ -16,6 +16,7 @@ import { getSportLexic } from 'helpers'
import { querieKeys } from 'config' import { querieKeys } from 'config'
import { getLocalStorageItem } from 'helpers/getLocalStorage'
import { filterKeys } from '../config' import { filterKeys } from '../config'
import { isValidDate } from '../helpers/isValidDate' import { isValidDate } from '../helpers/isValidDate'
import type { Match } from '../../../Matches' import type { Match } from '../../../Matches'
@ -28,7 +29,7 @@ export const useFilters = () => {
key: filterKeys.DATE, key: filterKeys.DATE,
validator: isValidDate, validator: isValidDate,
}) })
const sportList = JSON.parse(localStorage.getItem(querieKeys.sportsList)!) const sportList = getLocalStorageItem(querieKeys.sportsList)
const [selectedSport, setSelectedSport] = useState(['all_sports']) const [selectedSport, setSelectedSport] = useState(['all_sports'])
const [selectedLeague, setSelectedLeague] = useState<Array<string | number>>(['all_competitions']) const [selectedLeague, setSelectedLeague] = useState<Array<string | number>>(['all_competitions'])

@ -7,6 +7,9 @@ import map from 'lodash/map'
import type { Translations } from 'requests' import type { Translations } from 'requests'
import type { LexicsId, LexicsConfig } from '../types' import type { LexicsId, LexicsConfig } from '../types'
import { getLocalStorageItem } from '../../../helpers/getLocalStorage'
import { querieKeys } from '../../../config'
import { Sport } from '../../../requests/getSportList'
export const getSuffix = (lang: string) => ( export const getSuffix = (lang: string) => (
lang === 'ru' ? 'rus' : 'eng' lang === 'ru' ? 'rus' : 'eng'
@ -47,3 +50,14 @@ export const mapTranslationsToLocalKeys = (
{} as Translations, {} as Translations,
) )
} }
export const getLexicFromSport = () => {
const sportList = getLocalStorageItem(querieKeys.sportsList)
const sportLexics = Object.values(sportList as Array<Sport>)
.reduce((acc:LexicsConfig, cur: Sport) => {
acc[cur?.lexic] = cur?.lexic
return acc
}, {})
return sportLexics
}

@ -6,8 +6,11 @@ import {
} from 'react' } from 'react'
import type { LexicsConfig, LexicsId } from './types' import type { LexicsConfig, LexicsId } from './types'
import { useLexics } from './hooks' import { useLexics } from './hooks'
import { getLexicFromSport } from './helpers'
type Context = ReturnType<typeof useLexics> type Context = ReturnType<typeof useLexics>
type Props = { type Props = {
children: ReactNode, children: ReactNode,
@ -27,6 +30,6 @@ export const useLexicsConfig = (config: Array<LexicsId> | LexicsConfig) => {
const { addLexicsConfig } = useLexicsStore() const { addLexicsConfig } = useLexicsStore()
useEffect(() => { useEffect(() => {
addLexicsConfig(config) addLexicsConfig({ ...config, ...getLexicFromSport() })
}, [addLexicsConfig, config]) }, [addLexicsConfig, config])
} }

@ -5,7 +5,11 @@ import without from 'lodash/without'
import isEmpty from 'lodash/isEmpty' import isEmpty from 'lodash/isEmpty'
import type { SportList } from 'requests/getSportList' import type { SportList } from 'requests/getSportList'
import { getSportList } from 'requests/getSportList' import { Sport } from 'requests/getSportList'
import { querieKeys } from 'config'
import { getLocalStorageItem } from 'helpers/getLocalStorage'
export const useSports = () => { export const useSports = () => {
const [sports, setSports] = useState<SportList>([]) const [sports, setSports] = useState<SportList>([])
@ -13,7 +17,9 @@ export const useSports = () => {
const fetchInitialSports = useCallback(() => { const fetchInitialSports = useCallback(() => {
if (isEmpty(sports)) { if (isEmpty(sports)) {
getSportList().then(setSports) const sportsList = getLocalStorageItem(querieKeys.sportsList)
const sportsArray = Object.values(sportsList as Array<Sport>)
setSports(sportsArray)
} }
}, [sports]) }, [sports])

@ -4,6 +4,7 @@ import {
PROFILE_NAMES, PROFILE_NAMES,
querieKeys, querieKeys,
} from 'config' } from 'config'
import { getLocalStorageItem } from '../../../helpers/getLocalStorage'
type Args = { type Args = {
id: number, id: number,
@ -16,7 +17,7 @@ export const getProfileUrl = ({
profileType, profileType,
sportType, sportType,
}: Args) => { }: Args) => {
const sportList = JSON.parse(localStorage.getItem(querieKeys.sportsList)!) const sportList = getLocalStorageItem(querieKeys.sportsList)
return ( return (
sportList && `/${sportList[sportType]?.name_eng}/${PROFILE_NAMES[profileType]}/${id}` sportList && `/${sportList[sportType]?.name_eng}/${PROFILE_NAMES[profileType]}/${id}`

@ -30,6 +30,7 @@ export const SelectSportPopup = ({
}: Props) => { }: Props) => {
const sportNames = sportIds?.map((id) => String(getSportLexic(Number(id)))) const sportNames = sportIds?.map((id) => String(getSportLexic(Number(id))))
sportNames?.unshift('all_sports') sportNames?.unshift('all_sports')
// TODO: переделать на вариант без указания all_sports // TODO: переделать на вариант без указания all_sports
return ( return (
<> <>

@ -1,6 +1,6 @@
export const getLocalStorageItem = (key: string) => { export const getLocalStorageItem = (key: string) => {
const item = localStorage.getItem(key)! const item = localStorage.getItem(key)
return JSON.parse(item) return item ? JSON.parse(item) : ''
} }
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any

@ -18,7 +18,7 @@ import { useUserFavoritesStore } from 'features/UserFavorites/store'
import type { Match } from 'requests/getMatches/types' import type { Match } from 'requests/getMatches/types'
import { getSportList } from 'requests/getSportList' import type { Sport } from 'requests/getSportList'
import { getSounds } from 'requests/getSounds' import { getSounds } from 'requests/getSounds'
import { import {
getSportTeams, getSportTeams,
@ -29,6 +29,8 @@ import { getPlayerMatches } from 'requests/getMatches/getPlayerMatches'
import { getTeamPlayers, Player } from 'requests/getTeamPlayers' import { getTeamPlayers, Player } from 'requests/getTeamPlayers'
import { getSearchItems, PlayerTypeFromSearch } from 'requests' import { getSearchItems, PlayerTypeFromSearch } from 'requests'
import { getLocalStorageItem } from 'helpers/getLocalStorage'
import { querieKeys } from 'config'
import { import {
checkedMatches, checkedMatches,
playerMatchesState, playerMatchesState,
@ -36,14 +38,7 @@ import {
fetchingMatches, fetchingMatches,
} from '../../storeHighlightsAtoms' } from '../../storeHighlightsAtoms'
export type SportType = { type SportTypeName = Sport & {
id: number,
lexic: number,
name_eng: string,
name_rus: string,
}
type SportTypeName = SportType & {
disabled?: boolean, disabled?: boolean,
name: string, name: string,
} }
@ -263,15 +258,19 @@ export const useHighlightsForm = () => {
} }
useEffect(() => { useEffect(() => {
getSportList() const sportsList = getLocalStorageItem(querieKeys.sportsList)
.then((res) => setSports( const sportsArray = Object.values(sportsList as Array<Sport>)
res ?.reduce((acc, cur) => {
?.filter(({ id }: SportType) => id === 3 || id === 1) if ([1, 3].includes(cur.id)) {
.map((sport: SportType) => ({ return [
...sport, ...acc, {
name: sport?.name_eng, ...cur,
})), name: cur.name_eng,
)) }]
}
return acc
}, [] as Array<SportTypeName>)
setSports(sportsArray)
getSounds() getSounds()
.then((state) => { .then((state) => {

Loading…
Cancel
Save