Revert "feat(#680): add statsview page"

This reverts commit 0e147688a5.
pull/261/head
andreidekterev 3 years ago committed by Gitea
parent c90d4fc769
commit 17e8794399
  1. 2
      src/config/lexics/indexLexics.tsx
  2. 3
      src/config/lexics/statsviewLexics.tsx
  3. 1
      src/config/pages.tsx
  4. 4
      src/features/App/AuthenticatedApp.tsx
  5. 6
      src/features/MatchPage/store/hooks/useTeamsStats.tsx
  6. 7
      src/features/MatchSidePlaylists/components/TeamsStatsTable/Cell.tsx
  7. 32
      src/features/MatchSidePlaylists/components/TeamsStatsTable/hooks.tsx
  8. 71
      src/features/MatchSidePlaylists/components/TeamsStatsTable/index.tsx
  9. 90
      src/pages/StatsView/components/StatsTable.tsx
  10. 16
      src/pages/StatsView/helpers/getStatsItem.tsx
  11. 22
      src/pages/StatsView/helpers/getStatsLexic.tsx
  12. 2
      src/pages/StatsView/helpers/index.tsx
  13. 78
      src/pages/StatsView/hooks.tsx
  14. 35
      src/pages/StatsView/index.tsx
  15. 25
      src/pages/StatsView/styled.tsx
  16. 6
      src/requests/getTeamsStats.tsx

