Skip to content
This repository has been archived by the owner on Nov 2, 2021. It is now read-only.

Commit

Permalink
Refactor: Move API URL to constants.js
Browse files Browse the repository at this point in the history
  • Loading branch information
shuklaayush committed Jul 6, 2020
1 parent a8f8360 commit 9c7c859
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 26 deletions.
7 changes: 3 additions & 4 deletions src/components/Home.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {API_ROOT_URL} from '../constants';
import useIsVisible from '../hooks/useIsVisible';
import useStickySWR from '../hooks/useStickySWR';
import {fetcher} from '../utils/commonFunctions';
Expand Down Expand Up @@ -33,7 +34,7 @@ function Home(props) {
const location = useLocation();

const {data: timeseries} = useStickySWR(
'https://api.covid19india.org/v4/min/timeseries.min.json',
`${API_ROOT_URL}/timeseries.min.json`,
fetcher,
{
revalidateOnMount: true,
Expand All @@ -42,9 +43,7 @@ function Home(props) {
);

const {data} = useStickySWR(
`https://api.covid19india.org/v4/min/data${
date ? `-${date}` : ''
}.min.json`,
`${API_ROOT_URL}/data${date ? `-${date}` : ''}.min.json`,
fetcher,
{
revalidateOnMount: true,
Expand Down
38 changes: 18 additions & 20 deletions src/components/State.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import MapSwitcher from './MapSwitcher';
import StateHeader from './StateHeader';
import StateMeta from './StateMeta';

import {STATE_NAMES} from '../constants';
import {API_ROOT_URL, STATE_NAMES} from '../constants';
import useIsVisible from '../hooks/useIsVisible';
import {fetcher, formatNumber, getStatistic} from '../utils/commonFunctions';

Expand Down Expand Up @@ -53,22 +53,18 @@ function State(props) {
}, [regionHighlighted.stateCode, stateCode]);

const {data: timeseries} = useSWR(
`https://api.covid19india.org/v4/min/timeseries-${stateCode}.min.json`,
`${API_ROOT_URL}/timeseries-${stateCode}.min.json`,
fetcher,
{
revalidateOnMount: true,
refreshInterval: 100000,
}
);

const {data} = useSWR(
'https://api.covid19india.org/v4/min/data.min.json',
fetcher,
{
revalidateOnMount: true,
refreshInterval: 100000,
}
);
const {data} = useSWR(`${API_ROOT_URL}/data.min.json`, fetcher, {
revalidateOnMount: true,
refreshInterval: 100000,
});

const toggleShowAllDistricts = () => {
setShowAllDistricts(!showAllDistricts);
Expand Down Expand Up @@ -138,16 +134,18 @@ function State(props) {
</div>

{data && (
<MapExplorer
{...{
stateCode,
data,
regionHighlighted,
setRegionHighlighted,
mapStatistic,
setMapStatistic,
}}
></MapExplorer>
<Suspense fallback={<div style={{minHeight: '50rem'}} />}>
<MapExplorer
{...{
stateCode,
data,
regionHighlighted,
setRegionHighlighted,
mapStatistic,
setMapStatistic,
}}
></MapExplorer>
</Suspense>
)}

<span ref={stateMetaElement} />
Expand Down
4 changes: 2 additions & 2 deletions src/components/Timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ const Timeline = ({setIsTimelineMode, setDate, dates}) => {
'2020-04-14': 'End of Lockdown Phase 1',
'2020-04-15': 'Beginning of Lockdown Phase 2',
'2020-05-03': 'End of Lockdown Phase 2',
'2020-04-04': 'Beginning of Lockdown Phase 3',
'2020-04-17': 'End of Lockdown Phase 3',
'2020-05-04': 'Beginning of Lockdown Phase 3',
'2020-05-17': 'End of Lockdown Phase 3',
'2020-05-18': 'Beginning of Lockdown Phase 4',
'2020-05-31': 'End of Lockdown Phase 4',
'2020-06-01': 'Beginning of Lockdown Phase 5',
Expand Down
2 changes: 2 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const API_ROOT_URL = 'https://api.covid19india.org/v4/min';

export const LOCALE_SHORTHANDS = {
english: 'en-US',
hindi: 'hi',
Expand Down

0 comments on commit 9c7c859

Please sign in to comment.