Added humidity option to weather widget

This commit is contained in:
Paweł Malak 2021-11-18 15:14:53 +01:00
parent a549149452
commit 5cf7708ab8
11 changed files with 68 additions and 20 deletions

View file

@ -1,4 +1,5 @@
### v2.0.1 (TBA) ### v2.0.1 (TBA)
- Added option to display humidity in the weather widget ([#136](https://github.com/pawelmalak/flame/issues/136))
- Added option to set default theme for all new users ([#165](https://github.com/pawelmalak/flame/issues/165)) - Added option to set default theme for all new users ([#165](https://github.com/pawelmalak/flame/issues/165))
- Fixed bug with custom icons not working with apps when "pin by default" was disabled - Fixed bug with custom icons not working with apps when "pin by default" was disabled

View file

@ -11,7 +11,7 @@ import { State } from '../../../store/reducers';
import { ApiResponse, Weather, WeatherForm } from '../../../interfaces'; import { ApiResponse, Weather, WeatherForm } from '../../../interfaces';
// UI // UI
import { InputGroup, Button } from '../../UI'; import { InputGroup, Button, SettingsHeadline } from '../../UI';
// Utils // Utils
import { inputHandler, weatherSettingsTemplate } from '../../../utility'; import { inputHandler, weatherSettingsTemplate } from '../../../utility';
@ -84,6 +84,8 @@ export const WeatherSettings = (): JSX.Element => {
return ( return (
<form onSubmit={(e) => formSubmitHandler(e)}> <form onSubmit={(e) => formSubmitHandler(e)}>
<SettingsHeadline text="API" />
{/* API KEY */}
<InputGroup> <InputGroup>
<label htmlFor="WEATHER_API_KEY">API key</label> <label htmlFor="WEATHER_API_KEY">API key</label>
<input <input
@ -104,8 +106,10 @@ export const WeatherSettings = (): JSX.Element => {
</span> </span>
</InputGroup> </InputGroup>
<SettingsHeadline text="Location" />
{/* LAT */}
<InputGroup> <InputGroup>
<label htmlFor="lat">Location latitude</label> <label htmlFor="lat">Latitude</label>
<input <input
type="number" type="number"
id="lat" id="lat"
@ -128,8 +132,9 @@ export const WeatherSettings = (): JSX.Element => {
</span> </span>
</InputGroup> </InputGroup>
{/* LONG */}
<InputGroup> <InputGroup>
<label htmlFor="long">Location longitude</label> <label htmlFor="long">Longitude</label>
<input <input
type="number" type="number"
id="long" id="long"
@ -142,6 +147,8 @@ export const WeatherSettings = (): JSX.Element => {
/> />
</InputGroup> </InputGroup>
<SettingsHeadline text="Other" />
{/* TEMPERATURE */}
<InputGroup> <InputGroup>
<label htmlFor="isCelsius">Temperature unit</label> <label htmlFor="isCelsius">Temperature unit</label>
<select <select
@ -155,6 +162,20 @@ export const WeatherSettings = (): JSX.Element => {
</select> </select>
</InputGroup> </InputGroup>
{/* WEATHER DATA */}
<InputGroup>
<label htmlFor="weatherData">Additional weather data</label>
<select
id="weatherData"
name="weatherData"
value={formData.weatherData}
onChange={(e) => inputChangeHandler(e)}
>
<option value="cloud">Cloud coverage</option>
<option value="humidity">Humidity</option>
</select>
</InputGroup>
<Button>Save changes</Button> <Button>Save changes</Button>
</form> </form>
); );

View file

@ -13,22 +13,14 @@ import classes from './WeatherWidget.module.css';
// UI // UI
import { WeatherIcon } from '../../UI'; import { WeatherIcon } from '../../UI';
import { State } from '../../../store/reducers'; import { State } from '../../../store/reducers';
import { weatherTemplate } from '../../../utility/templateObjects/weatherTemplate';
export const WeatherWidget = (): JSX.Element => { export const WeatherWidget = (): JSX.Element => {
const { loading, config } = useSelector((state: State) => state.config); const { loading: configLoading, config } = useSelector(
(state: State) => state.config
);
const [weather, setWeather] = useState<Weather>({ const [weather, setWeather] = useState<Weather>(weatherTemplate);
externalLastUpdate: '',
tempC: 0,
tempF: 0,
isDay: 1,
cloud: 0,
conditionText: '',
conditionCode: 1000,
id: -1,
createdAt: new Date(),
updatedAt: new Date(),
});
const [isLoading, setIsLoading] = useState(true); const [isLoading, setIsLoading] = useState(true);
// Initial request to get data // Initial request to get data
@ -65,8 +57,7 @@ export const WeatherWidget = (): JSX.Element => {
return ( return (
<div className={classes.WeatherWidget}> <div className={classes.WeatherWidget}>
{isLoading || {configLoading ||
loading ||
(config.WEATHER_API_KEY && weather.id > 0 && ( (config.WEATHER_API_KEY && weather.id > 0 && (
<Fragment> <Fragment>
<div className={classes.WeatherIcon}> <div className={classes.WeatherIcon}>
@ -76,12 +67,15 @@ export const WeatherWidget = (): JSX.Element => {
/> />
</div> </div>
<div className={classes.WeatherDetails}> <div className={classes.WeatherDetails}>
{/* TEMPERATURE */}
{config.isCelsius ? ( {config.isCelsius ? (
<span>{weather.tempC}°C</span> <span>{weather.tempC}°C</span>
) : ( ) : (
<span>{weather.tempF}°F</span> <span>{weather.tempF}°F</span>
)} )}
<span>{weather.cloud}%</span>
{/* ADDITIONAL DATA */}
<span>{weather[config.weatherData]}%</span>
</div> </div>
</Fragment> </Fragment>
))} ))}

View file

@ -1,3 +1,5 @@
import { WeatherData } from '../types';
export interface Config { export interface Config {
WEATHER_API_KEY: string; WEATHER_API_KEY: string;
lat: number; lat: number;
@ -26,4 +28,6 @@ export interface Config {
monthSchema: string; monthSchema: string;
showTime: boolean; showTime: boolean;
defaultTheme: string; defaultTheme: string;
isKilometer: boolean;
weatherData: WeatherData;
} }

View file

@ -1,8 +1,11 @@
import { WeatherData } from '../types';
export interface WeatherForm { export interface WeatherForm {
WEATHER_API_KEY: string; WEATHER_API_KEY: string;
lat: number; lat: number;
long: number; long: number;
isCelsius: boolean; isCelsius: boolean;
weatherData: WeatherData;
} }
export interface SearchForm { export interface SearchForm {

View file

@ -8,4 +8,7 @@ export interface Weather extends Model {
cloud: number; cloud: number;
conditionText: string; conditionText: string;
conditionCode: number; conditionCode: number;
} humidity: number;
windK: number;
windM: number;
}

View file

@ -0,0 +1 @@
export type WeatherData = 'cloud' | 'humidity';

View file

@ -1 +1,2 @@
export * from './ConfigFormData'; export * from './ConfigFormData';
export * from './WeatherData';

View file

@ -29,4 +29,6 @@ export const configTemplate: Config = {
'January;February;March;April;May;June;July;August;September;October;November;December', 'January;February;March;April;May;June;July;August;September;October;November;December',
showTime: false, showTime: false,
defaultTheme: 'tron', defaultTheme: 'tron',
isKilometer: true,
weatherData: 'cloud',
}; };

View file

@ -29,6 +29,7 @@ export const weatherSettingsTemplate: WeatherForm = {
lat: 0, lat: 0,
long: 0, long: 0,
isCelsius: true, isCelsius: true,
weatherData: 'cloud',
}; };
export const searchSettingsTemplate: SearchForm = { export const searchSettingsTemplate: SearchForm = {

View file

@ -0,0 +1,17 @@
import { Weather } from '../../interfaces';
export const weatherTemplate: Weather = {
externalLastUpdate: '',
tempC: 0,
tempF: 0,
isDay: 1,
cloud: 0,
conditionText: '',
conditionCode: 1000,
id: -1,
createdAt: new Date(),
updatedAt: new Date(),
humidity: 0,
windK: 0,
windM: 0,
};