mirror of
https://gitlab.com/wheres-the-tp/ui-mobile.git
synced 2026-01-25 09:54:55 -06:00
make POST requests to /quantity to update the quantity of an existing food item - then mixin the new quantity with the existing food items observable
20 lines
978 B
JavaScript
20 lines
978 B
JavaScript
//@flow
|
|
import FoodItemRecord, { createFoodItem } from '../records/FoodItemRecord';
|
|
import { setById } from '../helpers/ImmutableHelpers';
|
|
import { Map } from 'immutable';
|
|
import location$ from './LocationStream';
|
|
import { getFoodItems, type FoodItemsForLocation } from '../apis/FoodItemsApi';
|
|
import Filter$ from './FilterStream';
|
|
import FilterRecord from '../records/FilterRecord';
|
|
import Quantity$ from './QuantityStream';
|
|
import type { QuantityFragment } from '../constants/QuantityConstants';
|
|
|
|
export default location$
|
|
.combineLatest(Filter$)
|
|
.mergeMap(([loc, filter]: [Position, FilterRecord]) => getFoodItems({ loc, filter }))
|
|
.map(({ fooditems = [] }: FoodItemsForLocation) => {
|
|
return fooditems.map(createFoodItem).reduce(setById, new Map());
|
|
})
|
|
.combineLatest(Quantity$, (foodItems: Map<string, FoodItemRecord>, quantities: Map<string, QuantityFragment>) => {
|
|
return foodItems.mergeDeepWith((foodItem, quantity) => foodItem.merge(quantity), quantities);
|
|
});
|