react-forecast-query
Advanced tools
Comparing version 0.1.1 to 0.2.0
@@ -10,7 +10,22 @@ /// <reference types="react" /> | ||
} | ||
export interface InjectedForecastProps { | ||
export interface InjectedForecastPropsCommon { | ||
/** | ||
* openweathermap api key | ||
*/ | ||
apiKey: string; | ||
/** | ||
* What kind of weather information do you want to see? | ||
*/ | ||
query: Array<keyof ForecastList>; | ||
/** | ||
* Do you own a pro account? | ||
*/ | ||
isPro?: boolean; | ||
/** | ||
* Should the query be listed by hour or by day | ||
*/ | ||
by?: 'day' | 'hour'; | ||
/** | ||
* Set up your forecast location and dates | ||
*/ | ||
setup?: (forecast: Forecast) => void; | ||
@@ -22,3 +37,14 @@ loadingComponent?: () => JSX.Element | null; | ||
} | ||
declare const weatherEnhancer: <T extends object>(Component: (new (props: T & ForecastResults) => JSX.Element | null) | ((props: T & ForecastResults) => JSX.Element | null), storage?: Storage, expire?: number | "never" | undefined) => (props: Pick<Pick<T, Exclude<keyof T, "data">>, Exclude<Exclude<keyof T, "data">, "forecast">> & InjectedForecastProps) => JSX.Element; | ||
interface InjectedForecastPropsGeo { | ||
geo: true; | ||
/** | ||
* Update periodically in minutes. This will be set up componentDidMount | ||
*/ | ||
updateGeo?: number; | ||
} | ||
interface InjectedForecastPropsNoGeo { | ||
geo?: false; | ||
} | ||
export declare type InjectedForecastProps = InjectedForecastPropsCommon & (InjectedForecastPropsGeo | InjectedForecastPropsNoGeo); | ||
declare const weatherEnhancer: <T extends object>(Component: (new (props: T & ForecastResults) => JSX.Element | null) | ((props: T & ForecastResults) => JSX.Element | null), storage?: Storage, expire?: number | "never" | undefined) => (props: (Pick<Pick<T, Exclude<keyof T, "data">>, Exclude<Exclude<keyof T, "data">, "forecast">> & InjectedForecastPropsCommon & InjectedForecastPropsGeo) | (Pick<Pick<T, Exclude<keyof T, "data">>, Exclude<Exclude<keyof T, "data">, "forecast">> & InjectedForecastPropsCommon & InjectedForecastPropsNoGeo)) => JSX.Element; | ||
export default weatherEnhancer; |
@@ -73,2 +73,3 @@ "use strict"; | ||
_this.state = { | ||
loadingGeo: false, | ||
loading: false, | ||
@@ -109,2 +110,5 @@ results: null, | ||
_a = this, props = _a.props, state = _a.state; | ||
if (state.loadingGeo) { | ||
return [2 /*return*/]; | ||
} | ||
this.setState({ loading: true, error: null }); | ||
@@ -165,2 +169,3 @@ acc = {}; | ||
var props; | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
@@ -173,5 +178,27 @@ switch (_a.label) { | ||
} | ||
return [4 /*yield*/, this.resolveQuery()]; | ||
if (!props.geo) return [3 /*break*/, 2]; | ||
this.setState({ loadingGeo: true }); | ||
return [4 /*yield*/, this.forecast.geo()]; | ||
case 1: | ||
_a.sent(); | ||
this.setState({ loadingGeo: false }); | ||
if (props.updateGeo) { | ||
this.geoInterval = window.setInterval(function () { return __awaiter(_this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
this.setState({ loadingGeo: true }); | ||
return [4 /*yield*/, this.forecast.geo()]; | ||
case 1: | ||
_a.sent(); | ||
this.setState({ loadingGeo: false }, this.resolveQuery); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }, 1000 * 60 * props.updateGeo); | ||
} | ||
_a.label = 2; | ||
case 2: return [4 /*yield*/, this.resolveQuery()]; | ||
case 3: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
@@ -182,2 +209,7 @@ } | ||
}; | ||
ForecastEnhancer.prototype.componentWillUnmount = function () { | ||
if (this.geoInterval !== undefined) { | ||
clearInterval(this.geoInterval); | ||
} | ||
}; | ||
ForecastEnhancer.prototype.componentDidUpdate = function (prevProps) { | ||
@@ -218,3 +250,3 @@ return __awaiter(this, void 0, void 0, function () { | ||
} | ||
if (state.loading) { | ||
if (state.loading || state.loadingGeo) { | ||
if (props.loadingComponent) { | ||
@@ -221,0 +253,0 @@ return props.loadingComponent(); |
{ | ||
"name": "react-forecast-query", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Higher order React component delivering weather information from open weather api. Wrapper for forecast-query package.", | ||
@@ -50,5 +50,5 @@ "main": "index.js", | ||
"dependencies": { | ||
"forecast-query": "^1.2.1" | ||
"forecast-query": "^1.3.1" | ||
}, | ||
"devDependencies": {} | ||
} |
@@ -88,2 +88,30 @@ # react-forecast-query | ||
## Changes since 0.2.0 | ||
Add support for gps geolocation in browser. | ||
### Example of use | ||
```JSX | ||
<WeatherDisplay | ||
apiKey={state.apiKey} | ||
label="Cloudy weather measurements" | ||
query={['clouds', 'cloudy']} | ||
by="hour" | ||
loadingComponent={() => <div>Loading...</div>} | ||
errorComponent={props => { | ||
console.error(props.error); | ||
return <div>Error!</div> | ||
}} | ||
geo // Try and get geolocation | ||
updateGeo={1} // Updates every minute | ||
setup={forecast => forecast | ||
.at(today, fourDaysFromNow) | ||
.units('metric') // No location setup needed | ||
.language('cz')} | ||
/> | ||
``` | ||
## More information | ||
@@ -90,0 +118,0 @@ |
19509
322
121
Updatedforecast-query@^1.3.1