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

Bookmarks view with grid + redux actions

This commit is contained in:
unknown 2021-05-23 18:38:39 +02:00
parent 27250dc850
commit e22e5afcb9
20 changed files with 297 additions and 19 deletions

View file

@ -4,7 +4,8 @@ import {
PinAppAction,
AddAppAction,
DeleteAppAction,
UpdateAppAction
UpdateAppAction,
GetCategoriesAction
} from './';
export enum ActionTypes {
@ -16,7 +17,10 @@ export enum ActionTypes {
addApp = 'ADD_APP',
addAppSuccess = 'ADD_APP_SUCCESS',
deleteApp = 'DELETE_APP',
updateApp = 'UPDATE_APP'
updateApp = 'UPDATE_APP',
getCategories = 'GET_CATEGORIES',
getCategoriesSuccess = 'GET_CATEGORIES_SUCCESS',
getCategoriesError = 'GET_CATEGORIES_ERROR'
}
export type Action = GetAppsAction<any> | SetThemeAction | PinAppAction | AddAppAction | DeleteAppAction | UpdateAppAction;
export type Action = GetAppsAction<any> | SetThemeAction | PinAppAction | AddAppAction | DeleteAppAction | UpdateAppAction | GetCategoriesAction<any>;

View file

@ -0,0 +1,27 @@
import axios from 'axios';
import { Dispatch } from 'redux';
import { ActionTypes } from './actionTypes';
import { Category, ApiResponse } from '../../interfaces';
export interface GetCategoriesAction<T> {
type: ActionTypes.getCategories | ActionTypes.getCategoriesSuccess | ActionTypes.getCategoriesError;
payload: T;
}
export const getCategories = () => async (dispatch: Dispatch) => {
dispatch<GetCategoriesAction<undefined>>({
type: ActionTypes.getCategories,
payload: undefined
})
try {
const res = await axios.get<ApiResponse<Category[]>>('/api/categories');
dispatch<GetCategoriesAction<Category[]>>({
type: ActionTypes.getCategoriesSuccess,
payload: res.data.data
})
} catch (err) {
console.log(err);
}
}

View file

@ -1,3 +1,4 @@
export * from './theme';
export * from './app';
export * from './actionTypes';
export * from './actionTypes';
export * from './bookmark';

View file

@ -4,7 +4,7 @@ import { App } from '../../interfaces/App';
export interface State {
loading: boolean;
apps: App[];
errors: '' | undefined;
errors: string | undefined;
}
const initialState: State = {

View file

@ -0,0 +1,40 @@
import { ActionTypes, Action } from '../actions';
import { Category, Bookmark } from '../../interfaces';
export interface State {
loading: boolean;
errors: string | undefined;
categories: Category[];
}
const initialState: State = {
loading: true,
errors: undefined,
categories: []
}
const getCategories = (state: State, action: Action): State => {
return {
...state,
loading: true,
errors: undefined
}
}
const getCategoriesSuccess = (state: State, action: Action): State => {
return {
...state,
loading: false,
categories: action.payload
}
}
const bookmarkReducer = (state = initialState, action: Action) => {
switch (action.type) {
case ActionTypes.getCategories: return getCategories(state, action);
case ActionTypes.getCategoriesSuccess: return getCategoriesSuccess(state, action);
default: return state;
}
}
export default bookmarkReducer;

View file

@ -4,10 +4,12 @@ import { GlobalState } from '../../interfaces/GlobalState';
import themeReducer from './theme';
import appReducer from './app';
import bookmarkReducer from './bookmark';
const rootReducer = combineReducers<GlobalState>({
theme: themeReducer,
app: appReducer
app: appReducer,
bookmark: bookmarkReducer
})
export default rootReducer;