import { CSSProperties, FormEventHandler, useState } from 'react' import { Form, Button, Card } from 'react-bootstrap' import { MapContainer, TileLayer } from 'react-leaflet' import { latLng } from 'leaflet' import { ClickHandler, LocationMarker, TrashboxMarkers } from '../components' import { useAddAnnouncement, useTrashboxes } from '../hooks/api' import { categories, categoryNames } from '../assets/category' import { stations, lines, lineNames } from '../assets/metro' import { fallbackError, gotError } from '../hooks/useFetch' import { useOsmAddresses } from '../hooks/api' const styles = { modal: { height: 'calc(100vh - 3rem)', } as CSSProperties, body: { overflowY: 'auto', } as CSSProperties, map: { width: '100%', height: 400, } as CSSProperties, } function AddPage() { const [addressPosition, setAddressPosition] = useState(latLng(59.972, 30.3227)) const trashboxes = useTrashboxes(addressPosition) const [selectedTrashbox, setSelectedTrashbox] = useState({ index: -1, category: '' }) const address = useOsmAddresses(addressPosition) const { doSend, button } = useAddAnnouncement() const handleSubmit: FormEventHandler = (event) => { event.preventDefault() event.stopPropagation() const formData = new FormData(event.currentTarget) formData.append('latitude', addressPosition.lat.toString()) formData.append('longtitude', addressPosition.lng.toString()) formData.append('address', address.data || '') // if address.error formData.set('bestBy', new Date((formData.get('bestBy') as number | null) || 0).getTime().toString()) void doSend(formData) } return (
Заголовок объявления Категория {categories.map(category => )} Срок годности Адрес выдачи

Адрес: {fallbackError(address)}

Описание Иллюстрация (фото или видео) Станция метро {lines.map( line => {Array.from(stations[line]).map(metro => )} )} Пункт сбора мусора
{trashboxes.loading ? (

Загрузка...

) : ( gotError(trashboxes) ? (

{trashboxes.error}

) : ( ) ) }
{!gotError(trashboxes) && selectedTrashbox.index > -1 ? (

Выбран пункт сбора мусора на { trashboxes.data[selectedTrashbox.index].Address } с категорией {selectedTrashbox.category}

) : (

Выберите пунк сбора мусора и категорию

)}