Skip to content

Commit

Permalink
Merge pull request #30 from sarthakpranesh/dev
Browse files Browse the repository at this point in the history
Fixed cross origin request error
  • Loading branch information
sarthakpranesh authored Oct 19, 2021
2 parents 9ea9c28 + 444820a commit f58cc83
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 71 deletions.
2 changes: 1 addition & 1 deletion App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const MainApp = () => {

return (
<View onLayout={onLayout} style={{ flex: 1 }}>
<StatusBar style="auto" />
<StatusBar style="auto" hidden />
<RootNavigator />
</View>
);
Expand Down
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"expo": {
"name": "Covid19",
"slug": "Covid19",
"version": "4.0.0",
"version": "4.0.1",
"orientation": "portrait",
"icon": "./assets/icon.png",
"splash": {
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"package": {
"productName": "Covid19",
"version": "4.0.0"
"version": "4.0.1"
},
"build": {
"distDir": "../web-build",
Expand Down
63 changes: 63 additions & 0 deletions src/services/API/DiseaseApi.ts → src/services/API/Disease.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import axios from "axios";

export type GlobalCases = {
confirmed: number;
deaths: number;
recovered: number;
deathsToday: number;
newConfirmed: number;
totalSerious: number;
};

export type CountryCases = GlobalCases;

export type TimelineData = {
date: string;
active: number;
Expand All @@ -15,6 +26,58 @@ export type CasesTimeline = {
recovered: any;
};

export const fetchGlobalData: () => Promise<GlobalCases> = () => {
return new Promise((resolve, reject) => {
axios
.get("https://disease.sh/v3/covid-19/all")
.then((response) => {
if (response.data.cases) {
const results: GlobalCases = {
confirmed: response.data.cases,
deaths: response.data.deaths,
recovered: response.data.recovered,
deathsToday: response.data.todayDeaths,
newConfirmed: response.data.todayCases,
totalSerious: response.data.critical,
};
return resolve(results);
}
reject(new Error("Ninja API returned no data"));
})
.catch((err) => {
console.log("Ninja API error (Global): ", err.message);
reject(err.message);
});
});
};

export const fetchCountryData: (country: string) => Promise<CountryCases> = (
country
) => {
return new Promise((resolve, reject) => {
axios
.get(`https://disease.sh/v3/covid-19/countries/${country}?strict=true`)
.then((response) => {
if (response.data.cases) {
const results: CountryCases = {
confirmed: response.data.cases,
deaths: response.data.deaths,
recovered: response.data.recovered,
deathsToday: response.data.todayDeaths,
newConfirmed: response.data.todayCases,
totalSerious: response.data.critical,
};
return resolve(results);
}
reject(new Error("Ninja API returned no data!"));
})
.catch((err) => {
console.log("Ninja API error (Country): ", err.message);
reject(err.message);
});
});
};

// get cases timeline
const getCasesTimeline = (country: string): Promise<CasesTimeline> => {
return new Promise((resolve, reject) => {
Expand Down
66 changes: 0 additions & 66 deletions src/services/API/NinjaApi.ts

This file was deleted.

5 changes: 3 additions & 2 deletions src/services/API/functions/getCovidData.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { fetchTimelineData, TimelineData } from "../DiseaseApi";
import {
fetchTimelineData,
TimelineData,
fetchGlobalData,
fetchCountryData,
GlobalCases,
CountryCases,
} from "../NinjaApi";
} from "../Disease";

export type HomeScreenData = {
global: GlobalCases;
Expand Down

0 comments on commit f58cc83

Please sign in to comment.