mirror of
https://gitlab.com/wheres-the-tp/ui-mobile.git
synced 2026-01-25 07:44:54 -06:00
51 lines
1.1 KiB
JavaScript
51 lines
1.1 KiB
JavaScript
//@flow
|
|
import { Set, Record } from 'immutable';
|
|
import { type RawFoodItem } from '../apis/FoodItemsApi';
|
|
import { type Category, CATEGORY_DESSERTS } from '../constants/CategoryConstants';
|
|
import { type Quantity, QUANTITY_MANY } from '../constants/QuantityConstants';
|
|
import ImageRecord from '../records/ImageRecord';
|
|
|
|
export type FoodItem = {
|
|
id: ?string,
|
|
name: string,
|
|
placeId: ?number,
|
|
latitude: number,
|
|
longitude: number,
|
|
distance: number,
|
|
quantity: Quantity,
|
|
category: Category,
|
|
images: Set<ImageRecord>,
|
|
thumbImage: ?string,
|
|
titleImage: ?string,
|
|
lastupdated: number,
|
|
};
|
|
|
|
const FoodRecordDefaults: FoodItem = {
|
|
id: '',
|
|
name: '',
|
|
placeId: null,
|
|
latitude: 0,
|
|
longitude: 0,
|
|
distance: 999,
|
|
quantity: QUANTITY_MANY,
|
|
category: CATEGORY_DESSERTS,
|
|
images: new Set(),
|
|
thumbImage: '',
|
|
titleImage: '',
|
|
lastupdated: 0,
|
|
};
|
|
|
|
const FoodItemRecord = Record(FoodRecordDefaults, 'FoodItemRecord');
|
|
|
|
export const createFoodItem = (foodItemRaw: ?RawFoodItem) => {
|
|
if (!foodItemRaw) {
|
|
return foodItemRaw;
|
|
}
|
|
return new FoodItemRecord({
|
|
...foodItemRaw,
|
|
placeId: foodItemRaw.placeid,
|
|
thumbImage: foodItemRaw.thumbimage,
|
|
});
|
|
};
|
|
|
|
export default FoodItemRecord;
|