mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-21 04:19:37 +02:00
WeatherIcon. Small changes to theme state
This commit is contained in:
parent
cb0b4b495f
commit
e293325da7
16 changed files with 137 additions and 32 deletions
5
client/package-lock.json
generated
5
client/package-lock.json
generated
|
@ -13766,6 +13766,11 @@
|
||||||
"resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz",
|
"resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz",
|
||||||
"integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg=="
|
"integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg=="
|
||||||
},
|
},
|
||||||
|
"skycons-ts": {
|
||||||
|
"version": "0.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/skycons-ts/-/skycons-ts-0.2.0.tgz",
|
||||||
|
"integrity": "sha512-GBn7Ox0dvZa9cin4NZIuBC4isdNYubSfJ+Rv0m5vkOQ8eBHPFApV98mbaAOseoKEBBjqsR1xDsY55rJ0HfwB6w=="
|
||||||
|
},
|
||||||
"slash": {
|
"slash": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz",
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
"redux": "^4.1.0",
|
"redux": "^4.1.0",
|
||||||
"redux-devtools-extension": "^2.13.9",
|
"redux-devtools-extension": "^2.13.9",
|
||||||
"redux-thunk": "^2.3.0",
|
"redux-thunk": "^2.3.0",
|
||||||
|
"skycons-ts": "^0.2.0",
|
||||||
"typescript": "^4.2.4",
|
"typescript": "^4.2.4",
|
||||||
"web-vitals": "^1.1.2"
|
"web-vitals": "^1.1.2"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
|
|
||||||
import classes from './AppCard.module.css';
|
import classes from './AppCard.module.css';
|
||||||
import Icon from '../../UI/Icon/Icon';
|
import Icon from '../../UI/Icons/Icon/Icon';
|
||||||
|
|
||||||
import { App } from '../../../interfaces';
|
import { App } from '../../../interfaces';
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { addApp } from '../../../store/actions';
|
||||||
import { NewApp } from '../../../interfaces/App';
|
import { NewApp } from '../../../interfaces/App';
|
||||||
|
|
||||||
import classes from './AppForm.module.css';
|
import classes from './AppForm.module.css';
|
||||||
import Icon from '../../UI/Icon/Icon';
|
import Icon from '../../UI/Icons/Icon/Icon';
|
||||||
|
|
||||||
interface ComponentProps {
|
interface ComponentProps {
|
||||||
modalHandler: Function;
|
modalHandler: Function;
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { App, GlobalState } from '../../../interfaces';
|
||||||
import { pinApp, deleteApp } from '../../../store/actions';
|
import { pinApp, deleteApp } from '../../../store/actions';
|
||||||
|
|
||||||
import classes from './AppTable.module.css';
|
import classes from './AppTable.module.css';
|
||||||
import Icon from '../../UI/Icon/Icon';
|
import Icon from '../../UI/Icons/Icon/Icon';
|
||||||
|
|
||||||
interface ComponentProps {
|
interface ComponentProps {
|
||||||
apps: App[];
|
apps: App[];
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
color: var(--color-primary);
|
color: var(--color-primary);
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
font-size: 4em;
|
font-size: 4em;
|
||||||
margin-bottom: 0.5em;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
|
|
||||||
.Header p {
|
.Header p {
|
||||||
|
@ -12,6 +12,36 @@
|
||||||
height: 30px;
|
height: 30px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.HeaderMain {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 2.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.WeatherWidget {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
.WeatherDetails {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
font-size: 16px;
|
||||||
|
color: var(--color-primary);
|
||||||
|
margin-left: 10px;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.WeatherDetails span:first-child {
|
||||||
|
border-bottom: 1px solid var(--color-primary);
|
||||||
|
padding-bottom: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.WeatherDetails span:last-child {
|
||||||
|
padding-top: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
.SettingsButton {
|
.SettingsButton {
|
||||||
width: 35px;
|
width: 35px;
|
||||||
height: 35px;
|
height: 35px;
|
||||||
|
|
|
@ -4,14 +4,12 @@ import { connect } from 'react-redux';
|
||||||
import { GlobalState } from '../../interfaces/GlobalState';
|
import { GlobalState } from '../../interfaces/GlobalState';
|
||||||
import { getApps } from '../../store/actions';
|
import { getApps } from '../../store/actions';
|
||||||
|
|
||||||
import Icon from '../UI/Icon/Icon';
|
import Icon from '../UI/Icons/Icon/Icon';
|
||||||
import Modal from '../UI/Modal/Modal';
|
import WeatherIcon from '../UI/Icons/WeatherIcon/WeatherIcon';
|
||||||
|
|
||||||
import classes from './Home.module.css';
|
import classes from './Home.module.css';
|
||||||
import { Container } from '../UI/Layout/Layout';
|
import { Container } from '../UI/Layout/Layout';
|
||||||
import Headline from '../UI/Headlines/Headline/Headline';
|
|
||||||
import SectionHeadline from '../UI/Headlines/SectionHeadline/SectionHeadline';
|
import SectionHeadline from '../UI/Headlines/SectionHeadline/SectionHeadline';
|
||||||
import Apps from '../Apps/Apps';
|
|
||||||
import AppGrid from '../Apps/AppGrid/AppGrid';
|
import AppGrid from '../Apps/AppGrid/AppGrid';
|
||||||
import { App } from '../../interfaces';
|
import { App } from '../../interfaces';
|
||||||
import Spinner from '../UI/Spinner/Spinner';
|
import Spinner from '../UI/Spinner/Spinner';
|
||||||
|
@ -63,7 +61,18 @@ const Home = (props: ComponentProps): JSX.Element => {
|
||||||
<Container>
|
<Container>
|
||||||
<header className={classes.Header}>
|
<header className={classes.Header}>
|
||||||
<p>{dateAndTime()}</p>
|
<p>{dateAndTime()}</p>
|
||||||
<h1>{greeter()}</h1>
|
<span className={classes.HeaderMain}>
|
||||||
|
<h1>{greeter()}</h1>
|
||||||
|
<div className={classes.WeatherWidget}>
|
||||||
|
<div className={classes.WeatherIcon}>
|
||||||
|
<WeatherIcon icon='clear-day' />
|
||||||
|
</div>
|
||||||
|
<div className={classes.WeatherDetails}>
|
||||||
|
<span>30°C</span>
|
||||||
|
<span>15°C</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</span>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<SectionHeadline title='Apps' link='/apps' />
|
<SectionHeadline title='Apps' link='/apps' />
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { Fragment } from 'react';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
|
|
||||||
import classes from './ActionButton.module.css';
|
import classes from './ActionButton.module.css';
|
||||||
import Icon from '../../Icon/Icon';
|
import Icon from '../../Icons/Icon/Icon';
|
||||||
|
|
||||||
interface ComponentProps {
|
interface ComponentProps {
|
||||||
name: string;
|
name: string;
|
||||||
|
@ -24,11 +24,32 @@ const ActionButton = (props: ComponentProps): JSX.Element => {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (props.link) {
|
if (props.link) {
|
||||||
return (<Link to={props.link}>{body}</Link>)
|
return (
|
||||||
|
<Link
|
||||||
|
to={props.link}
|
||||||
|
tabIndex={0}>
|
||||||
|
{body}
|
||||||
|
</Link>
|
||||||
|
)
|
||||||
} else if (props.handler) {
|
} else if (props.handler) {
|
||||||
return (<div className={classes.ActionButton} onClick={props.handler}>{body}</div>)
|
return (
|
||||||
|
<div
|
||||||
|
className={classes.ActionButton}
|
||||||
|
onClick={props.handler}
|
||||||
|
onKeyPress={(e) => {
|
||||||
|
if (e.key === 'Enter' && props.handler) props.handler()
|
||||||
|
}}
|
||||||
|
tabIndex={0}
|
||||||
|
>{body}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
return (<div className={classes.ActionButton}>{body}</div>)
|
return (
|
||||||
|
<div
|
||||||
|
className={classes.ActionButton}>
|
||||||
|
{body}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
.Icon {
|
|
||||||
color: var(--color-primary);
|
|
||||||
width: 90%;
|
|
||||||
}
|
|
6
client/src/components/UI/Icons/Icon/Icon.module.css
Normal file
6
client/src/components/UI/Icons/Icon/Icon.module.css
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
.Icon {
|
||||||
|
color: var(--color-primary);
|
||||||
|
/* for settings */
|
||||||
|
/* color: var(--color-background); */
|
||||||
|
width: 90%;
|
||||||
|
}
|
34
client/src/components/UI/Icons/WeatherIcon/WeatherIcon.tsx
Normal file
34
client/src/components/UI/Icons/WeatherIcon/WeatherIcon.tsx
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
import { useEffect } from 'react';
|
||||||
|
import { connect } from 'react-redux';
|
||||||
|
import { IconKey, Skycons } from 'skycons-ts';
|
||||||
|
import { GlobalState, Theme } from '../../../../interfaces';
|
||||||
|
|
||||||
|
interface ComponentProps {
|
||||||
|
theme: Theme;
|
||||||
|
icon: IconKey
|
||||||
|
}
|
||||||
|
|
||||||
|
const WeatherIcon = (props: ComponentProps): JSX.Element => {
|
||||||
|
const randomId = `icon-${Math.floor(Math.random() * 1000)}`;
|
||||||
|
useEffect(() => {
|
||||||
|
const delay = setTimeout(() => {
|
||||||
|
const skycons = new Skycons({'color': props.theme.colors.accent});
|
||||||
|
skycons.add(`weather-icon-${randomId}`, props.icon);
|
||||||
|
skycons.play();
|
||||||
|
}, 1);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
clearTimeout(delay);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return <canvas id={`weather-icon-${randomId}`} width='50' height='50'></canvas>
|
||||||
|
}
|
||||||
|
|
||||||
|
const mapStateToProps = (state: GlobalState) => {
|
||||||
|
return {
|
||||||
|
theme: state.theme.theme
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default connect(mapStateToProps)(WeatherIcon);
|
|
@ -1,5 +1,4 @@
|
||||||
import classes from './Modal.module.css';
|
import classes from './Modal.module.css';
|
||||||
import Icon from '../Icon/Icon';
|
|
||||||
|
|
||||||
interface ComponentProps {
|
interface ComponentProps {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import {
|
import {
|
||||||
GetAppsAction,
|
GetAppsAction,
|
||||||
SetTheme,
|
SetThemeAction,
|
||||||
PinAppAction,
|
PinAppAction,
|
||||||
AddAppAction,
|
AddAppAction,
|
||||||
DeleteAppAction
|
DeleteAppAction
|
||||||
|
@ -17,4 +17,4 @@ export enum ActionTypes {
|
||||||
deleteApp = 'DELETE_APP'
|
deleteApp = 'DELETE_APP'
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Action = GetAppsAction<any> | SetTheme | PinAppAction | AddAppAction | DeleteAppAction;
|
export type Action = GetAppsAction<any> | SetThemeAction | PinAppAction | AddAppAction | DeleteAppAction;
|
|
@ -3,9 +3,9 @@ import { themes } from '../../components/Themer/themes.json';
|
||||||
import { Theme } from '../../interfaces/Theme';
|
import { Theme } from '../../interfaces/Theme';
|
||||||
import { ActionTypes } from './actionTypes';
|
import { ActionTypes } from './actionTypes';
|
||||||
|
|
||||||
export interface SetTheme {
|
export interface SetThemeAction {
|
||||||
type: ActionTypes.setTheme,
|
type: ActionTypes.setTheme,
|
||||||
payload: string
|
payload: Theme
|
||||||
}
|
}
|
||||||
|
|
||||||
export const setTheme = (themeName: string) => (dispatch: Dispatch) => {
|
export const setTheme = (themeName: string) => (dispatch: Dispatch) => {
|
||||||
|
@ -15,14 +15,14 @@ export const setTheme = (themeName: string) => (dispatch: Dispatch) => {
|
||||||
localStorage.setItem('theme', themeName);
|
localStorage.setItem('theme', themeName);
|
||||||
loadTheme(theme);
|
loadTheme(theme);
|
||||||
|
|
||||||
dispatch<SetTheme>({
|
dispatch<SetThemeAction>({
|
||||||
type: ActionTypes.setTheme,
|
type: ActionTypes.setTheme,
|
||||||
payload: themeName
|
payload: theme
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const loadTheme = (theme: Theme) => {
|
export const loadTheme = (theme: Theme): void => {
|
||||||
for (const [key, value] of Object.entries(theme.colors)) {
|
for (const [key, value] of Object.entries(theme.colors)) {
|
||||||
document.body.style.setProperty(`--color-${key}`, value);
|
document.body.style.setProperty(`--color-${key}`, value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,24 @@
|
||||||
import { ActionTypes, Action } from '../actions';
|
import { ActionTypes, Action } from '../actions';
|
||||||
|
import { Theme } from '../../interfaces/Theme';
|
||||||
|
|
||||||
export interface State {
|
export interface State {
|
||||||
theme: string;
|
theme: Theme;
|
||||||
}
|
}
|
||||||
|
|
||||||
const initialState: State = {
|
const initialState: State = {
|
||||||
theme: 'blues'
|
theme: {
|
||||||
}
|
name: 'blues',
|
||||||
|
colors: {
|
||||||
const setTheme = (state: State, action: Action): State => {
|
background: '#2B2C56',
|
||||||
return { theme: action.payload };
|
primary: '#EFF1FC',
|
||||||
|
accent: '#6677EB'
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const themeReducer = (state = initialState, action: Action) => {
|
const themeReducer = (state = initialState, action: Action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case ActionTypes.setTheme: return setTheme(state, action);
|
case ActionTypes.setTheme: return { theme: action.payload };
|
||||||
default: return state;
|
default: return state;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue