Components: refactored UI components to use new state. Minor changes to exports and props

This commit is contained in:
Paweł Malak
2021-11-09 13:46:07 +01:00
parent adc017c48d
commit 89d935e27f
16 changed files with 118 additions and 146 deletions

View File

@@ -1,6 +1,4 @@
.Icon {
color: var(--color-primary);
/* for settings */
/* color: var(--color-background); */
width: 90%;
}
}

View File

@@ -2,12 +2,12 @@ import classes from './Icon.module.css';
import { Icon as MDIcon } from '@mdi/react';
interface ComponentProps {
interface Props {
icon: string;
color?: string;
}
const Icon = (props: ComponentProps): JSX.Element => {
export const Icon = (props: Props): JSX.Element => {
const MDIcons = require('@mdi/js');
let iconPath = MDIcons[props.icon];
@@ -22,7 +22,5 @@ const Icon = (props: ComponentProps): JSX.Element => {
path={iconPath}
color={props.color ? props.color : 'var(--color-primary)'}
/>
)
}
export default Icon;
);
};

View File

@@ -1,39 +1,32 @@
import { useEffect } from 'react';
import { connect } from 'react-redux';
import { useSelector } from 'react-redux';
import { Skycons } from 'skycons-ts';
import { GlobalState, Theme } from '../../../../interfaces';
import { State } from '../../../../store/reducers';
import { IconMapping, TimeOfDay } from './IconMapping';
interface ComponentProps {
theme: Theme;
interface Props {
weatherStatusCode: number;
isDay: number;
}
const WeatherIcon = (props: ComponentProps): JSX.Element => {
export const WeatherIcon = (props: Props): JSX.Element => {
const { theme } = useSelector((state: State) => state.theme);
const icon = props.isDay
? new IconMapping().mapIcon(props.weatherStatusCode, TimeOfDay.day)
: new IconMapping().mapIcon(props.weatherStatusCode, TimeOfDay.night);
useEffect(() => {
const delay = setTimeout(() => {
const skycons = new Skycons({'color': props.theme.colors.accent});
const skycons = new Skycons({ color: theme.colors.accent });
skycons.add(`weather-icon`, icon);
skycons.play();
}, 1);
return () => {
clearTimeout(delay);
}
}, [props.weatherStatusCode, icon, props.theme.colors.accent]);
};
}, [props.weatherStatusCode, icon, theme.colors.accent]);
return <canvas id={`weather-icon`} width='50' height='50'></canvas>
}
const mapStateToProps = (state: GlobalState) => {
return {
theme: state.theme.theme
}
}
export default connect(mapStateToProps)(WeatherIcon);
return <canvas id={`weather-icon`} width="50" height="50"></canvas>;
};