Added announcement disposal:
Added ann details button Added modal shown on its click Moved trashbox selection there Added trashboxes mock while testing in restricted area
This commit is contained in:
@@ -8,3 +8,4 @@ export { default as useRemoveAnnouncement } from './useRemoveAnnouncement'
|
||||
export { default as useSignIn } from './useSignIn'
|
||||
export { default as useSignUp } from './useSignUp'
|
||||
export { default as usePoetry } from './usePoetry'
|
||||
export { default as useDispose } from './useDispose'
|
||||
|
35
front/src/hooks/api/useDispose.ts
Normal file
35
front/src/hooks/api/useDispose.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { useCallback } from 'react'
|
||||
|
||||
import { useSendWithButton } from '..'
|
||||
import { composeDisposeBody, composeDisposeURL, processDispose } from '../../api/dispose'
|
||||
import { DisposeParams, isDisposeResponse } from '../../api/dispose/types'
|
||||
|
||||
const useDispose = (resolve: () => void) => {
|
||||
const { doSend, button } = useSendWithButton(
|
||||
'Выбор сделан',
|
||||
'Зачтено',
|
||||
true,
|
||||
composeDisposeURL(),
|
||||
'POST',
|
||||
true,
|
||||
isDisposeResponse,
|
||||
processDispose,
|
||||
)
|
||||
|
||||
const doSendWithClose = useCallback(async (...args: DisposeParams) => {
|
||||
const res = await doSend({}, {
|
||||
body: composeDisposeBody(...args),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
})
|
||||
|
||||
if (res) {
|
||||
resolve()
|
||||
}
|
||||
}, [doSend, resolve])
|
||||
|
||||
return { handleDispose: doSendWithClose, disposeButton: button }
|
||||
}
|
||||
|
||||
export default useDispose
|
@@ -6,7 +6,7 @@ import { isRemoveAnnouncementResponse } from '../../api/removeAnnouncement/types
|
||||
|
||||
const useRemoveAnnouncement = (resolve: () => void) => {
|
||||
const { doSend, button } = useSendWithButton(
|
||||
'Закрыть',
|
||||
'Закрыть объявление',
|
||||
'Закрыто',
|
||||
true,
|
||||
composeRemoveAnnouncementURL(),
|
||||
|
@@ -1,18 +1,41 @@
|
||||
import { LatLng } from 'leaflet'
|
||||
import { sampleSize, random } from 'lodash'
|
||||
|
||||
import { useFetch } from '../'
|
||||
import { composeTrashboxURL, processTrashbox } from '../../api/trashbox'
|
||||
import { isTrashboxResponse } from '../../api/trashbox/types'
|
||||
import { Trashbox } from '../../api/trashbox/types'
|
||||
import { UseFetchReturn } from '../useFetch'
|
||||
|
||||
const useTrashboxes = (position: LatLng) => (
|
||||
useFetch(
|
||||
composeTrashboxURL(position),
|
||||
'GET',
|
||||
true,
|
||||
isTrashboxResponse,
|
||||
processTrashbox,
|
||||
[],
|
||||
)
|
||||
import { faker } from '@faker-js/faker/locale/ru'
|
||||
import { Category, categories } from '../../assets/category'
|
||||
import { useCallback, useMemo } from 'react'
|
||||
|
||||
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[]> => (
|
||||
// useFetch(
|
||||
// composeTrashboxURL(position, category),
|
||||
// 'GET',
|
||||
// true,
|
||||
// isTrashboxResponse,
|
||||
// processTrashbox,
|
||||
// [],
|
||||
// )
|
||||
|
||||
{
|
||||
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