mirror of
https://gitlab.com/wheres-the-tp/ui-mobile.git
synced 2026-01-25 04:34:55 -06:00
39 lines
962 B
JavaScript
39 lines
962 B
JavaScript
// @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
|
|
}
|
|
}
|
|
});
|