diff --git a/src/App.tsx b/src/App.tsx index bb63ee8..62a4ca0 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react' +import React, {useContext, useState} from 'react' import './App.css' import { Avatar, @@ -20,6 +20,7 @@ import seriea from './resources/images/seriea.png' import ligue1 from './resources/images/ligue1.png' import europa from './resources/images/europa.png' import conference from './resources/images/conference.png' +import {PaginationContext, PaginationProvider} from "./contexts"; const LeagueOption: React.FC<{ image: string; name: string }> = ({ image, @@ -38,8 +39,7 @@ const LeagueOption: React.FC<{ image: string; name: string }> = ({ const App: React.FC = () => { const [date, setDate] = useState(dayjs()) const [league, setLeague] = useState('eng.1') - const [page, setPage] = useState(1) - const [total, setTotal] = useState(26) + const {state, actions} = useContext(PaginationContext); const leagueOptions = [ {label: 'Nation', options: [ { @@ -85,6 +85,7 @@ const App: React.FC = () => { setLeague(value) } return ( + @@ -114,9 +115,11 @@ const App: React.FC = () => { - + {actions.setCurrentPage(page)}}/> + ) } diff --git a/src/components/DashBoard.tsx b/src/components/DashBoard.tsx index 5f536b8..63dc9c2 100644 --- a/src/components/DashBoard.tsx +++ b/src/components/DashBoard.tsx @@ -1,7 +1,8 @@ import { useScoreBoardData } from '../hooks' import { Col, Space, Spin } from 'antd' -import React, { useEffect } from 'react' +import React, {useContext, useEffect} from 'react' import { showMessage, ScoreCard } from './' +import {PaginationContext} from "../contexts"; interface Props { date: string @@ -10,12 +11,21 @@ interface Props { export const DashBoard: React.FC = ({ date, league }) => { const { isLoading, error, data } = useScoreBoardData(date, league) + const {state, actions} = useContext(PaginationContext) + useEffect(() => { if (error) { + actions.setCurrentPage(1) + actions.setTotalCount(1) showMessage('error', 'An error has occurred while fetching data.') } if (data?.events.length === 0) { + actions.setCurrentPage(1) + actions.setTotalCount(1) showMessage('info', 'No game today!') + } else { + actions.setCurrentPage(1) + actions.setTotalCount(data?.events.length) } }, [data, error])