adds integrations with bookish-server, the books API and the google books API, adds functionality for library, searching for books, and displaying renters registered in the system
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
import { actionTypes } from '../constants/books/action_types';
|
||||
import { mergeDeepRight } from 'ramda';
|
||||
|
||||
import { Action } from '../types/actions';
|
||||
|
||||
const initialState = {
|
||||
books: [],
|
||||
filter: '',
|
||||
images: {},
|
||||
cart: [],
|
||||
loading: false,
|
||||
loadError: null,
|
||||
checkoutError: null,
|
||||
returnError: null
|
||||
}
|
||||
|
||||
export function books(state = initialState, action: Action) {
|
||||
switch (action.type) {
|
||||
// FETCH_BOOK actions
|
||||
case actionTypes.FETCH_BOOKS.request:
|
||||
return {
|
||||
...state,
|
||||
loading: true
|
||||
}
|
||||
case actionTypes.FETCH_BOOKS.success:
|
||||
return {
|
||||
...state,
|
||||
loading: false,
|
||||
loadError: null,
|
||||
books: [...action.data]
|
||||
}
|
||||
case actionTypes.FETCH_BOOKS.failure:
|
||||
return {
|
||||
...state,
|
||||
loading: false,
|
||||
error: action.err
|
||||
}
|
||||
|
||||
// FETCH_COVER_IMAGE actions
|
||||
case actionTypes.FETCH_COVER_IMAGE.request:
|
||||
return {
|
||||
...state,
|
||||
loading: true
|
||||
}
|
||||
case actionTypes.FETCH_COVER_IMAGE.success:
|
||||
interface ImageReturn {
|
||||
title: string;
|
||||
imageLink: string;
|
||||
}
|
||||
|
||||
let imageReturn: ImageReturn = {...action.data as ImageReturn};
|
||||
|
||||
const images = {...state.images}
|
||||
|
||||
images[imageReturn.title] = imageReturn.imageLink;
|
||||
|
||||
return mergeDeepRight(state, {
|
||||
loading: false,
|
||||
images: {...images}
|
||||
})
|
||||
case actionTypes.FETCH_COVER_IMAGE.failure:
|
||||
return {
|
||||
...state,
|
||||
loading: false
|
||||
}
|
||||
|
||||
// SET_FILTER action
|
||||
case actionTypes.SET_FILTER:
|
||||
return {
|
||||
...state,
|
||||
filter: action.data
|
||||
}
|
||||
|
||||
// ADD_TO_CART action
|
||||
case actionTypes.ADD_TO_CART:
|
||||
return {
|
||||
...state,
|
||||
cart: state.cart.concat(action.data)
|
||||
}
|
||||
|
||||
// CHECKOUT_BOOK action
|
||||
case actionTypes.CHECKOUT_BOOK.request:
|
||||
return {
|
||||
...state,
|
||||
loading: true
|
||||
}
|
||||
case actionTypes.CHECKOUT_BOOK.success:
|
||||
return {
|
||||
...state,
|
||||
loading: false,
|
||||
checkoutError: null
|
||||
}
|
||||
case actionTypes.CHECKOUT_BOOK.failure:
|
||||
return {
|
||||
...state,
|
||||
loading: false,
|
||||
checkoutError: action.err
|
||||
}
|
||||
|
||||
// RETURN_BOOK action
|
||||
case actionTypes.RETURN_BOOK.request:
|
||||
return {
|
||||
...state,
|
||||
loading: true
|
||||
}
|
||||
case actionTypes.RETURN_BOOK.success:
|
||||
return {
|
||||
...state,
|
||||
loading: false,
|
||||
returnError: false
|
||||
}
|
||||
case actionTypes.RETURN_BOOK.failure:
|
||||
return {
|
||||
...state,
|
||||
loading: false,
|
||||
returnError: action.err
|
||||
}
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { combineReducers } from 'redux';
|
||||
|
||||
import { books } from './books';
|
||||
import { renters } from './renters';
|
||||
|
||||
export const RootReducer = combineReducers({
|
||||
books,
|
||||
renters
|
||||
})
|
||||
@@ -0,0 +1,56 @@
|
||||
import { actionTypes } from '../constants/renters/action_types';
|
||||
|
||||
import { Action } from '../types/actions';
|
||||
|
||||
const initialState = {
|
||||
renters: [],
|
||||
loading: false,
|
||||
loadError: null,
|
||||
registerError: null,
|
||||
}
|
||||
|
||||
export function renters(state = initialState, action: Action) {
|
||||
switch(action.type) {
|
||||
// FETCH_RENTERS action
|
||||
case actionTypes.FETCH_RENTERS.request:
|
||||
return {
|
||||
...state,
|
||||
loading: true
|
||||
}
|
||||
case actionTypes.FETCH_RENTERS.success:
|
||||
return {
|
||||
...state,
|
||||
loading: false,
|
||||
loadError: null,
|
||||
renters: [...action.data]
|
||||
}
|
||||
case actionTypes.FETCH_RENTERS.failure:
|
||||
return {
|
||||
...state,
|
||||
loading: false,
|
||||
loadError: action.err
|
||||
}
|
||||
|
||||
// REGISTER_RENTER action
|
||||
case actionTypes.REGISTER_RENTER.request:
|
||||
return {
|
||||
...state,
|
||||
loading: true
|
||||
}
|
||||
case actionTypes.REGISTER_RENTER.success:
|
||||
return {
|
||||
...state,
|
||||
loading: false,
|
||||
registerError: null,
|
||||
}
|
||||
case actionTypes.REGISTER_RENTER.failure:
|
||||
return {
|
||||
...state,
|
||||
loading: false,
|
||||
registerError: action.err
|
||||
}
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { createStore, applyMiddleware } from 'redux';
|
||||
import { composeWithDevTools } from 'redux-devtools-extension';
|
||||
import thunk from 'redux-thunk';
|
||||
|
||||
import { RootReducer } from '../';
|
||||
|
||||
export const store = createStore(
|
||||
RootReducer,
|
||||
{},
|
||||
composeWithDevTools({})(
|
||||
applyMiddleware(thunk)
|
||||
)
|
||||
);
|
||||
Reference in New Issue
Block a user