1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-08-07 03:35:18 +02:00

Sorting settings. Sort apps on change/add/update

This commit is contained in:
unknown 2021-06-18 10:38:05 +02:00
parent 8974fb3b49
commit 754dc3a7b9
9 changed files with 124 additions and 27 deletions

View file

@ -1,5 +1,6 @@
import { ActionTypes, Action } from '../actions';
import { App } from '../../interfaces/App';
import { sortData } from '../../utility';
export interface State {
loading: boolean;
@ -52,15 +53,9 @@ const pinApp = (state: State, action: Action): State => {
}
const addAppSuccess = (state: State, action: Action): State => {
const tmpApps: App[] = [...state.apps, action.payload].sort((a: App, b: App) => {
if (a.name.toLowerCase() < b.name.toLowerCase()) { return -1 }
if (a.name.toLowerCase() > b.name.toLowerCase()) { return 1 }
return 0;
});
return {
...state,
apps: tmpApps
apps: [...state.apps, action.payload]
}
}
@ -89,13 +84,22 @@ const updateApp = (state: State, action: Action): State => {
}
}
const reorderApp = (state: State, action: Action): State => {
const reorderApps = (state: State, action: Action): State => {
return {
...state,
apps: action.payload
}
}
const sortApps = (state: State, action: Action): State => {
const sortedApps = sortData<App>(state.apps, action.payload);
return {
...state,
apps: sortedApps
}
}
const appReducer = (state = initialState, action: Action) => {
switch (action.type) {
case ActionTypes.getApps: return getApps(state, action);
@ -105,7 +109,8 @@ const appReducer = (state = initialState, action: Action) => {
case ActionTypes.addAppSuccess: return addAppSuccess(state, action);
case ActionTypes.deleteApp: return deleteApp(state, action);
case ActionTypes.updateApp: return updateApp(state, action);
case ActionTypes.reorderApp: return reorderApp(state, action);
case ActionTypes.reorderApps: return reorderApps(state, action);
case ActionTypes.sortApps: return sortApps(state, action);
default: return state;
}
}