fix(ott-2416): fix fetch matches in mobile version

keep-around/b5fe367a4f0f5018a86ec3e4283c874fb11ccfa9
nevainero 4 years ago
parent 88b683eb07
commit b5fe367a4f
  1. 5
      src/features/Matches/hooks.tsx
  2. 31
      src/features/Matches/index.tsx

@ -11,6 +11,7 @@ import type { MatchesBySection } from 'requests'
import { useRequest } from 'hooks' import { useRequest } from 'hooks'
import { usePreferencesStore } from 'features/PreferencesPopup' import { usePreferencesStore } from 'features/PreferencesPopup'
import { isMobileDevice } from 'config/userAgent'
import { prepareMatches } from './helpers/prepareMatches' import { prepareMatches } from './helpers/prepareMatches'
@ -20,7 +21,7 @@ export type Props = {
fetch: (limit: number, offset: number) => Promise<MatchesBySection>, fetch: (limit: number, offset: number) => Promise<MatchesBySection>,
} }
const MATCHES_LIMIT = 60 const MATCHES_LIMIT = isMobileDevice ? 1000 : 60
const initialState = { const initialState = {
broadcast: [], broadcast: [],
@ -78,7 +79,7 @@ export const useMatches = ({ fetch }: Props) => {
}), [matches]) }), [matches])
return { return {
fetchMoreMatches, fetchMoreMatches: isMobileDevice ? fetchMoreMatches : () => {},
isFetching, isFetching,
matches: preparedMatches, matches: preparedMatches,
} }

@ -1,7 +1,9 @@
import { Fragment } from 'react' import { Fragment, useMemo } from 'react'
import { T9n } from 'features/T9n' import { T9n } from 'features/T9n'
import { InfiniteScroll } from 'features/InfiniteScroll' import { InfiniteScroll } from 'features/InfiniteScroll'
import { Loader } from 'features/Loader'
import { isMobileDevice } from 'config/userAgent'
import type { Props } from './hooks' import type { Props } from './hooks'
import { useMatches } from './hooks' import { useMatches } from './hooks'
@ -22,6 +24,27 @@ export const Matches = (props: Props) => {
}, },
} = useMatches(props) } = useMatches(props)
const mobileView = useMemo(() => (
isFetching ? (
<Loader color='white' />
) : (
<MatchesList
as='grid'
matches={broadcast}
/>
)
), [isFetching, broadcast])
const desktopView = useMemo(() => (
<>
<MatchesList
as='grid'
matches={broadcast}
/>
{isFetching && <Loading><T9n t='loading' />...</Loading>}
</>
), [isFetching, broadcast])
if (isVideoSections) { if (isVideoSections) {
return ( return (
<Fragment> <Fragment>
@ -46,11 +69,7 @@ export const Matches = (props: Props) => {
return ( return (
<InfiniteScroll fullPageScroll onFetchMore={fetchMoreMatches}> <InfiniteScroll fullPageScroll onFetchMore={fetchMoreMatches}>
<MatchesList {isMobileDevice ? mobileView : desktopView}
as='grid'
matches={broadcast}
/>
{isFetching && <Loading><T9n t='loading' />...</Loading>}
</InfiniteScroll> </InfiniteScroll>
) )
} }

Loading…
Cancel
Save