Trashboxes fetching fixes

This commit is contained in:
2023-08-12 02:50:26 +03:00
parent a5798cf767
commit 0aaef69a5a
4 changed files with 7 additions and 27 deletions

View File

@ -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