mirror of
https://github.com/pawelmalak/flame.git
synced 2026-03-12 07:04:45 +08:00
Pinned Apps
This commit is contained in:
@@ -1,13 +1,18 @@
|
||||
import {
|
||||
GetAppsAction,
|
||||
SetTheme
|
||||
SetTheme,
|
||||
PinAppAction,
|
||||
AddAppAction
|
||||
} from './';
|
||||
|
||||
export enum ActionTypes {
|
||||
setTheme,
|
||||
getApps,
|
||||
getAppsSuccess,
|
||||
getAppsError
|
||||
setTheme = 'SET_THEME',
|
||||
getApps = 'GET_APPS',
|
||||
getAppsSuccess = 'GET_APPS_SUCCESS',
|
||||
getAppsError = 'GET_APPS_ERROR',
|
||||
pinApp = 'PIN_APP',
|
||||
addApp = 'ADD_APP',
|
||||
addAppSuccess = 'ADD_APP_SUCCESS'
|
||||
}
|
||||
|
||||
export type Action = GetAppsAction<any> | SetTheme;
|
||||
export type Action = GetAppsAction<any> | SetTheme | PinAppAction | AddAppAction;
|
||||
@@ -1,11 +1,11 @@
|
||||
import axios from 'axios';
|
||||
import { Dispatch } from 'redux';
|
||||
import { ActionTypes } from './actionTypes';
|
||||
import { App, AppResponse } from '../../interfaces/App';
|
||||
import { App, AppResponse, NewApp } from '../../interfaces/App';
|
||||
|
||||
export interface GetAppsAction<T> {
|
||||
type: ActionTypes.getApps | ActionTypes.getAppsSuccess | ActionTypes.getAppsError,
|
||||
payload: T
|
||||
type: ActionTypes.getApps | ActionTypes.getAppsSuccess | ActionTypes.getAppsError;
|
||||
payload: T;
|
||||
}
|
||||
|
||||
export const getApps = () => async (dispatch: Dispatch) => {
|
||||
@@ -15,7 +15,7 @@ export const getApps = () => async (dispatch: Dispatch) => {
|
||||
});
|
||||
|
||||
try {
|
||||
const res = await axios.get<AppResponse>('/api/apps');
|
||||
const res = await axios.get<AppResponse<App[]>>('/api/apps');
|
||||
|
||||
dispatch<GetAppsAction<App[]>>({
|
||||
type: ActionTypes.getAppsSuccess,
|
||||
@@ -27,4 +27,40 @@ export const getApps = () => async (dispatch: Dispatch) => {
|
||||
payload: err.data.data
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export interface PinAppAction {
|
||||
type: ActionTypes.pinApp;
|
||||
payload: App;
|
||||
}
|
||||
|
||||
export const pinApp = (id: number, isPinned: boolean) => async (dispatch: Dispatch) => {
|
||||
try {
|
||||
const res = await axios.put<AppResponse<App>>(`/api/apps/${id}`, { isPinned: !isPinned });
|
||||
|
||||
dispatch<PinAppAction>({
|
||||
type: ActionTypes.pinApp,
|
||||
payload: res.data.data
|
||||
})
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
}
|
||||
|
||||
export interface AddAppAction {
|
||||
type: ActionTypes.addAppSuccess;
|
||||
payload: App;
|
||||
}
|
||||
|
||||
export const addApp = (formData: NewApp) => async (dispatch: Dispatch) => {
|
||||
try {
|
||||
const res = await axios.post<AppResponse<App>>('/api/apps', formData);
|
||||
|
||||
dispatch<AddAppAction>({
|
||||
type: ActionTypes.addAppSuccess,
|
||||
payload: res.data.data
|
||||
})
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user