// @flow import { withProps } from "recompose"; import { emit } from "../streams/ImagesStream"; import { addImage, getImages } from "../apis/ImagesApi"; import AuthManager from "../AuthManager"; import { map } from "ramda"; export const withImages = withProps({ addImage: async ({ foodItemId, imageUri }) => { try { if (!AuthManager.user) { throw new Error("You need to be logged in to add images"); } const username = AuthManager.user.name; const { url, date } = await addImage({ foodItemId, username, imageUri }); emit({ url, username, date, food_item_id: foodItemId }); } catch (error) { // TODO error handling in the UI console.error(error); // eslint-disable-line } }, getImages: async ({ foodItemId }) => { try { const images = await getImages(foodItemId); map(emit, images); } catch (error) { // TODO error handling in the UI console.error(error); // eslint-disable-line } } });