2021-05-20 07:50:20 +00:00
|
|
|
import HTTPService from './HTTPService';
|
2021-05-20 08:19:37 +00:00
|
|
|
import * as chrono from 'chrono-node';
|
2021-05-26 10:18:13 +00:00
|
|
|
import { getEndpoint } from 'utils/common/apiUtil';
|
|
|
|
|
|
|
|
const ENDPOINT = getEndpoint();
|
2021-05-20 07:50:20 +00:00
|
|
|
|
2021-05-21 09:47:28 +00:00
|
|
|
export type Bbox = [number, number, number, number];
|
|
|
|
export interface LocationSearchResponse {
|
2021-05-26 10:18:13 +00:00
|
|
|
place: string;
|
2021-05-21 09:47:28 +00:00
|
|
|
bbox: Bbox;
|
|
|
|
}
|
2021-05-20 07:50:20 +00:00
|
|
|
export const getMapboxToken = () => {
|
|
|
|
return process.env.NEXT_PUBLIC_MAPBOX_TOKEN;
|
|
|
|
};
|
|
|
|
|
2021-05-20 08:19:37 +00:00
|
|
|
export function parseHumanDate(humanDate: string) {
|
|
|
|
return chrono.parseDate(humanDate);
|
|
|
|
}
|
|
|
|
|
2021-05-20 07:50:20 +00:00
|
|
|
export async function searchLocation(
|
2021-05-26 10:18:13 +00:00
|
|
|
searchPhrase: string
|
2021-05-21 09:47:28 +00:00
|
|
|
): Promise<LocationSearchResponse[]> {
|
2021-05-26 10:18:13 +00:00
|
|
|
const resp = await HTTPService.get(`${ENDPOINT}/search/location`, {
|
|
|
|
query: searchPhrase,
|
|
|
|
limit: 4,
|
|
|
|
});
|
2021-05-26 11:41:55 +00:00
|
|
|
return resp.data.result;
|
2021-05-20 07:50:20 +00:00
|
|
|
}
|