mirror of
https://github.com/pawelmalak/flame.git
synced 2025-08-07 03:35:18 +02:00
Set app visibility
This commit is contained in:
parent
ee9aefa4fa
commit
d1738a0a3e
7 changed files with 127 additions and 105 deletions
|
@ -11,108 +11,115 @@ export interface State {
|
|||
const initialState: State = {
|
||||
loading: true,
|
||||
apps: [],
|
||||
errors: undefined
|
||||
}
|
||||
errors: undefined,
|
||||
};
|
||||
|
||||
const getApps = (state: State, action: Action): State => {
|
||||
return {
|
||||
...state,
|
||||
loading: true,
|
||||
errors: undefined
|
||||
}
|
||||
}
|
||||
errors: undefined,
|
||||
};
|
||||
};
|
||||
|
||||
const getAppsSuccess = (state: State, action: Action): State => {
|
||||
return {
|
||||
...state,
|
||||
loading: false,
|
||||
apps: action.payload
|
||||
}
|
||||
}
|
||||
apps: action.payload,
|
||||
};
|
||||
};
|
||||
|
||||
const getAppsError = (state: State, action: Action): State => {
|
||||
return {
|
||||
...state,
|
||||
loading: false,
|
||||
errors: action.payload
|
||||
}
|
||||
}
|
||||
errors: action.payload,
|
||||
};
|
||||
};
|
||||
|
||||
const pinApp = (state: State, action: Action): State => {
|
||||
const tmpApps = [...state.apps];
|
||||
const changedApp = tmpApps.find((app: App) => app.id === action.payload.id);
|
||||
|
||||
|
||||
if (changedApp) {
|
||||
changedApp.isPinned = action.payload.isPinned;
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
...state,
|
||||
apps: tmpApps
|
||||
}
|
||||
}
|
||||
apps: tmpApps,
|
||||
};
|
||||
};
|
||||
|
||||
const addAppSuccess = (state: State, action: Action): State => {
|
||||
return {
|
||||
...state,
|
||||
apps: [...state.apps, action.payload]
|
||||
}
|
||||
}
|
||||
apps: [...state.apps, action.payload],
|
||||
};
|
||||
};
|
||||
|
||||
const deleteApp = (state: State, action: Action): State => {
|
||||
const tmpApps = [...state.apps].filter((app: App) => app.id !== action.payload);
|
||||
|
||||
return {
|
||||
...state,
|
||||
apps: tmpApps
|
||||
}
|
||||
}
|
||||
apps: [...state.apps].filter((app: App) => app.id !== action.payload),
|
||||
};
|
||||
};
|
||||
|
||||
const updateApp = (state: State, action: Action): State => {
|
||||
const tmpApps = [...state.apps];
|
||||
const appInUpdate = tmpApps.find((app: App) => app.id === action.payload.id);
|
||||
|
||||
if (appInUpdate) {
|
||||
appInUpdate.name = action.payload.name;
|
||||
appInUpdate.url = action.payload.url;
|
||||
appInUpdate.icon = action.payload.icon;
|
||||
}
|
||||
const appIdx = state.apps.findIndex((app) => app.id === action.payload.id);
|
||||
|
||||
return {
|
||||
...state,
|
||||
apps: tmpApps
|
||||
}
|
||||
}
|
||||
apps: [
|
||||
...state.apps.slice(0, appIdx),
|
||||
{
|
||||
...action.payload,
|
||||
},
|
||||
...state.apps.slice(appIdx + 1),
|
||||
],
|
||||
};
|
||||
};
|
||||
|
||||
const reorderApps = (state: State, action: Action): State => {
|
||||
return {
|
||||
...state,
|
||||
apps: action.payload
|
||||
}
|
||||
}
|
||||
apps: action.payload,
|
||||
};
|
||||
};
|
||||
|
||||
const sortApps = (state: State, action: Action): State => {
|
||||
const sortedApps = sortData<App>(state.apps, action.payload);
|
||||
|
||||
return {
|
||||
...state,
|
||||
apps: sortedApps
|
||||
}
|
||||
}
|
||||
apps: sortedApps,
|
||||
};
|
||||
};
|
||||
|
||||
const appReducer = (state = initialState, action: Action) => {
|
||||
switch (action.type) {
|
||||
case ActionTypes.getApps: return getApps(state, action);
|
||||
case ActionTypes.getAppsSuccess: return getAppsSuccess(state, action);
|
||||
case ActionTypes.getAppsError: return getAppsError(state, action);
|
||||
case ActionTypes.pinApp: return pinApp(state, action);
|
||||
case ActionTypes.addAppSuccess: return addAppSuccess(state, action);
|
||||
case ActionTypes.deleteApp: return deleteApp(state, action);
|
||||
case ActionTypes.updateApp: return updateApp(state, action);
|
||||
case ActionTypes.reorderApps: return reorderApps(state, action);
|
||||
case ActionTypes.sortApps: return sortApps(state, action);
|
||||
default: return state;
|
||||
case ActionTypes.getApps:
|
||||
return getApps(state, action);
|
||||
case ActionTypes.getAppsSuccess:
|
||||
return getAppsSuccess(state, action);
|
||||
case ActionTypes.getAppsError:
|
||||
return getAppsError(state, action);
|
||||
case ActionTypes.pinApp:
|
||||
return pinApp(state, action);
|
||||
case ActionTypes.addAppSuccess:
|
||||
return addAppSuccess(state, action);
|
||||
case ActionTypes.deleteApp:
|
||||
return deleteApp(state, action);
|
||||
case ActionTypes.updateApp:
|
||||
return updateApp(state, action);
|
||||
case ActionTypes.reorderApps:
|
||||
return reorderApps(state, action);
|
||||
case ActionTypes.sortApps:
|
||||
return sortApps(state, action);
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default appReducer;
|
||||
export default appReducer;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue