From 6e56a02523fa13e63bf0cb42a9fc90ad4811a0b4 Mon Sep 17 00:00:00 2001 From: sarthakpranesh Date: Tue, 19 Oct 2021 12:06:14 +0530 Subject: [PATCH 1/2] Replacing the Ninja api with Disease api url, closes #29 Signed-off-by: sarthakpranesh --- App.tsx | 2 +- .../API/{DiseaseApi.ts => Disease.ts} | 63 ++++++++++++++++++ src/services/API/NinjaApi.ts | 66 ------------------- src/services/API/functions/getCovidData.ts | 5 +- 4 files changed, 67 insertions(+), 69 deletions(-) rename src/services/API/{DiseaseApi.ts => Disease.ts} (54%) delete mode 100644 src/services/API/NinjaApi.ts diff --git a/App.tsx b/App.tsx index 4ebdc6c..a59aea2 100644 --- a/App.tsx +++ b/App.tsx @@ -104,7 +104,7 @@ const MainApp = () => { return ( - + ); diff --git a/src/services/API/DiseaseApi.ts b/src/services/API/Disease.ts similarity index 54% rename from src/services/API/DiseaseApi.ts rename to src/services/API/Disease.ts index ae0e65d..5ce00e0 100644 --- a/src/services/API/DiseaseApi.ts +++ b/src/services/API/Disease.ts @@ -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; @@ -15,6 +26,58 @@ export type CasesTimeline = { recovered: any; }; +export const fetchGlobalData: () => Promise = () => { + 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 = ( + 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 => { return new Promise((resolve, reject) => { diff --git a/src/services/API/NinjaApi.ts b/src/services/API/NinjaApi.ts deleted file mode 100644 index 5f55bd9..0000000 --- a/src/services/API/NinjaApi.ts +++ /dev/null @@ -1,66 +0,0 @@ -import axios from "axios"; - -export interface GlobalCases { - confirmed: number; - deaths: number; - recovered: number; - deathsToday: number; - newConfirmed: number; - totalSerious: number; -} - -export const fetchGlobalData: () => Promise = () => { - return new Promise((resolve, reject) => { - axios - .get("https://corona.lmao.ninja/v2/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 interface CountryCases extends GlobalCases {} - -export const fetchCountryData: (country: string) => Promise = ( - country -) => { - return new Promise((resolve, reject) => { - axios - .get( - `https://corona.lmao.ninja/v2/countries/${country}?today&strict&query%20` - ) - .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); - }); - }); -}; diff --git a/src/services/API/functions/getCovidData.ts b/src/services/API/functions/getCovidData.ts index c156ab6..9237358 100644 --- a/src/services/API/functions/getCovidData.ts +++ b/src/services/API/functions/getCovidData.ts @@ -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; From 444820a6ff3bd9e7a67acd631c670d52067063f1 Mon Sep 17 00:00:00 2001 From: sarthakpranesh Date: Tue, 19 Oct 2021 12:19:01 +0530 Subject: [PATCH 2/2] Bumpping up app version Signed-off-by: sarthakpranesh --- app.json | 2 +- src-tauri/tauri.conf.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app.json b/app.json index 571c6b4..0992c21 100644 --- a/app.json +++ b/app.json @@ -2,7 +2,7 @@ "expo": { "name": "Covid19", "slug": "Covid19", - "version": "4.0.0", + "version": "4.0.1", "orientation": "portrait", "icon": "./assets/icon.png", "splash": { diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 9c07c67..df40898 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "package": { "productName": "Covid19", - "version": "4.0.0" + "version": "4.0.1" }, "build": { "distDir": "../web-build",