parent
5f93cc4717
commit
3795025519
@ -0,0 +1,9 @@ |
||||
export const landingLexics = { |
||||
inactive_button: 20083, |
||||
inactive_description_1: 20084, |
||||
inactive_description_2: 20086, |
||||
inactive_period: 801, |
||||
inactive_title_1: 20087, |
||||
inactive_title_2: 20088, |
||||
|
||||
} |
||||
@ -0,0 +1,141 @@ |
||||
import { |
||||
useEffect, |
||||
useState, |
||||
} from 'react' |
||||
|
||||
import size from 'lodash/size' |
||||
import includes from 'lodash/includes' |
||||
|
||||
import type { Landing } from 'requests/getLanding' |
||||
import { getLanding } from 'requests/getLanding' |
||||
|
||||
import { PAGES } from 'config/pages' |
||||
|
||||
import { redirectToUrl } from 'helpers/redirectToUrl' |
||||
|
||||
import { useLexicsStore } from 'features/LexicsStore' |
||||
import { useAuthStore } from 'features/AuthStore' |
||||
|
||||
import { getLandingName, isPastLandingDate } from './helpers' |
||||
import { getName } from '../Name' |
||||
|
||||
export const useLandings = () => { |
||||
const [tournamentInfo, setTournamentInfo] = useState<Landing | null>(null) |
||||
const [isInactiveLanding, setIsInactiveLanding] = useState(false) |
||||
|
||||
const { addLexicsConfig, suffix } = useLexicsStore() |
||||
const { |
||||
landingUrlFrom, |
||||
setIsFromLanding, |
||||
user, |
||||
} = useAuthStore() |
||||
|
||||
const buttonLexic = tournamentInfo?.lexic_button || '' |
||||
const period = tournamentInfo?.lexic_period || '' |
||||
const title = tournamentInfo?.lexic_title || '' |
||||
const description = tournamentInfo?.lexic_description || '' |
||||
const gallery = tournamentInfo?.media.gallery |
||||
|
||||
useEffect(() => { |
||||
const lexics = [buttonLexic, period, title, description] |
||||
addLexicsConfig(lexics) |
||||
}, [ |
||||
addLexicsConfig, |
||||
buttonLexic, |
||||
description, |
||||
period, |
||||
title, |
||||
]) |
||||
|
||||
const redirectToHomePage = () => redirectToUrl(PAGES.home) |
||||
const onButtonClick = () => { |
||||
if (includes(landingUrlFrom, PAGES.match) || includes(landingUrlFrom, PAGES.tournament)) { |
||||
setIsFromLanding(true) |
||||
redirectToUrl(landingUrlFrom) |
||||
sessionStorage.removeItem('landingUrlFrom') |
||||
} else { |
||||
redirectToUrl(tournamentInfo?.url_button || '') |
||||
} |
||||
} |
||||
|
||||
useEffect(() => { |
||||
(async () => { |
||||
const landingData = sessionStorage.getItem('landingData') |
||||
const parseLandingDate = landingData && JSON.parse(landingData) |
||||
|
||||
try { |
||||
const date = landingUrlFrom |
||||
? await getLanding({ |
||||
landingName: parseLandingDate.landing_id || parseLandingDate.url_landing, |
||||
seasonId: parseLandingDate.season_id, |
||||
sportId: parseLandingDate.sport_id, |
||||
tournamentId: parseLandingDate.tournament_id, |
||||
}) |
||||
: await getLanding({ landingName: getLandingName() }) |
||||
if (user) return redirectToUrl(date.url_button || '') |
||||
if (isPastLandingDate(date.date_to)) setIsInactiveLanding(true) |
||||
setTournamentInfo(date) |
||||
return sessionStorage.removeItem('landingData') |
||||
} catch (err) { |
||||
return redirectToHomePage() |
||||
} |
||||
})() |
||||
}, [landingUrlFrom, user]) |
||||
|
||||
const [sliderItemId, setSliderItemId] = useState(0) |
||||
|
||||
const onSliderSwitchClick = (itemId: number) => setSliderItemId(itemId) |
||||
|
||||
const imgCounter = size(gallery) |
||||
|
||||
useEffect(() => { |
||||
if (sliderItemId === imgCounter) { |
||||
setSliderItemId(0) |
||||
} |
||||
const getSliderInterval = setInterval(() => { |
||||
setSliderItemId(sliderItemId + 1) |
||||
}, 5000) |
||||
return () => clearInterval(getSliderInterval) |
||||
}, [imgCounter, sliderItemId]) |
||||
|
||||
const isInactiveLandingData = () => { |
||||
if (!tournamentInfo?.tournaments || !isInactiveLanding) return null |
||||
|
||||
const { |
||||
season, |
||||
tournament_eng, |
||||
tournament_rus, |
||||
} = tournamentInfo.tournaments[0] |
||||
|
||||
const currentTournamentsTitle = { |
||||
name_eng: tournament_eng, |
||||
name_rus: tournament_rus, |
||||
} |
||||
|
||||
const tournamentsTitle = getName({ nameObj: currentTournamentsTitle, suffix }) |
||||
|
||||
return { |
||||
season, |
||||
tournamentsTitle, |
||||
} |
||||
} |
||||
|
||||
return { |
||||
buttonColor: tournamentInfo?.button_color, |
||||
buttonLexic, |
||||
description, |
||||
gallery, |
||||
isInactiveLanding, |
||||
isInactiveLandingData: isInactiveLandingData(), |
||||
logo: tournamentInfo?.media.logo, |
||||
logoInsports: tournamentInfo?.logo_insports, |
||||
onButtonClick, |
||||
onSliderSwitchClick, |
||||
period, |
||||
redirectToHomePage, |
||||
sliderItemId, |
||||
teams: tournamentInfo?.teams, |
||||
title, |
||||
tournamentInfo, |
||||
} |
||||
} |
||||
@ -1,96 +0,0 @@ |
||||
import { |
||||
useEffect, |
||||
useState, |
||||
} from 'react' |
||||
|
||||
import size from 'lodash/size' |
||||
import includes from 'lodash/includes' |
||||
|
||||
import type { TournamentLanding } from 'requests/getTournamentLanding' |
||||
import { getTournamentLanding } from 'requests/getTournamentLanding' |
||||
|
||||
import { PAGES } from 'config/pages' |
||||
|
||||
import { redirectToUrl } from 'helpers/redirectToUrl' |
||||
|
||||
import { useLexicsStore } from 'features/LexicsStore' |
||||
import { useAuthStore } from 'features/AuthStore' |
||||
|
||||
import { getLandingName, isPastLandingDate } from './helpers' |
||||
|
||||
export const useTournamentLanding = () => { |
||||
const [tournamentInfo, setTournamentInfo] = useState<TournamentLanding | null>(null) |
||||
|
||||
const { addLexicsConfig } = useLexicsStore() |
||||
const { page, setIsFromLanding } = useAuthStore() |
||||
|
||||
const buttonLexic = tournamentInfo?.lexic_button || '' |
||||
const period = tournamentInfo?.lexic_period || '' |
||||
const title = tournamentInfo?.lexic_title || '' |
||||
const description = tournamentInfo?.lexic_description || '' |
||||
const gallery = tournamentInfo?.media.gallery |
||||
|
||||
useEffect(() => { |
||||
const lexics = [buttonLexic, period, title, description] |
||||
addLexicsConfig(lexics) |
||||
}, [ |
||||
addLexicsConfig, |
||||
buttonLexic, |
||||
description, |
||||
period, |
||||
title, |
||||
]) |
||||
|
||||
const redirectToHomePage = () => redirectToUrl(PAGES.home) |
||||
const onButtonClick = () => { |
||||
if (includes(page, 'matches')) { |
||||
setIsFromLanding(true) |
||||
redirectToUrl(page) |
||||
} else { |
||||
redirectToUrl(tournamentInfo?.url_button || '') |
||||
} |
||||
} |
||||
|
||||
useEffect(() => { |
||||
getTournamentLanding(getLandingName()) |
||||
.then((data) => ( |
||||
isPastLandingDate(data.date_to) |
||||
? redirectToHomePage() |
||||
: setTournamentInfo(data) |
||||
)) |
||||
.catch(redirectToHomePage) |
||||
}, []) |
||||
|
||||
const [sliderItemId, setSliderItemId] = useState(0) |
||||
|
||||
const onSliderSwitchClick = (itemId: number) => setSliderItemId(itemId) |
||||
|
||||
const imgCounter = size(gallery) |
||||
|
||||
useEffect(() => { |
||||
if (sliderItemId === imgCounter) { |
||||
setSliderItemId(0) |
||||
} |
||||
const getSliderInterval = setInterval(() => { |
||||
setSliderItemId(sliderItemId + 1) |
||||
}, 5000) |
||||
return () => clearInterval(getSliderInterval) |
||||
}, [imgCounter, sliderItemId]) |
||||
|
||||
return { |
||||
buttonColor: tournamentInfo?.button_color, |
||||
buttonLexic, |
||||
description, |
||||
gallery, |
||||
logo: tournamentInfo?.media.logo, |
||||
logoInsports: tournamentInfo?.logo_insports, |
||||
onButtonClick, |
||||
onSliderSwitchClick, |
||||
period, |
||||
redirectToHomePage, |
||||
sliderItemId, |
||||
teams: tournamentInfo?.teams, |
||||
title, |
||||
tournamentInfo, |
||||
} |
||||
} |
||||
@ -1,21 +1,35 @@ |
||||
import isUndefined from 'lodash/isUndefined' |
||||
|
||||
import { API_ROOT } from 'config' |
||||
import { callApi } from 'helpers' |
||||
|
||||
type Args = { |
||||
matchId: number, |
||||
matchId?: number, |
||||
sportType: number, |
||||
tournamentId?: number, |
||||
} |
||||
|
||||
type LandingStatus = { |
||||
landing_id: number, |
||||
season_id: number, |
||||
sport_id: number, |
||||
tournament_id: number, |
||||
url_landing: string, |
||||
} |
||||
|
||||
export const getLandingStatus = async ({ |
||||
matchId, |
||||
sportType, |
||||
}: Args): Promise<{landing_id: number | null}> => { |
||||
tournamentId, |
||||
}: Args): Promise<LandingStatus> => { |
||||
const config = { |
||||
method: 'GET', |
||||
} |
||||
|
||||
return callApi({ |
||||
config, |
||||
url: `${API_ROOT}/v1/landings/${sportType}/${matchId}/status`, |
||||
url: `${API_ROOT}/v1/landings/status/${sportType}?${ |
||||
isUndefined(matchId) ? '' : `match_id=${matchId}`}${ |
||||
isUndefined(tournamentId) ? '' : `tournament_id=${tournamentId}`}`,
|
||||
}) |
||||
} |
||||
|
||||
Loading…
Reference in new issue