mirror of
https://github.com/pawelmalak/flame.git
synced 2026-02-28 09:23:12 +08:00
38 lines
725 B
TypeScript
38 lines
725 B
TypeScript
import { Action } from '../actions';
|
|
import { ActionType } from '../action-types';
|
|
import { Theme } from '../../interfaces/Theme';
|
|
import { arrayPartition } from '../../utility';
|
|
|
|
interface ThemeState {
|
|
themes: Theme[];
|
|
userThemes: Theme[];
|
|
}
|
|
|
|
const initialState: ThemeState = {
|
|
themes: [],
|
|
userThemes: [],
|
|
};
|
|
|
|
export const themeReducer = (
|
|
state: ThemeState = initialState,
|
|
action: Action
|
|
): ThemeState => {
|
|
switch (action.type) {
|
|
case ActionType.fetchThemes: {
|
|
const [themes, userThemes] = arrayPartition<Theme>(
|
|
action.payload,
|
|
(e) => !e.isCustom
|
|
);
|
|
|
|
return {
|
|
...state,
|
|
themes,
|
|
userThemes,
|
|
};
|
|
}
|
|
|
|
default:
|
|
return state;
|
|
}
|
|
};
|