@ -5,7 +5,6 @@ import { mailingsLexics } from './mailings'
import { sportsLexic } from './sportsLexic' import { sportsLexic } from './sportsLexic'
import { landingLexics } from './landingLexics' import { landingLexics } from './landingLexics'
import { matchDownload } from './matchDownload' import { matchDownload } from './matchDownload'
import { statsviewLexics } from './statsviewLexics'
const matchPopupLexics = { const matchPopupLexics = {
actions: 1020, actions: 1020,
@ -226,5 +225,4 @@ export const indexLexics = {
...sportsPopup, ...sportsPopup,
...landingLexics, ...landingLexics,
...matchDownload, ...matchDownload,
...statsviewLexics,
} }

@ -1,3 +0,0 @@
export const statsviewLexics = {
powered_by: 20210,
}

@ -7,7 +7,6 @@ export const PAGES = {
mailings: '/useraccount/mailings', mailings: '/useraccount/mailings',
match: '/matches', match: '/matches',
player: '/players', player: '/players',
statsview: '/statsview',
team: '/teams', team: '/teams',
thanksForSubscribe: '/thanks-for-subscription', thanksForSubscribe: '/thanks-for-subscription',
tournament: '/tournaments', tournament: '/tournaments',

@ -41,7 +41,6 @@ const HighlightsPage = lazy(() => import('pages/HighlightsPage'))
const ThanksPage = lazy(() => import('pages/ThanksPage')) const ThanksPage = lazy(() => import('pages/ThanksPage'))
const Mailings = lazy(() => import('pages/Mailings')) const Mailings = lazy(() => import('pages/Mailings'))
const FailedPaymeePage = lazy(() => import('pages/FailedPaymeePage')) const FailedPaymeePage = lazy(() => import('pages/FailedPaymeePage'))
const StatsView = lazy(() => import('pages/StatsView'))
export const AuthenticatedApp = () => { export const AuthenticatedApp = () => {
useSportList() useSportList()
@ -78,9 +77,6 @@ export const AuthenticatedApp = () => {
<Route exact path={PAGES.home}> <Route exact path={PAGES.home}>
<HomePage /> <HomePage />
</Route> </Route>
<Route path={`/:sportName${PAGES.statsview}/:pageId`}>
<StatsView />
</Route>
<Route path={`/:sportName${PAGES.tournament}/:pageId`}> <Route path={`/:sportName${PAGES.tournament}/:pageId`}>
<TournamentPage /> <TournamentPage />
</Route> </Route>

@ -23,7 +23,7 @@ import { getTeamsStats, TeamStatItem } from 'requests'
import { usePageParams } from 'hooks' import { usePageParams } from 'hooks'
import { getLocalStorageItem, isMatchPage } from 'helpers' import { getLocalStorageItem } from 'helpers/getLocalStorage'
import { StatsType, Tabs as StatsTab } from 'features/MatchSidePlaylists/components/TabStats/config' import { StatsType, Tabs as StatsTab } from 'features/MatchSidePlaylists/components/TabStats/config'
import { getHalfTime } from 'features/MatchPage/helpers/getHalfTime' import { getHalfTime } from 'features/MatchPage/helpers/getHalfTime'
@ -44,7 +44,7 @@ type UseTeamsStatsArgs = {
statsType: StatsType, statsType: StatsType,
} }
export type TeamsStats = { type TeamsStats = {
[teamId: number]: Array<TeamStatItem>, [teamId: number]: Array<TeamStatItem>,
} }
@ -73,7 +73,7 @@ export const useTeamsStats = ({
) )
const getFirstClickableParam = useCallback((stats: TeamsStats) => { const getFirstClickableParam = useCallback((stats: TeamsStats) => {
if (isEmpty(stats) || !isMatchPage()) return null if (isEmpty(stats)) return null
const statItem = (matchProfile?.team1.id && find( const statItem = (matchProfile?.team1.id && find(
stats[matchProfile.team1.id], stats[matchProfile.team1.id],

@ -31,7 +31,6 @@ import { useMatchPageStore } from 'features/MatchPage/store'
import { useLexicsStore } from 'features/LexicsStore' import { useLexicsStore } from 'features/LexicsStore'
import { Spotlight, Steps } from 'features/MatchTour' import { Spotlight, Steps } from 'features/MatchTour'
import { isMatchPage } from 'helpers'
import { StatsType } from '../TabStats/config' import { StatsType } from '../TabStats/config'
import { CircleAnimationBar } from '../CircleAnimationBar' import { CircleAnimationBar } from '../CircleAnimationBar'
@ -98,7 +97,7 @@ export const Cell = ({
) )
const onParamClick = async (param: Param, paramName: string) => { const onParamClick = async (param: Param, paramName: string) => {
if (!isMatchPage() && !isClickable(param)) return if (!isClickable(param)) return
disablePlayingEpisodes() disablePlayingEpisodes()
@ -172,7 +171,7 @@ export const Cell = ({
) )
: ( : (
<ParamValue <ParamValue
clickable={isMatchPage() && isClickable(teamStatItem.param1)} clickable={isClickable(teamStatItem.param1)}
onClick={() => onParamClick(teamStatItem.param1, translate(teamStatItem.lexic))} onClick={() => onParamClick(teamStatItem.param1, translate(teamStatItem.lexic))}
data-param-id={teamStatItem.param1.id} data-param-id={teamStatItem.param1.id}
hasValue={Boolean(teamStatItem.param1.val)} hasValue={Boolean(teamStatItem.param1.val)}
@ -213,7 +212,7 @@ export const Cell = ({
<Fragment> <Fragment>
<Divider>/</Divider> <Divider>/</Divider>
<ParamValue <ParamValue
clickable={isMatchPage() && isClickable(teamStatItem.param2)} clickable={isClickable(teamStatItem.param2)}
onClick={() => onParamClick( onClick={() => onParamClick(
teamStatItem.param2!, teamStatItem.param2!,
translate(teamStatItem.lexic), translate(teamStatItem.lexic),

@ -1,8 +1,12 @@
import { useEffect, useMemo } from 'react' import { useEffect, useMemo } from 'react'
import find from 'lodash/find'
import reduce from 'lodash/reduce'
import type { TeamStatItem } from 'requests'
import { useMatchPageStore } from 'features/MatchPage/store' import { useMatchPageStore } from 'features/MatchPage/store'
import { useLexicsConfig } from 'features/LexicsStore' import { useLexicsConfig } from 'features/LexicsStore'
import { getStatsLexics } from 'pages/StatsView/helpers'
export const useTeamsStatsTable = () => { export const useTeamsStatsTable = () => {
const { const {
@ -13,12 +17,31 @@ export const useTeamsStatsTable = () => {
teamsStats, teamsStats,
} = useMatchPageStore() } = useMatchPageStore()
const statsLexicIds = useMemo( const lexicsIds = useMemo(
() => getStatsLexics({ matchProfile: profile, stats: teamsStats }), () => (
profile
? reduce<TeamStatItem, Array<number>>(
teamsStats[profile.team1.id],
(acc, curr) => {
!acc.includes(curr.lexic) && acc.push(curr.lexic)
!acc.includes(curr.param1.lexic) && acc.push(curr.param1.lexic)
curr.param2 && !acc.includes(curr.param2.lexic) && acc.push(curr.param2.lexic)
return acc
},
[],
)
: []),
[profile, teamsStats], [profile, teamsStats],
) )
useLexicsConfig(statsLexicIds) useLexicsConfig(lexicsIds)
const getStatItemById = (paramId: number) => {
if (!profile) return null
return find(teamsStats[profile?.team2.id], ({ param1 }) => param1.id === paramId) || null
}
useEffect(() => { useEffect(() => {
setCircleAnimation((state) => ({ setCircleAnimation((state) => ({
@ -29,5 +52,6 @@ export const useTeamsStatsTable = () => {
return { return {
firstClickableParam: getFirstClickableParam(teamsStats), firstClickableParam: getFirstClickableParam(teamsStats),
getStatItemById,
} }
} }

@ -1,12 +1,23 @@
import { useTour } from '@reactour/tour' import { useTour } from '@reactour/tour'
import map from 'lodash/map'
import { useMatchPageStore } from 'features/MatchPage/store' import { useMatchPageStore } from 'features/MatchPage/store'
import { Loader } from 'features/Loader' import { Loader } from 'features/Loader'
import { defaultTheme } from 'features/Theme/config' import { defaultTheme } from 'features/Theme/config'
import { StatsTable } from 'pages/StatsView/components/StatsTable'
import { useTeamsStatsTable } from './hooks' import { useTeamsStatsTable } from './hooks'
import { Cell } from './Cell'
import {
Container,
TableWrapper,
Table,
Header,
Row,
CellContainer,
TeamShortName,
StatItemTitle,
} from './styled'
export const TeamsStatsTable = () => { export const TeamsStatsTable = () => {
const { const {
@ -17,6 +28,7 @@ export const TeamsStatsTable = () => {
const { const {
firstClickableParam, firstClickableParam,
getStatItemById,
} = useTeamsStatsTable() } = useTeamsStatsTable()
const { isOpen } = useTour() const { isOpen } = useTour()
@ -30,11 +42,54 @@ export const TeamsStatsTable = () => {
} }
return ( return (
<StatsTable <Container>
firstClickableParam={firstClickableParam} <TableWrapper isOpenTour={Boolean(isOpen)}>
isOpen={Boolean(isOpen)} <Table role='marquee' aria-live='off'>
profile={profile} <Header>
teamsStats={teamsStats} <Row>
/> <CellContainer as='th'>
<TeamShortName
nameObj={profile.team1}
prefix='abbrev_'
/>
</CellContainer>
<CellContainer as='th' />
<CellContainer as='th'>
<TeamShortName
nameObj={profile.team2}
prefix='abbrev_'
/>
</CellContainer>
</Row>
</Header>
<tbody>
{map(teamsStats[profile.team1.id], (team1StatItem) => {
const team2StatItem = getStatItemById(team1StatItem.param1.id)
return (
<Row key={team1StatItem.param1.id}>
<Cell
teamStatItem={team1StatItem}
teamId={profile.team1.id}
firstClickableParam={firstClickableParam}
/>
<CellContainer>
<StatItemTitle t={team1StatItem.lexic} />
</CellContainer>
<Cell
teamStatItem={team2StatItem}
teamId={profile.team2.id}
firstClickableParam={firstClickableParam}
/>
</Row>
)
})}
</tbody>
</Table>
</TableWrapper>
</Container>
) )
} }

@ -1,90 +0,0 @@
import map from 'lodash/map'
import { MatchInfo, Param } from 'requests'
import {
CellContainer,
Container,
Header,
Row,
StatItemTitle,
Table,
TableWrapper,
TeamShortName,
} from 'features/MatchSidePlaylists/components/TeamsStatsTable/styled'
import { Cell } from 'features/MatchSidePlaylists/components/TeamsStatsTable/Cell'
import { TeamsStats } from 'features/MatchPage/store/hooks/useTeamsStats'
import { getStatItemById } from '../helpers'
type StatsTableProps = {
firstClickableParam?: Param | null,
isOpen?: boolean,
profile: MatchInfo,
teamsStats: TeamsStats,
}
export const StatsTable = ({
firstClickableParam = null,
isOpen = false,
profile,
teamsStats,
}: StatsTableProps) => {
if (!profile) return null
return (
<Container>
<TableWrapper isOpenTour={Boolean(isOpen)}>
<Table role='marquee' aria-live='off'>
<Header>
<Row>
<CellContainer as='th'>
<TeamShortName
nameObj={profile.team1}
prefix='abbrev_'
/>
</CellContainer>
<CellContainer as='th' />
<CellContainer as='th'>
<TeamShortName
nameObj={profile.team2}
prefix='abbrev_'
/>
</CellContainer>
</Row>
</Header>
<tbody>
{map(teamsStats[profile.team1.id], (team1StatItem) => {
const team2StatItem = getStatItemById({
matchProfile: profile,
paramId: team1StatItem.param1.id,
stats: teamsStats,
})
return (
<Row key={team1StatItem.param1.id}>
<Cell
teamStatItem={team1StatItem}
teamId={profile.team1.id}
firstClickableParam={firstClickableParam}
/>
<CellContainer>
<StatItemTitle t={team1StatItem.lexic} />
</CellContainer>
<Cell
teamStatItem={team2StatItem}
teamId={profile.team2.id}
firstClickableParam={firstClickableParam}
/>
</Row>
)
})}
</tbody>
</Table>
</TableWrapper>
</Container>
)
}

@ -1,16 +0,0 @@
import { TeamStatItem } from 'requests'
import { StatsLexicType } from './getStatsLexic'
type StatsItemType = StatsLexicType & {
paramId: number,
}
export const getStatItemById = ({
matchProfile,
paramId,
stats,
}: StatsItemType) => {
if (!matchProfile) return null
return stats[matchProfile?.team2.id]
.find(({ param1 }: TeamStatItem) => param1.id === paramId) || null
}

@ -1,22 +0,0 @@
import reduce from 'lodash/reduce'
import { MatchInfo, TeamStatItem } from 'requests'
import { TeamsStats } from 'features/MatchPage/store/hooks/useTeamsStats'
export type StatsLexicType = {
matchProfile: MatchInfo,
stats: TeamsStats,
}
export const getStatsLexics = ({ matchProfile, stats }: StatsLexicType) => (
matchProfile
? reduce<TeamStatItem, Array<number>>(
stats[matchProfile.team1.id],
(acc, curr) => {
!acc.includes(curr.lexic) && acc.push(curr.lexic)
!acc.includes(curr.param1.lexic) && acc.push(curr.param1.lexic)
curr.param2 && !acc.includes(curr.param2.lexic) && acc.push(curr.param2.lexic)
return acc
},
[],
)
: [])

@ -1,2 +0,0 @@
export * from './getStatsLexic'
export * from './getStatsItem'

@ -1,78 +0,0 @@
import {
useEffect,
useMemo,
useState,
} from 'react'
import {
getMatchInfo,
getTeamsStats,
MatchInfo,
} from 'requests'
import { useInterval, usePageParams } from 'hooks'
import { TeamsStats } from 'features/MatchPage/store/hooks/useTeamsStats'
import { useLexicsConfig } from 'features/LexicsStore'
import { getStatsLexics } from 'pages/StatsView/helpers'
const INTERVAL_FETCH_STATS = 30 * 1000
export const useStatsView = () => {
const [matchProfile, setMatchProfile] = useState<MatchInfo>(null)
const [stats, setStats] = useState<TeamsStats>({})
const {
profileId,
sportName,
sportType,
} = usePageParams()
const fetchMatchInfo = async () => {
if (!sportName || !profileId) return
const profile = await getMatchInfo(sportType, profileId)
setMatchProfile(profile)
}
const fetchStats = async () => {
if (!sportName || !profileId) return
const statistic = await getTeamsStats({
matchId: profileId,
sportName,
})
setStats(statistic)
}
const statsLexicIds = useMemo(
() => getStatsLexics({ matchProfile, stats }),
[matchProfile, stats],
)
useLexicsConfig(statsLexicIds)
const { start, stop } = useInterval({
callback: fetchStats,
intervalDuration: INTERVAL_FETCH_STATS,
startImmediate: true,
})
useEffect(() => {
if (!sportName || !profileId) return undefined
start()
fetchMatchInfo()
return () => stop()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
profileId,
sportName,
])
return {
matchProfile,
teamsStats: stats,
}
}

@ -1,35 +0,0 @@
import { Logo } from 'features/Logo'
import { T9n } from 'features/T9n'
import { useStatsView } from './hooks'
import { StatsTable } from './components/StatsTable'
import { Powered, Container } from './styled'
const StatsView = () => {
const { matchProfile, teamsStats } = useStatsView()
return (
<Container>
<header className='header__logo'>
<Logo />
</header>
<main>
{matchProfile?.team1 && matchProfile?.team2 && (
<StatsTable
profile={matchProfile}
teamsStats={teamsStats}
/>
)}
</main>
<footer className='footer__powered'>
<a target='_blank' href='https://india.insports.tv' rel='noreferrer'>
<Powered>
<T9n t='powered_by' />
</Powered>
</a>
</footer>
</Container>
)
}
export default StatsView

@ -1,25 +0,0 @@
import styled from 'styled-components/macro'
export const Powered = styled.span`
display: block;
text-decoration: none;
font-size: 12px;
line-height: 20px;
text-align: center;
letter-spacing: -0.32px;
color: #76ADFF;
`
export const Container = styled.div`
display: flex;
flex-direction: column;
gap: 15px;
padding: 25px 5px 15px 5px;
.header__logo{
display: flex;
justify-content: center;
}
`

@ -25,13 +25,13 @@ export type TeamStatItem = {
} }
type Response = { type Response = {
data?: TeamsType, data?: {
[teamId: string]: Array<TeamStatItem>,
},
error?: string, error?: string,
message?: string, message?: string,
} }
export type TeamsType = Record<string, Array<TeamStatItem>>
type GetTeamsStatsArgs = { type GetTeamsStatsArgs = {
matchId: number, matchId: number,
period?: number, period?: number,

Loading…
Cancel
Save