keep-around/9c71b58e1d5c96da8427c6d16baea7e760b2da7b
parent
a38def840c
commit
9c71b58e1d
@ -0,0 +1,18 @@ |
|||||||
|
export const sportId = 1 |
||||||
|
|
||||||
|
export const tournamentsId = [227, 946, 3067, 5665] |
||||||
|
|
||||||
|
export const teamsId = [ |
||||||
|
23, |
||||||
|
2719, |
||||||
|
528, |
||||||
|
17018, |
||||||
|
567, |
||||||
|
16306, |
||||||
|
1189, |
||||||
|
480, |
||||||
|
16920, |
||||||
|
6032, |
||||||
|
17624, |
||||||
|
114440, |
||||||
|
] |
||||||
@ -1,13 +1,68 @@ |
|||||||
import { useState } from 'react' |
import { |
||||||
|
useCallback, |
||||||
|
useEffect, |
||||||
|
useState, |
||||||
|
} from 'react' |
||||||
|
|
||||||
|
import map from 'lodash/map' |
||||||
|
|
||||||
|
import { |
||||||
|
getTournaments, |
||||||
|
Tournament, |
||||||
|
} from 'requests/getTournaments' |
||||||
|
import { getTeams, Team } from 'requests/getTeams' |
||||||
|
import { Tournaments } from 'requests/getSportTournaments' |
||||||
|
|
||||||
|
import { |
||||||
|
tournamentsId, |
||||||
|
teamsId, |
||||||
|
sportId, |
||||||
|
} from '../../config' |
||||||
|
|
||||||
export const useTournamentPopup = () => { |
export const useTournamentPopup = () => { |
||||||
const [isOpen, setIsOpen] = useState(false) |
const [isOpen, setIsOpen] = useState(false) |
||||||
|
const [isFetching, setFetching] = useState(true) |
||||||
|
const [tournaments, setTournaments] = useState<Tournaments>([]) |
||||||
|
const [teams, setTeams] = useState<Tournaments>([]) |
||||||
|
|
||||||
const close = () => setIsOpen(false) |
const close = () => setIsOpen(false) |
||||||
const open = () => setIsOpen(true) |
const open = () => setIsOpen(true) |
||||||
|
|
||||||
|
const convertData = useCallback( |
||||||
|
(data: Array<Tournament> | Array<Team>) => map( |
||||||
|
data, |
||||||
|
(tournament) => ({ |
||||||
|
gender: null, |
||||||
|
sport: sportId, |
||||||
|
tournament_type: sportId, |
||||||
|
...tournament, |
||||||
|
}), |
||||||
|
), |
||||||
|
[], |
||||||
|
) |
||||||
|
|
||||||
|
useEffect(() => { |
||||||
|
(async () => { |
||||||
|
Promise.all([ |
||||||
|
getTournaments(1, tournamentsId).then(convertData), |
||||||
|
getTeams(1, teamsId).then(convertData), |
||||||
|
]) |
||||||
|
.then((data) => { |
||||||
|
// @ts-expect-error
|
||||||
|
setTournaments(data[0]) |
||||||
|
// @ts-expect-error
|
||||||
|
setTeams(data[1]) |
||||||
|
setFetching(false) |
||||||
|
}) |
||||||
|
})() |
||||||
|
}, [convertData]) |
||||||
|
|
||||||
return { |
return { |
||||||
close, |
close, |
||||||
|
isFetching, |
||||||
isOpen, |
isOpen, |
||||||
open, |
open, |
||||||
|
teams, |
||||||
|
tournaments, |
||||||
} |
} |
||||||
} |
} |
||||||
|
|||||||
@ -0,0 +1,40 @@ |
|||||||
|
import { |
||||||
|
DATA_URL, |
||||||
|
PROCEDURES, |
||||||
|
} from 'config' |
||||||
|
import { callApi } from 'helpers' |
||||||
|
|
||||||
|
const proc = PROCEDURES.get_teams |
||||||
|
|
||||||
|
export type Team = { |
||||||
|
country: { |
||||||
|
id: number, |
||||||
|
name_eng: string, |
||||||
|
name_rus: string, |
||||||
|
}, |
||||||
|
header_image: string | null, |
||||||
|
id: number, |
||||||
|
is_favorite: boolean, |
||||||
|
name_eng: string, |
||||||
|
name_rus: string, |
||||||
|
short_name_eng: string, |
||||||
|
short_name_rus: string, |
||||||
|
} | null |
||||||
|
|
||||||
|
export const getTeams = (sportId: number, teams: Array<number>) |
||||||
|
: Promise<Array<Team>> => { |
||||||
|
const config = { |
||||||
|
body: { |
||||||
|
params: { |
||||||
|
_p_sport_id: sportId, |
||||||
|
_p_teams: teams, |
||||||
|
}, |
||||||
|
proc, |
||||||
|
}, |
||||||
|
} |
||||||
|
|
||||||
|
return callApi({ |
||||||
|
config, |
||||||
|
url: DATA_URL, |
||||||
|
}) |
||||||
|
} |
||||||
@ -0,0 +1,40 @@ |
|||||||
|
import { |
||||||
|
DATA_URL, |
||||||
|
PROCEDURES, |
||||||
|
} from 'config' |
||||||
|
import { callApi } from 'helpers' |
||||||
|
|
||||||
|
const proc = PROCEDURES.get_tournaments |
||||||
|
|
||||||
|
export type Tournament = { |
||||||
|
country: { |
||||||
|
id: number, |
||||||
|
name_eng: string, |
||||||
|
name_rus: string, |
||||||
|
}, |
||||||
|
header_image: string | null, |
||||||
|
id: number, |
||||||
|
is_favorite: boolean, |
||||||
|
name_eng: string, |
||||||
|
name_rus: string, |
||||||
|
short_name_eng: string, |
||||||
|
short_name_rus: string, |
||||||
|
} | null |
||||||
|
|
||||||
|
export const getTournaments = (sportId: number, tournaments: Array<number>) |
||||||
|
: Promise<Array<Tournament>> => { |
||||||
|
const config = { |
||||||
|
body: { |
||||||
|
params: { |
||||||
|
_p_sport_id: sportId, |
||||||
|
_p_tournaments: tournaments, |
||||||
|
}, |
||||||
|
proc, |
||||||
|
}, |
||||||
|
} |
||||||
|
|
||||||
|
return callApi({ |
||||||
|
config, |
||||||
|
url: DATA_URL, |
||||||
|
}) |
||||||
|
} |
||||||
Loading…
Reference in new issue