mirror of
https://gitlab.com/wheres-the-tp/ui-mobile.git
synced 2026-01-25 04:24:56 -06:00
fix search
This commit is contained in:
parent
8441321f94
commit
cdd3086edd
4 changed files with 38 additions and 32 deletions
|
|
@ -1,14 +1,14 @@
|
|||
// @flow
|
||||
import { memoizeWith, identity } from "ramda";
|
||||
import FilterRecord from "../records/FilterRecord";
|
||||
import FoodItemRecord from "../records/FoodItemRecord";
|
||||
import AuthManager from "../AuthManager";
|
||||
import { map, path, nth } from "ramda";
|
||||
import { addImage } from "./ImagesApi";
|
||||
import { fetchRequest } from "./FetchApi";
|
||||
import { memoizeWith, identity } from 'ramda';
|
||||
import FilterRecord from '../records/FilterRecord';
|
||||
import FoodItemRecord from '../records/FoodItemRecord';
|
||||
import AuthManager from '../AuthManager';
|
||||
import { map, path, nth } from 'ramda';
|
||||
import { addImage } from './ImagesApi';
|
||||
import { fetchRequest } from './FetchApi';
|
||||
|
||||
export type FoodItemsFilter = {
|
||||
radius?: number
|
||||
radius?: number,
|
||||
};
|
||||
|
||||
export type RawFoodItem = {
|
||||
|
|
@ -21,27 +21,33 @@ export type RawFoodItem = {
|
|||
latitude: number,
|
||||
longitude: number,
|
||||
distance: number,
|
||||
lastupdated: number
|
||||
lastupdated: number,
|
||||
};
|
||||
|
||||
export type FoodItemsForLocation = {
|
||||
orderby: string,
|
||||
filter: FoodItemsFilter,
|
||||
fooditems: ?Array<RawFoodItem>
|
||||
fooditems: ?Array<RawFoodItem>,
|
||||
};
|
||||
|
||||
export const getFoodItems = memoizeWith(
|
||||
identity,
|
||||
async ({ loc, filter }: { loc: Position, filter: FilterRecord }): Promise<FoodItemsForLocation> => {
|
||||
({ loc, filter }) => `${loc.coords.latitude + loc.coords.longitude}:${filter.toString()}`,
|
||||
async ({
|
||||
loc,
|
||||
filter,
|
||||
}: {
|
||||
loc: Position,
|
||||
filter: FilterRecord,
|
||||
}): Promise<FoodItemsForLocation> => {
|
||||
const {
|
||||
coords: { latitude: lat, longitude: lng }
|
||||
coords: { latitude: lat, longitude: lng },
|
||||
} = loc;
|
||||
const { orderby, categories, radius, search } = filter;
|
||||
|
||||
try {
|
||||
return fetchRequest({
|
||||
endpoint: "/fooditems",
|
||||
method: "POST",
|
||||
endpoint: '/fooditems',
|
||||
method: 'POST',
|
||||
body: {
|
||||
lat,
|
||||
lng,
|
||||
|
|
@ -49,22 +55,22 @@ export const getFoodItems = memoizeWith(
|
|||
filter: {
|
||||
...(categories ? { categories } : {}),
|
||||
radius,
|
||||
search
|
||||
}
|
||||
}
|
||||
}).then(json => ({
|
||||
search,
|
||||
},
|
||||
},
|
||||
}).then((json) => ({
|
||||
...json,
|
||||
loading: false,
|
||||
error: null
|
||||
error: null,
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error(error); // eslint-disable-line no-console
|
||||
return {
|
||||
orderby: "distance",
|
||||
orderby: 'distance',
|
||||
filter: {},
|
||||
fooditems: [],
|
||||
loading: false,
|
||||
error: error
|
||||
error: error,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -72,24 +78,24 @@ export const getFoodItems = memoizeWith(
|
|||
|
||||
export const createFoodItem = async (foodItem: FoodItemRecord) => {
|
||||
if (!AuthManager.user) {
|
||||
throw new Error("You must be logged in to create food items");
|
||||
throw new Error('You must be logged in to create food items');
|
||||
}
|
||||
|
||||
const username = AuthManager.user.name;
|
||||
|
||||
const res = await fetchRequest({
|
||||
endpoint: "/addfooditem",
|
||||
method: "POST",
|
||||
body: foodItem
|
||||
endpoint: '/addfooditem',
|
||||
method: 'POST',
|
||||
body: foodItem,
|
||||
});
|
||||
|
||||
const addImageUri = (imageUri: string) => addImage({ foodItemId: res.id, imageUri, username });
|
||||
|
||||
const images = map(path(["url"]), await Promise.all(map(addImageUri, foodItem.images.toArray())));
|
||||
const images = map(path(['url']), await Promise.all(map(addImageUri, foodItem.images.toArray())));
|
||||
|
||||
return {
|
||||
...res,
|
||||
images,
|
||||
thumbimage: nth(0, images)
|
||||
thumbimage: nth(0, images),
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -53,12 +53,12 @@ class TopToolbar extends Component {
|
|||
|
||||
onSearchCleared = () => {
|
||||
const { setFilter, filter } = this.props;
|
||||
setFilter(filter.update((prevFilter) => prevFilter.set('search', '')));
|
||||
setFilter(filter.set('search', ''));
|
||||
};
|
||||
|
||||
onChangeText = (search) => {
|
||||
const { setFilter, filter } = this.props;
|
||||
setFilter(filter.update((prevFilter) => prevFilter.set('search', search)));
|
||||
setFilter(filter.set('search', search));
|
||||
};
|
||||
|
||||
getRightElement = () => {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
export const BASE_URL = 'aretherecookies.herokuapp.com';
|
||||
|
||||
// @home
|
||||
// export const BASE_URL = '192.168.1.8:3000';
|
||||
// export const BASE_URL = '192.168.1.247:3000';
|
||||
|
||||
// @stouthaus
|
||||
// export const BASE_URL = '192.168.1.181:3000';
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ const fetchedFoodItems$ = Filter$.combineLatest(location$)
|
|||
if (!loc) {
|
||||
return Promise.resolve({});
|
||||
}
|
||||
return Observable.merge(Promise.resolve({}), getFoodItems({ filter, loc }));
|
||||
return getFoodItems({ filter, loc });
|
||||
})
|
||||
.map(({ fooditems }: FoodItemsForLocation) => {
|
||||
if (fooditems) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue