44 lines
936 B
JavaScript
44 lines
936 B
JavaScript
const setMinPrice = ({type, action}, component) => {
|
|
component.setState({
|
|
filters: {
|
|
minPrice: parseFloat(action.minPrice) || 0
|
|
}
|
|
})
|
|
}
|
|
|
|
const viewListingDetails= ({type, action}, component) => {
|
|
component.setState({
|
|
listingDetails: true,
|
|
listingId: action.id,
|
|
descriptionExpanded: false
|
|
})
|
|
}
|
|
|
|
const listingsLoaded = ({type, action}, component) => {
|
|
component.setState({
|
|
listings: action.listings
|
|
});
|
|
}
|
|
|
|
const expandDescription = ({type, action}, component) => {
|
|
component.setState({
|
|
descriptionExpanded: true
|
|
});
|
|
}
|
|
|
|
const handlers = {
|
|
'SET_MIN_PRICE': setMinPrice,
|
|
'LISTINGS_LOADED': listingsLoaded,
|
|
'EXPAND_DESCRIPTION': expandDescription,
|
|
'VIEW_LISTING_DETAILS': viewListingDetails
|
|
}
|
|
|
|
export const handleMessage = ({type, action}, component) => {
|
|
|
|
if (!handlers[type]) {
|
|
throw new `Unhandled message: ${type}`;
|
|
}
|
|
|
|
return handlers[type]({type, action}, component);
|
|
}
|