diff --git a/src/Components/MultiDayForecast/Component.tsx b/src/Components/MultiDayForecast/Component.tsx index 8088a07..060de7e 100644 --- a/src/Components/MultiDayForecast/Component.tsx +++ b/src/Components/MultiDayForecast/Component.tsx @@ -1,20 +1,16 @@ import * as React from 'react'; import '../../../node_modules/open-weather-icons/dist/css/open-weather-icons.css'; import './Component.css'; -import { Forecast5Days, ForecaseAtInstance } from '../WeatherApp'; + import { SingleDayForecast } from '../SingleDayForecast'; -import { Utils } from '../../Utils'; +import { Utils, Forecast5DaysMixed, Forecast5DaysSeperated } from '../../Utils'; export interface MultiDayForecastProps { - forecast5Days: Forecast5Days; + forecast5DaysMixed: Forecast5DaysMixed; } export interface MultiDayForecastState { - forecastDay1: Array; - forecastDay2: Array; - forecastDay3: Array; - forecastDay4: Array; - forecastDay5: Array; + forecast5DaysSeperated: Forecast5DaysSeperated; } export class MultiDayForecast extends React.Component { @@ -33,32 +29,46 @@ export class MultiDayForecast extends React.Component { + props.forecast5DaysMixed.list.forEach((forecastAtInstanceValue) => { const forecastDay = Utils.createDateFromEpochInIndiaTZ(forecastAtInstanceValue.dt); if (Utils.checkSameDayInSameTZ(forecastDay, day1)) { - tempState.forecastDay1.push(forecastAtInstanceValue); + + forecast5DaysSeperated.forecastDay1.push(forecastAtInstanceValue); + } else if (Utils.checkSameDayInSameTZ(forecastDay, day2)) { - tempState.forecastDay2.push(forecastAtInstanceValue); + + forecast5DaysSeperated.forecastDay2.push(forecastAtInstanceValue); + } else if (Utils.checkSameDayInSameTZ(forecastDay, day3)) { - tempState.forecastDay3.push(forecastAtInstanceValue); + + forecast5DaysSeperated.forecastDay3.push(forecastAtInstanceValue); + } else if (Utils.checkSameDayInSameTZ(forecastDay, day4)) { - tempState.forecastDay4.push(forecastAtInstanceValue); + + forecast5DaysSeperated.forecastDay4.push(forecastAtInstanceValue); + } else if (Utils.checkSameDayInSameTZ(forecastDay, day5)) { - tempState.forecastDay5.push(forecastAtInstanceValue); + + forecast5DaysSeperated.forecastDay5.push(forecastAtInstanceValue); + } else { // Because it is rolling 5 days, last few times can fall into (today + 5) th day // Just skip those values @@ -70,13 +80,30 @@ export class MultiDayForecast extends React.Component - - - - - + + + + + ); } diff --git a/src/Components/SingleDayForecast/Component.tsx b/src/Components/SingleDayForecast/Component.tsx index 5d9d997..4f8d24d 100644 --- a/src/Components/SingleDayForecast/Component.tsx +++ b/src/Components/SingleDayForecast/Component.tsx @@ -1,9 +1,10 @@ import * as React from 'react'; import './Component.css'; -import { ForecaseAtInstance } from '../WeatherApp'; +import { Forecast5DaysSeperated, ForecaseAtInstance } from '../../Utils'; export interface SingleDayForecastProps { - forecastDay: Array; + forecastCurrentDay: Array; + forecast5DaysSeperated: Forecast5DaysSeperated; } export class SingleDayForecast extends React.Component { @@ -23,7 +24,12 @@ export class SingleDayForecast extends React.Component - {JSON.stringify(this.props)}; +
+ {JSON.stringify(this.calcSummary())}; +
+
+ BLANK +
); } diff --git a/src/Components/WeatherApp/App.tsx b/src/Components/WeatherApp/App.tsx index 903dc69..ad55ba6 100644 --- a/src/Components/WeatherApp/App.tsx +++ b/src/Components/WeatherApp/App.tsx @@ -2,47 +2,11 @@ import * as React from 'react'; // import * as moment from 'moment'; import '../../../node_modules/open-weather-icons/dist/css/open-weather-icons.css'; import './App.css'; +import { Forecast5DaysMixed } from '../../Utils'; import { MultiDayForecast } from '../MultiDayForecast'; -export interface ForecaseAtInstance { - dt: number; - main: { - temp: number; - temp_min: number; - temp_max: number; - pressure: number; - sea_level: number; - grnd_level: number; - humidity: number; - temp_kf: number; - }; - - weather: [{ - id: number; - main: string; // Make enum - description: string; - icon: string; - }]; - - clouds: { - all: number; - }; - - wind: { - speed: number; - deg: number; - }; - - dt_txt: string; -} - -export interface Forecast5Days { - cnt: number; - list: Array; -} - export interface WeatherDataState { - data: Forecast5Days | undefined; + data: Forecast5DaysMixed | undefined; } export class WeatherApp extends React.Component<{}, WeatherDataState> { @@ -59,7 +23,7 @@ export class WeatherApp extends React.Component<{}, WeatherDataState> { return response.json(); }) .then((responseObject) => { - this.setState({ data: responseObject as Forecast5Days }); + this.setState({ data: responseObject as Forecast5DaysMixed }); }); } @@ -67,8 +31,8 @@ export class WeatherApp extends React.Component<{}, WeatherDataState> { return 'Still Loading'; } - renderDates(forecast5Days: Forecast5Days): JSX.Element | string { - return ; + renderDates(forecast5DaysMixed: Forecast5DaysMixed): JSX.Element | string { + return ; } render() { diff --git a/src/Components/WeatherApp/index.tsx b/src/Components/WeatherApp/index.tsx index d7bd095..f435512 100644 --- a/src/Components/WeatherApp/index.tsx +++ b/src/Components/WeatherApp/index.tsx @@ -1 +1 @@ -export { WeatherApp, ForecaseAtInstance, Forecast5Days } from './App'; \ No newline at end of file +export { WeatherApp } from './App'; \ No newline at end of file diff --git a/src/Utils/index.ts b/src/Utils/index.ts index c3e1d0d..7fab552 100644 --- a/src/Utils/index.ts +++ b/src/Utils/index.ts @@ -1 +1 @@ -export { Utils, IndiaTZName } from './utils'; \ No newline at end of file +export { Utils, IndiaTZName, ForecaseAtInstance, Forecast5DaysMixed, Forecast5DaysSeperated } from './utils'; \ No newline at end of file diff --git a/src/Utils/utils.ts b/src/Utils/utils.ts index 18ece61..d09472c 100644 --- a/src/Utils/utils.ts +++ b/src/Utils/utils.ts @@ -20,4 +20,49 @@ export class Utils { // tslint:disable-next-line:triple-equals return (moment1.clone().startOf('day').format() == moment2.clone().startOf('day').format()); } +} + +export interface ForecaseAtInstance { + dt: number; + main: { + temp: number; + temp_min: number; + temp_max: number; + pressure: number; + sea_level: number; + grnd_level: number; + humidity: number; + temp_kf: number; + }; + + weather: [{ + id: number; + main: string; // Make enum + description: string; + icon: string; + }]; + + clouds: { + all: number; + }; + + wind: { + speed: number; + deg: number; + }; + + dt_txt: string; +} + +export interface Forecast5DaysMixed { + cnt: number; + list: Array; +} + +export interface Forecast5DaysSeperated { + forecastDay1: Array; + forecastDay2: Array; + forecastDay3: Array; + forecastDay4: Array; + forecastDay5: Array; } \ No newline at end of file