Trashboxes fetching fixes
This commit is contained in:
@ -3,40 +3,20 @@ import { LatLng } from 'leaflet'
|
||||
import { Trashbox, isTrashboxResponse } from '../../api/trashbox/types'
|
||||
import useFetch, { UseFetchReturn } from '../useFetch'
|
||||
|
||||
import { faker } from '@faker-js/faker/locale/ru'
|
||||
import { Category } from '../../assets/category'
|
||||
import { useMemo } from 'react'
|
||||
import { composeTrashboxURL, processTrashbox } from '../../api/trashbox'
|
||||
|
||||
function genMockTrashbox(pos: LatLng): Trashbox {
|
||||
const loc = faker.location.nearbyGPSCoordinate({ origin: [pos.lat, pos.lng], radius: 1 })
|
||||
|
||||
return {
|
||||
Name: faker.company.name(),
|
||||
Address: faker.location.streetAddress(),
|
||||
Categories: faker.lorem.words({ max: 3, min: 1 }).split(' '),
|
||||
Lat: loc[0],
|
||||
Lng: loc[1],
|
||||
}
|
||||
}
|
||||
|
||||
const useTrashboxes = (position: LatLng, category: Category): UseFetchReturn<Trashbox[]> => (
|
||||
// TODO: Remove once available
|
||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||
import.meta.env.PROD ? useFetch(
|
||||
useFetch(
|
||||
composeTrashboxURL(position, category),
|
||||
'GET',
|
||||
true,
|
||||
isTrashboxResponse,
|
||||
processTrashbox,
|
||||
[],
|
||||
) : {
|
||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||
data: useMemo(() => new Array(3).fill(3).map(() => genMockTrashbox(position)), [position]),
|
||||
loading: false,
|
||||
error: null,
|
||||
refetch: () => { return },
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
export default useTrashboxes
|
||||
|
Reference in New Issue
Block a user