utils#API_BASEURL TypeScript Examples
The following examples show how to use
utils#API_BASEURL.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.tsx From covid19-visualized with MIT License | 6 votes |
Summary: FunctionComponent = () => {
const { data, loading } = useFetch<SummaryType>(API_BASEURL)()
return (
<>
<div className="text-center my-12">
<h1 className="my-2">Summary</h1>
<h6>Last updatated at: {!loading ? dateFormat(data.lastUpdate, true) : 'Loading...'}</h6>
</div>
<div className="divider-line" />
<SummaryComponent
loading={loading}
data={{
confirmed: data?.confirmed.value,
recovered: data?.recovered.value,
deaths: data?.deaths.value
}}
/>
</>
)
}
Example #2
Source File: index.tsx From covid19-visualized with MIT License | 6 votes |
Daily: FunctionComponent = () => {
const { data, loading } = useFetch<DailyType[]>(API_BASEURL + 'daily')(
data => data
.map((item, index) => {
item.confirmed.perDay = getPerDayStats({ data, index, stats: 'confirmed' })
item.recovered.perDay = getPerDayStats({ data, index, stats: 'recovered' })
item.deaths.perDay = getPerDayStats({ data, index, stats: 'deaths' })
return item
})
.sort(({ reportDate: prev }, { reportDate: next }) => (
new Date(next).getTime() - new Date(prev).getTime()
))
)
return (
<ScrollableList<DailyType> title="Daily Update" data={data} loading={loading}>
{daily => (
<Card
className="text-center"
header={<h5 className="text-center">{dateFormat(daily.reportDate)}</h5>}
footer={
<>
<h3>Total</h3>
<div className="divider-line mt-2 mb-4" style={{ width: '30%' }} />
<p>Confirmed: <span className="font is-weight-bold color is-txt-warning">{daily.confirmed.total}</span></p>
{/* <p>Recovered: <span className="font is-weight-bold color is-txt-success">{daily.recovered.total} ({getPercentage(daily.recovered.total, daily.confirmed.total)})</span></p> */}
<p>Deaths: <span className="font is-weight-bold color is-txt-danger">{daily.deaths.total} ({getPercentage(daily.deaths.total, daily.confirmed.total)})</span></p>
</>
}
>
<p>Confirmed: <span className="font is-weight-bold color is-txt-warning">{daily.confirmed.perDay}</span></p>
{/* <p>Recovered: <span className="font is-weight-bold color is-txt-success">{daily.recovered.perDay}</span></p> */}
<p>Deaths: <span className="font is-weight-bold color is-txt-danger">{daily.deaths.perDay}</span></p>
</Card>
)}
</ScrollableList>
)
}
Example #3
Source File: index.tsx From covid19-visualized with MIT License | 6 votes |
Page: NextPage = () => {
const { data } = useFetch<Country[]>(API_BASEURL + 'confirmed')()
return (
<>
<Summary />
<div className="btn-link mb-24">
<Link href="/region">
<Button block color="primary" text="See Country and Region Cases" />
</Link>
<Link href="/indonesia">
<Button className="mt-8" block color="danger" text="See Indonesia Cases" />
</Link>
</div>
<h2 className="text-center mt-32 mb-12">World Visualization</h2>
<Visualization
id="world-visualization"
data={data}
visualize={visualize.world}
legends={worldLegends.map(({ color, value }) => (
<div key={color} className="legends-item font is-size-small">
<div className="legends-detail">{value === 0 ? `No case infected` : `${value} or more cases infected`}</div>
<div className="legends-color mx-4" style={{ backgroundColor: color }} />
</div>
))}
/>
<Daily />
</>
)
}
Example #4
Source File: region.tsx From covid19-visualized with MIT License | 5 votes |
Page: NextPage = () => {
const countries = useFetch<Country[]>(API_BASEURL + 'confirmed')(
data => (
data.sort(({ countryRegion: prev }, { countryRegion: next }) => (next > prev) ? -1 : 1)
)
)
return (
<>
<Head>
<title>Country and Region | COVID-19 Visualized</title>
{meta}
</Head>
<div className="text-center my-12">
<h1 className="my-2">Country and Region</h1>
</div>
<div className="divider-line mb-32" />
<div className="btn-link mb-24">
<Link href="/">
<Button block color="secondary" text="< Back to Home" />
</Link>
</div>
<DataSearch<Country>
data={countries.data}
loading={countries.loading}
searchPlaceholder="Search country state or province... (eg: indonesia)"
searchFilter={(keyword, item) => {
const region = item.countryRegion.toLowerCase()
const province = item.provinceState?.toLowerCase()
return region.includes(keyword) || (province ? province.includes(keyword) : false)
}}
>
{(data, keyword) => data.length
? (
<FlexList<Country> data={data} wrapperClass="my-12" itemClass="my-12">
{country => (
<Region
chart={{
confirmed: country.confirmed,
recovered: country.recovered,
deaths: country.deaths
}}
header={
country.provinceState
? `${country.provinceState}, ${country.countryRegion}`
: country.countryRegion
}
footer={`Last updated at: ${dateFormat(country.lastUpdate, true)}`}
>
<p>Total Confirmed: <span className="font is-weight-bold color is-txt-warning">{country.confirmed}</span></p>
<p className="mt-8">Active: <span className="font is-weight-bold color is-txt-warning">{getActiveCase(country)}</span></p>
<p>Recovered: <span className="font is-weight-bold color is-txt-success">{country.recovered}</span></p>
<p>Deaths: <span className="font is-weight-bold color is-txt-danger">{country.deaths}</span></p>
</Region>
)}
</FlexList>
) : (
<h3 className="text-center my-24">{
keyword.length
? `No matching country or province "${keyword}" found.`
: 'Please type the name of the country that you want to search.'
}</h3>
)
}
</DataSearch>
</>
)
}