feat: added primaryColor to the redux store
parent
7e29e18a56
commit
e14f4832aa
@ -0,0 +1,34 @@
|
||||
import { PrimaryColorStateType } from '../../themes/colors';
|
||||
|
||||
export const APPLY_PRIMARY_COLOR = 'APPLY_PRIMARY_COLOR';
|
||||
|
||||
export const applyPrimaryColor = (color: PrimaryColorStateType) => {
|
||||
return {
|
||||
type: APPLY_PRIMARY_COLOR,
|
||||
payload: color,
|
||||
};
|
||||
};
|
||||
|
||||
export const initialPrimaryColorState: PrimaryColorStateType = 'green';
|
||||
|
||||
export const reducer = (
|
||||
state: any = initialPrimaryColorState,
|
||||
{
|
||||
type,
|
||||
payload,
|
||||
}: {
|
||||
type: string;
|
||||
payload: PrimaryColorStateType;
|
||||
}
|
||||
): PrimaryColorStateType => {
|
||||
switch (type) {
|
||||
case APPLY_PRIMARY_COLOR:
|
||||
return payload;
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export const actions = {
|
||||
applyPrimaryColor,
|
||||
};
|
@ -0,0 +1,4 @@
|
||||
import { PrimaryColorStateType } from '../../themes/colors';
|
||||
import { StateType } from '../reducer';
|
||||
|
||||
export const getPrimaryColor = (state: StateType): PrimaryColorStateType => state.primaryColor;
|
@ -1,9 +0,0 @@
|
||||
import { COLORS, PrimaryColorStateType } from './colors';
|
||||
|
||||
export function switchPrimaryColor(color: PrimaryColorStateType) {
|
||||
document.documentElement.style.setProperty(
|
||||
'--primary-color',
|
||||
(COLORS.PRIMARY as any)[`${color.toUpperCase()}`]
|
||||
);
|
||||
// TODO Store in Database
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
import { Dispatch } from 'redux';
|
||||
import { applyPrimaryColor } from '../state/ducks/primaryColor';
|
||||
import { COLORS, PrimaryColorStateType } from './colors';
|
||||
|
||||
export function switchPrimaryColor(color: PrimaryColorStateType, dispatch: Dispatch | null) {
|
||||
document.documentElement.style.setProperty(
|
||||
'--primary-color',
|
||||
(COLORS.PRIMARY as any)[`${color.toUpperCase()}`]
|
||||
);
|
||||
dispatch?.(applyPrimaryColor(color));
|
||||
}
|
Loading…
Reference in New Issue