This commit is contained in:
2019-07-24 00:53:01 -04:00
parent 434a1ded24
commit a9f4324f29
21 changed files with 345 additions and 100 deletions

15
app/actions/auction.js Normal file
View File

@@ -0,0 +1,15 @@
import {
SET_AUCTION_FILTER,
SET_AUCTION_VIEW_MODE,
} from '../constants/actionTypes.js';
export const changeFilterMode = (payload) => ({
type: SET_AUCTION_FILTER,
payload,
});
export const changeViewMode = (payload) => ({
type: SET_AUCTION_VIEW_MODE,
payload,
});

View File

@@ -0,0 +1,39 @@
import { List } from 'immutable';
import { getEndpointUrl } from '../api/index.js';
import {
AUCTIONS_UPDATED,
ITEMS_LOADED,
} from '../constants/actionTypes.js';
import { blockUI, unblockUI } from './index.js';
import { API_ENDPOINTS } from '../constants/constants.js';
import Auction from '../domain/Auction.js';
const autionStatusLoadSuccess = (auctions, dispatch) => {
const payload = List(auctions).map((i) => Auction.fromJS(i));
dispatch({ type: AUCTIONS_UPDATED, payload });
dispatch(unblockUI);
};
export const fetchAuctionStatus = () => (dispatch, getState) => {
const state = getState();
const activeEvent = state.get('activeEvent');
let apiUrl = getEndpointUrl(API_ENDPOINTS.GET_STATUS);
apiUrl = apiUrl.replace(/:event_id$/, '');
if (activeEvent) {
apiUrl = `${apiUrl}${activeEvent}`;
}
dispatch(blockUI());
return fetch(apiUrl)
.then(response => response.json())
.then(payload => autionStatusLoadSuccess(payload, dispatch))
.catch(err => console.error('[actions::getStatus]', err));
};

28
app/actions/events.js Normal file
View File

@@ -0,0 +1,28 @@
import { List } from 'immutable';
import { getEndpointUrl } from '../api/index.js';
import {
EVENTS_LOADED,
GET_EVENTS,
} from '../constants/actionTypes.js';
import { blockUI, unblockUI } from './index.js';
import { API_ENDPOINTS } from '../constants/constants.js';
import Event from '../domain/Event.js';
const eventsLoadSuccess = (events, dispatch) => {
const payload = List(events).map((i) => Event.fromJS(i));
dispatch({ type: EVENTS_LOADED, payload });
dispatch(unblockUI);
};
export const fetchEvents = () => (dispatch) => {
dispatch(blockUI());
fetch(getEndpointUr(API_ENDPOINTS.GET_EVENTS))
.then(response => response.json())
.then(payload => eventsLoadSuccess(payload, dispatch))
.catch(err => console.error('[actions::getEvents]', err));
};

View File

@@ -1,78 +1,8 @@
import { List } from 'immutable';
import { getEndpointUrl } from '../api/index.js';
import Auction from '../domain/Auction.js';
import Event from '../domain/Event.js';
import Item from '../domain/Item.js';
import {
AUCTIONS_UPDATED,
BLOCK_UI,
EVENTS_LOADED,
GET_EVENTS,
GET_ITEMS,
ITEMS_LOADED,
UNBLOCK_UI,
} from '../constants/actionTypes.js';
import { API_ENDPOINTS } from '../constants/constants.js';
export const getEvents = () => (dispatch) => {
dispatch(blockUI());
fetch(getEndpointUr(API_ENDPOINTS.GET_EVENTS))
.then(response => response.json())
.then((payload) => {
const events = List(payload).map((i) => Event.fromJS(i));
dispatch({ type: EVENTS_LOADED, payload: events });
dispatch(unblockUI);
});
};
export const getItems = () => (dispatch, getState) => {
const state = getState();
const activeEvent = state.get('activeEvent');
let apiUrl = getEndpointUrl(API_ENDPOINTS.GET_ITEMS);
apiUrl = apiUrl.replace(/:event_id$/, '');
if (activeEvent) {
apiUrl = `${apiUrl}${activeEvent}`;
}
dispatch(blockUI());
fetch(apiUrl)
.then(response => response.json())
.then(payload => {
const items = List(payload).map(i => Item.fromJS(i));
dispatch({ type: ITEMS_LOADED, payload: items });
dispatch(unblockUI());
})
.catch(err => console.error('[actions::getItems]', err));
};
export const getStatus = () => (dispatch, getState) => {
const state = getState();
const activeEvent = state.get('activeEvent');
let apiUrl = getEndpointUrl(API_ENDPOINTS.GET_STATUS);
apiUrl = apiUrl.replace(/:event_id$/, '');
if (activeEvent) {
apiUrl = `${apiUrl}${activeEvent}`;
}
dispatch(blockUI());
return fetch(apiUrl)
.then(response => response.json())
.then(payload => {
const auctions = List(payload).map(i => Auction.fromJS(i));
dispatch(unblockUI());
dispatch({ type: AUCTIONS_UPDATED, payload: auctions });
})
.catch(err => console.error('[actions::getStatus]', err));
};
export const blockUI = () => ({
type: BLOCK_UI,
});

38
app/actions/items.js Normal file
View File

@@ -0,0 +1,38 @@
import { List } from 'immutable';
import { getEndpointUrl } from '../api/index.js';
import {
GET_ITEMS,
ITEMS_LOADED,
} from '../constants/actionTypes.js';
import { blockUI, unblockUI } from './index.js';
import { API_ENDPOINTS } from '../constants/constants.js';
import Item from '../domain/Item.js';
const itemsLoadSuccess = (items, dispatch) => {
const payload = List(items).map((i) => Item.fromJS(i));
dispatch({ type: ITEMS_LOADED, payload });
dispatch(unblockUI);
};
export const fetchItems = () => (dispatch, getState) => {
const state = getState();
const activeEvent = state.get('activeEvent');
let apiUrl = getEndpointUrl(API_ENDPOINTS.GET_ITEMS);
apiUrl = apiUrl.replace(/:event_id$/, '');
if (activeEvent) {
apiUrl = `${apiUrl}${activeEvent}`;
}
dispatch(blockUI());
fetch(apiUrl)
.then(response => response.json())
.then(payload => itemsLoadSuccess(payload, dispatch))
.catch(err => console.error('[actions::getItems]', err));
};