mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-18 19:19:36 +02:00
Fixed color of weather icon when changing theme
This commit is contained in:
parent
b8af178cbf
commit
378dd8e36d
5 changed files with 76 additions and 8 deletions
|
@ -10,7 +10,7 @@ interface Props {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const WeatherIcon = (props: Props): JSX.Element => {
|
export const WeatherIcon = (props: Props): JSX.Element => {
|
||||||
const { theme } = useSelector((state: State) => state.theme);
|
const { activeTheme } = useSelector((state: State) => state.theme);
|
||||||
|
|
||||||
const icon = props.isDay
|
const icon = props.isDay
|
||||||
? new IconMapping().mapIcon(props.weatherStatusCode, TimeOfDay.day)
|
? new IconMapping().mapIcon(props.weatherStatusCode, TimeOfDay.day)
|
||||||
|
@ -18,7 +18,7 @@ export const WeatherIcon = (props: Props): JSX.Element => {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const delay = setTimeout(() => {
|
const delay = setTimeout(() => {
|
||||||
const skycons = new Skycons({ color: theme.colors.accent });
|
const skycons = new Skycons({ color: activeTheme.colors.accent });
|
||||||
skycons.add(`weather-icon`, icon);
|
skycons.add(`weather-icon`, icon);
|
||||||
skycons.play();
|
skycons.play();
|
||||||
}, 1);
|
}, 1);
|
||||||
|
@ -26,7 +26,7 @@ export const WeatherIcon = (props: Props): JSX.Element => {
|
||||||
return () => {
|
return () => {
|
||||||
clearTimeout(delay);
|
clearTimeout(delay);
|
||||||
};
|
};
|
||||||
}, [props.weatherStatusCode, icon, theme.colors.accent]);
|
}, [props.weatherStatusCode, icon, activeTheme.colors.accent]);
|
||||||
|
|
||||||
return <canvas id={`weather-icon`} width="50" height="50"></canvas>;
|
return <canvas id={`weather-icon`} width="50" height="50"></canvas>;
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,7 +7,7 @@ import {
|
||||||
UpdateConfigAction,
|
UpdateConfigAction,
|
||||||
UpdateQueryAction,
|
UpdateQueryAction,
|
||||||
} from '../actions/config';
|
} from '../actions/config';
|
||||||
import axios from 'axios';
|
import axios, { AxiosError } from 'axios';
|
||||||
import { ApiResponse, Config, Query } from '../../interfaces';
|
import { ApiResponse, Config, Query } from '../../interfaces';
|
||||||
import { ActionType } from '../action-types';
|
import { ActionType } from '../action-types';
|
||||||
import { storeUIConfig, applyAuth } from '../../utility';
|
import { storeUIConfig, applyAuth } from '../../utility';
|
||||||
|
@ -103,7 +103,15 @@ export const addQuery =
|
||||||
payload: res.data.data,
|
payload: res.data.data,
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
const error = err as AxiosError<{ error: string }>;
|
||||||
|
|
||||||
|
dispatch<any>({
|
||||||
|
type: ActionType.createNotification,
|
||||||
|
payload: {
|
||||||
|
title: 'Error',
|
||||||
|
message: error.response?.data.error,
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,11 @@ export const setTheme =
|
||||||
for (const [key, value] of Object.entries(colors)) {
|
for (const [key, value] of Object.entries(colors)) {
|
||||||
document.body.style.setProperty(`--color-${key}`, value);
|
document.body.style.setProperty(`--color-${key}`, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dispatch({
|
||||||
|
type: ActionType.setTheme,
|
||||||
|
payload: colors,
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const fetchThemes =
|
export const fetchThemes =
|
||||||
|
@ -30,3 +35,33 @@ export const fetchThemes =
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// export const addTheme = () => async (dispatch: Dispatch<>) => {
|
||||||
|
// try {
|
||||||
|
// // const res = await axios.post<>('/api/themes')
|
||||||
|
// } catch (err) {}
|
||||||
|
// };
|
||||||
|
|
||||||
|
// export const addQuery =
|
||||||
|
// (query: Query) => async (dispatch: Dispatch<AddQueryAction>) => {
|
||||||
|
// try {
|
||||||
|
// const res = await axios.post<ApiResponse<Query>>('/api/queries', query, {
|
||||||
|
// headers: applyAuth(),
|
||||||
|
// });
|
||||||
|
|
||||||
|
// dispatch({
|
||||||
|
// type: ActionType.addQuery,
|
||||||
|
// payload: res.data.data,
|
||||||
|
// });
|
||||||
|
// } catch (err) {
|
||||||
|
// const error = err as AxiosError<{ error: string }>;
|
||||||
|
|
||||||
|
// dispatch<any>({
|
||||||
|
// type: ActionType.createNotification,
|
||||||
|
// payload: {
|
||||||
|
// title: 'Error',
|
||||||
|
// message: error.response?.data.error,
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import { ActionType } from '../action-types';
|
import { ActionType } from '../action-types';
|
||||||
import { Theme } from '../../interfaces';
|
import { Theme, ThemeColors } from '../../interfaces';
|
||||||
|
|
||||||
export interface SetThemeAction {
|
export interface SetThemeAction {
|
||||||
type: ActionType.setTheme;
|
type: ActionType.setTheme;
|
||||||
|
payload: ThemeColors;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FetchThemesAction {
|
export interface FetchThemesAction {
|
||||||
|
|
|
@ -1,14 +1,28 @@
|
||||||
import { Action } from '../actions';
|
import { Action } from '../actions';
|
||||||
import { ActionType } from '../action-types';
|
import { ActionType } from '../action-types';
|
||||||
import { Theme } from '../../interfaces/Theme';
|
import { Theme, ThemeColors } from '../../interfaces/Theme';
|
||||||
import { arrayPartition } from '../../utility';
|
import { arrayPartition, parsePABToTheme } from '../../utility';
|
||||||
|
|
||||||
interface ThemeState {
|
interface ThemeState {
|
||||||
|
activeTheme: Theme;
|
||||||
themes: Theme[];
|
themes: Theme[];
|
||||||
userThemes: Theme[];
|
userThemes: Theme[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const savedTheme: ThemeColors = parsePABToTheme(localStorage.theme) || {
|
||||||
|
primary: '#effbff',
|
||||||
|
accent: '#6ee2ff',
|
||||||
|
background: '#242b33',
|
||||||
|
};
|
||||||
|
|
||||||
const initialState: ThemeState = {
|
const initialState: ThemeState = {
|
||||||
|
activeTheme: {
|
||||||
|
name: 'main',
|
||||||
|
isCustom: false,
|
||||||
|
colors: {
|
||||||
|
...savedTheme,
|
||||||
|
},
|
||||||
|
},
|
||||||
themes: [],
|
themes: [],
|
||||||
userThemes: [],
|
userThemes: [],
|
||||||
};
|
};
|
||||||
|
@ -18,6 +32,16 @@ export const themeReducer = (
|
||||||
action: Action
|
action: Action
|
||||||
): ThemeState => {
|
): ThemeState => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
|
case ActionType.setTheme: {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
activeTheme: {
|
||||||
|
...state.activeTheme,
|
||||||
|
colors: action.payload,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
case ActionType.fetchThemes: {
|
case ActionType.fetchThemes: {
|
||||||
const [themes, userThemes] = arrayPartition<Theme>(
|
const [themes, userThemes] = arrayPartition<Theme>(
|
||||||
action.payload,
|
action.payload,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue