From 53e0abae2de19dd819173655f99984ff10b5f8f4 Mon Sep 17 00:00:00 2001 From: Mirlan Date: Wed, 29 Sep 2021 15:33:56 +0600 Subject: [PATCH] Ott 1710 disable preferences on facr (#510) * refactor(1710): replaced hooks usePageId useSportNameParam to usePageParams * feat(1710): added config to disable preferencse --- src/config/clients/facr.tsx | 1 + src/config/clients/types.tsx | 1 + .../components/FinishedMatch/hooks/index.tsx | 10 +++------- .../FinishedMatch/hooks/useChapters.tsx | 5 ++--- .../FinishedMatch/hooks/useEpisodes.tsx | 5 ++--- .../components/MatchProfileCard/index.tsx | 4 ++-- .../MatchPage/hooks/useLastPlayPosition.tsx | 10 +++------- src/features/MatchPage/hooks/useMatchProfile.tsx | 10 +++------- .../hooks/usePlayerProgressReporter.tsx | 10 +++------- src/features/Menu/index.tsx | 5 +++-- src/features/PlayerPage/hooks.tsx | 5 ++--- .../PreferencesPopup/store/hooks/index.tsx | 4 +++- src/features/TeamPage/hooks.tsx | 5 ++--- src/features/TournamentPage/hooks.tsx | 5 ++--- src/hooks/index.tsx | 2 -- src/hooks/usePageId.tsx | 13 ------------- src/hooks/useSportNameParam.tsx | 16 ---------------- 17 files changed, 32 insertions(+), 79 deletions(-) delete mode 100644 src/hooks/usePageId.tsx delete mode 100644 src/hooks/useSportNameParam.tsx diff --git a/src/config/clients/facr.tsx b/src/config/clients/facr.tsx index f36b1ef9..52c9c902 100644 --- a/src/config/clients/facr.tsx +++ b/src/config/clients/facr.tsx @@ -13,6 +13,7 @@ export const facr: ClientConfig = { metaDataUrlParams: `?hash=${randomHash()}`, }, defaultLanguage: 'cs', + disabledPreferences: true, requests: { [PROCEDURES.get_matches]: params, [PROCEDURES.get_team_matches]: params, diff --git a/src/config/clients/types.tsx b/src/config/clients/types.tsx index 5f03d824..e79de112 100644 --- a/src/config/clients/types.tsx +++ b/src/config/clients/types.tsx @@ -9,6 +9,7 @@ export type ClientConfig = { metaDataUrlParams?: string, }, defaultLanguage?: Languages, + disabledPreferences?: boolean, requests?: Record, styles: { background?: string, diff --git a/src/features/MatchPage/components/FinishedMatch/hooks/index.tsx b/src/features/MatchPage/components/FinishedMatch/hooks/index.tsx index bbc65f83..ad076a94 100644 --- a/src/features/MatchPage/components/FinishedMatch/hooks/index.tsx +++ b/src/features/MatchPage/components/FinishedMatch/hooks/index.tsx @@ -2,11 +2,8 @@ import { useEffect } from 'react' import type { MatchInfo } from 'requests' -import { - useSportNameParam, - usePageId, - useToggle, -} from 'hooks' +import { usePageParams } from 'hooks/usePageParams' +import { useToggle } from 'hooks/useToggle' import type { Settings } from 'features/MatchPopup' import { useMatchPopupStore } from 'features/MatchPopup' @@ -29,8 +26,7 @@ export const useFinishedMatch = ({ profile }: Props) => { setMatch, setSettings, } = useMatchPopupStore() - const { sportType } = useSportNameParam() - const matchId = usePageId() + const { profileId: matchId, sportType } = usePageParams() const { close: closeSettingsPopup, isOpen: isSettingsPopupOpen, diff --git a/src/features/MatchPage/components/FinishedMatch/hooks/useChapters.tsx b/src/features/MatchPage/components/FinishedMatch/hooks/useChapters.tsx index 5a61b0f3..747bfe31 100644 --- a/src/features/MatchPage/components/FinishedMatch/hooks/useChapters.tsx +++ b/src/features/MatchPage/components/FinishedMatch/hooks/useChapters.tsx @@ -7,7 +7,7 @@ import { import type { Episodes, Videos } from 'requests' import { getVideos } from 'requests' -import { usePageId, useSportNameParam } from 'hooks' +import { usePageParams } from 'hooks/usePageParams' import type { PlaylistOption } from 'features/MatchPage/types' @@ -23,8 +23,7 @@ export const useChapters = ({ selectedPlaylist, }: Args) => { const [videos, setVideos] = useState([]) - const { sportType } = useSportNameParam() - const matchId = usePageId() + const { profileId: matchId, sportType } = usePageParams() useEffect(() => { getVideos(sportType, matchId).then(setVideos) diff --git a/src/features/MatchPage/components/FinishedMatch/hooks/useEpisodes.tsx b/src/features/MatchPage/components/FinishedMatch/hooks/useEpisodes.tsx index d8524f79..04a2edaa 100644 --- a/src/features/MatchPage/components/FinishedMatch/hooks/useEpisodes.tsx +++ b/src/features/MatchPage/components/FinishedMatch/hooks/useEpisodes.tsx @@ -9,7 +9,7 @@ import isEmpty from 'lodash/isEmpty' import type { Episodes } from 'requests' import { getPlayerPlaylists } from 'requests' -import { usePageId, useSportNameParam } from 'hooks' +import { usePageParams } from 'hooks/usePageParams' import { PlaylistOption, PlaylistTypes } from 'features/MatchPage/types' import { @@ -26,8 +26,7 @@ export const useEpisodes = () => { settings, } = useMatchPopupStore() const [episodes, setEpisodes] = useState([]) - const { sportType } = useSportNameParam() - const matchId = usePageId() + const { profileId: matchId, sportType } = usePageParams() const fetchEpisodes = useCallback(( playlistOption: PlaylistOption, diff --git a/src/features/MatchPage/components/MatchProfileCard/index.tsx b/src/features/MatchPage/components/MatchProfileCard/index.tsx index 781994fd..a9bea42c 100644 --- a/src/features/MatchPage/components/MatchProfileCard/index.tsx +++ b/src/features/MatchPage/components/MatchProfileCard/index.tsx @@ -5,7 +5,7 @@ import { ProfileTypes } from 'config' import { useMatchSwitchesStore } from 'features/MatchSwitches' import { Name } from 'features/Name' -import { useSportNameParam } from 'hooks/useSportNameParam' +import { usePageParams } from 'hooks/usePageParams' import { Wrapper, @@ -21,7 +21,7 @@ type Props = { } export const MatchProfileCard = ({ profile }: Props) => { - const { sportType } = useSportNameParam() + const { sportType } = usePageParams() const { isScoreHidden } = useMatchSwitchesStore() if (!profile) return diff --git a/src/features/MatchPage/hooks/useLastPlayPosition.tsx b/src/features/MatchPage/hooks/useLastPlayPosition.tsx index 5e09f32b..885f0470 100644 --- a/src/features/MatchPage/hooks/useLastPlayPosition.tsx +++ b/src/features/MatchPage/hooks/useLastPlayPosition.tsx @@ -3,11 +3,8 @@ import { useEffect, useState } from 'react' import type { LastPlayPosition } from 'requests' import { getMatchLastWatchSeconds } from 'requests' -import { - useSportNameParam, - usePageId, - useRequest, -} from 'hooks' +import { usePageParams } from 'hooks/usePageParams' +import { useRequest } from 'hooks/useRequest' const initialPosition = { half: 0, @@ -15,8 +12,7 @@ const initialPosition = { } export const useLastPlayPosition = () => { - const { sportType } = useSportNameParam() - const matchId = usePageId() + const { profileId: matchId, sportType } = usePageParams() const [ lastPlayPosition, setPosition, diff --git a/src/features/MatchPage/hooks/useMatchProfile.tsx b/src/features/MatchPage/hooks/useMatchProfile.tsx index e94abd55..a7dd4402 100644 --- a/src/features/MatchPage/hooks/useMatchProfile.tsx +++ b/src/features/MatchPage/hooks/useMatchProfile.tsx @@ -7,18 +7,14 @@ import { import type { MatchInfo } from 'requests' import { getMatchInfo } from 'requests' -import { - useSportNameParam, - useInterval, - usePageId, -} from 'hooks' +import { usePageParams } from 'hooks/usePageParams' +import { useInterval } from 'hooks/useInterval' import { MATCH_UPDATE_INTERVAL } from '../config' export const useMatchProfile = () => { const [matchProfile, setMatchProfile] = useState(null) - const { sportType } = useSportNameParam() - const matchId = usePageId() + const { profileId: matchId, sportType } = usePageParams() const fetchMatchProfile = useCallback(() => { getMatchInfo(sportType, matchId).then(setMatchProfile) diff --git a/src/features/MatchPage/hooks/usePlayerProgressReporter.tsx b/src/features/MatchPage/hooks/usePlayerProgressReporter.tsx index fae19c75..b393f8f3 100644 --- a/src/features/MatchPage/hooks/usePlayerProgressReporter.tsx +++ b/src/features/MatchPage/hooks/usePlayerProgressReporter.tsx @@ -2,17 +2,13 @@ import { useCallback, useRef } from 'react' import { reportPlayerProgress } from 'requests' -import { - useSportNameParam, - usePageId, - useInterval, -} from 'hooks' +import { usePageParams } from 'hooks/usePageParams' +import { useInterval } from 'hooks/useInterval' const reportRequestInterval = 30000 export const usePlayerProgressReporter = () => { - const { sportType } = useSportNameParam() - const matchId = usePageId() + const { profileId: matchId, sportType } = usePageParams() const playerData = useRef({ period: 0, seconds: 0 }) const intervalCallback = () => { diff --git a/src/features/Menu/index.tsx b/src/features/Menu/index.tsx index babb40ac..f46e1b0a 100644 --- a/src/features/Menu/index.tsx +++ b/src/features/Menu/index.tsx @@ -1,7 +1,8 @@ import { Link, useRouteMatch } from 'react-router-dom' -import { PAGES } from 'config' import { isMobileDevice } from 'config/userAgent' +import { client } from 'config/clients' +import { PAGES } from 'config/pages' import { usePreferencesStore } from 'features/PreferencesPopup' @@ -20,7 +21,7 @@ export const Menu = () => { {isMobileDevice && } { - isHomePage && ( + isHomePage && !client.disabledPreferences && ( diff --git a/src/features/PlayerPage/hooks.tsx b/src/features/PlayerPage/hooks.tsx index aa6957ef..e569a110 100644 --- a/src/features/PlayerPage/hooks.tsx +++ b/src/features/PlayerPage/hooks.tsx @@ -4,15 +4,14 @@ import { useCallback, } from 'react' -import { useSportNameParam, usePageId } from 'hooks' +import { usePageParams } from 'hooks/usePageParams' import type { PlayerProfile } from 'requests/getPlayerInfo' import { getPlayerInfo, getPlayerMatches } from 'requests' export const usePlayerPage = () => { const [playerProfile, setPlayerProfile] = useState(null) - const { sportType } = useSportNameParam() - const playerId = usePageId() + const { profileId: playerId, sportType } = usePageParams() const { firstname_eng = '', diff --git a/src/features/PreferencesPopup/store/hooks/index.tsx b/src/features/PreferencesPopup/store/hooks/index.tsx index 44d55c48..5365a0b6 100644 --- a/src/features/PreferencesPopup/store/hooks/index.tsx +++ b/src/features/PreferencesPopup/store/hooks/index.tsx @@ -4,6 +4,8 @@ import isBoolean from 'lodash/isBoolean' import uniq from 'lodash/uniq' import map from 'lodash/map' +import { client } from 'config/clients' + import { useLocalStore, useToggle } from 'hooks' import { useTournamentsBySports } from './useTournamentsBySports' @@ -14,7 +16,7 @@ import { useSearch } from './useSearch' export const usePreferences = () => { const [firstLoad, setFirstLoad] = useLocalStore({ - defaultValue: true, + defaultValue: !client.disabledPreferences, key: 'preferences_first_load', validator: isBoolean, }) diff --git a/src/features/TeamPage/hooks.tsx b/src/features/TeamPage/hooks.tsx index 5eddfebf..f42aa4c5 100644 --- a/src/features/TeamPage/hooks.tsx +++ b/src/features/TeamPage/hooks.tsx @@ -7,12 +7,11 @@ import { import type { TeamInfo } from 'requests' import { getTeamInfo, getTeamMatches } from 'requests' -import { useSportNameParam, usePageId } from 'hooks' +import { usePageParams } from 'hooks/usePageParams' export const useTeamPage = () => { const [teamProfile, setTeamProfile] = useState(null) - const { sportType } = useSportNameParam() - const teamId = usePageId() + const { profileId: teamId, sportType } = usePageParams() useEffect(() => { getTeamInfo(sportType, teamId) diff --git a/src/features/TournamentPage/hooks.tsx b/src/features/TournamentPage/hooks.tsx index f49158f1..38496eaf 100644 --- a/src/features/TournamentPage/hooks.tsx +++ b/src/features/TournamentPage/hooks.tsx @@ -7,14 +7,13 @@ import { import type { TournamentInfo } from 'requests' import { getTournamentInfo, getTournamentMatches } from 'requests' -import { useSportNameParam, usePageId } from 'hooks' +import { usePageParams } from 'hooks/usePageParams' import { useName } from 'features/Name' export const useTournamentPage = () => { const [tournamentProfile, setTournamentProfile] = useState(null) - const { sportType } = useSportNameParam() - const tournamentId = usePageId() + const { profileId: tournamentId, sportType } = usePageParams() const country = useName(tournamentProfile?.country || {}) useEffect(() => { diff --git a/src/hooks/index.tsx b/src/hooks/index.tsx index bf94cc3b..f318328b 100644 --- a/src/hooks/index.tsx +++ b/src/hooks/index.tsx @@ -1,7 +1,5 @@ -export * from './usePageId' export * from './useToggle' export * from './useRequest' -export * from './useSportNameParam' export * from './useStorage' export * from './useInterval' export * from './useEventListener' diff --git a/src/hooks/usePageId.tsx b/src/hooks/usePageId.tsx deleted file mode 100644 index 3576b38d..00000000 --- a/src/hooks/usePageId.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import { useParams } from 'react-router-dom' - -type Params = { - pageId: string, -} - -/** - * Хук возвращает id страницы - */ -export const usePageId = () => { - const { pageId } = useParams() - return Number(pageId) -} diff --git a/src/hooks/useSportNameParam.tsx b/src/hooks/useSportNameParam.tsx deleted file mode 100644 index f13f35fe..00000000 --- a/src/hooks/useSportNameParam.tsx +++ /dev/null @@ -1,16 +0,0 @@ -import { useParams } from 'react-router' - -import toUpper from 'lodash/toUpper' - -import { SportTypes } from 'config' - -type SportName = 'FOOTBALL' | 'HOCKEY' | 'BASKETBALL' - -export const useSportNameParam = () => { - const { sportName } = useParams<{ sportName: string }>() - - return { - sportName, - sportType: SportTypes[toUpper(sportName) as SportName], - } -}