mirror of
https://github.com/pawelmalak/flame.git
synced 2025-08-08 04:15:18 +02:00
Cleaned up Apps component. Delete App redux action. Apps edit mode with functionality do delete and pin apps
This commit is contained in:
parent
7e540587a5
commit
cb0b4b495f
10 changed files with 225 additions and 52 deletions
|
@ -2,7 +2,8 @@ import {
|
|||
GetAppsAction,
|
||||
SetTheme,
|
||||
PinAppAction,
|
||||
AddAppAction
|
||||
AddAppAction,
|
||||
DeleteAppAction
|
||||
} from './';
|
||||
|
||||
export enum ActionTypes {
|
||||
|
@ -12,7 +13,8 @@ export enum ActionTypes {
|
|||
getAppsError = 'GET_APPS_ERROR',
|
||||
pinApp = 'PIN_APP',
|
||||
addApp = 'ADD_APP',
|
||||
addAppSuccess = 'ADD_APP_SUCCESS'
|
||||
addAppSuccess = 'ADD_APP_SUCCESS',
|
||||
deleteApp = 'DELETE_APP'
|
||||
}
|
||||
|
||||
export type Action = GetAppsAction<any> | SetTheme | PinAppAction | AddAppAction;
|
||||
export type Action = GetAppsAction<any> | SetTheme | PinAppAction | AddAppAction | DeleteAppAction;
|
|
@ -63,4 +63,22 @@ export const addApp = (formData: NewApp) => async (dispatch: Dispatch) => {
|
|||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
}
|
||||
|
||||
export interface DeleteAppAction {
|
||||
type: ActionTypes.deleteApp,
|
||||
payload: number
|
||||
}
|
||||
|
||||
export const deleteApp = (id: number) => async (dispatch: Dispatch) => {
|
||||
try {
|
||||
const res = await axios.delete<AppResponse<{}>>(`/api/apps/${id}`);
|
||||
|
||||
dispatch<DeleteAppAction>({
|
||||
type: ActionTypes.deleteApp,
|
||||
payload: id
|
||||
})
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
}
|
|
@ -60,6 +60,15 @@ const addAppSuccess = (state: State, action: Action): State => {
|
|||
}
|
||||
}
|
||||
|
||||
const deleteApp = (state: State, action: Action): State => {
|
||||
const tmpApps = [...state.apps].filter((app: App) => app.id !== action.payload);
|
||||
|
||||
return {
|
||||
...state,
|
||||
apps: tmpApps
|
||||
}
|
||||
}
|
||||
|
||||
const appReducer = (state = initialState, action: Action) => {
|
||||
switch (action.type) {
|
||||
case ActionTypes.getApps: return getApps(state, action);
|
||||
|
@ -67,6 +76,7 @@ const appReducer = (state = initialState, action: 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);
|
||||
default: return state;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue