From 0aaef69a5a8ebdecc6a2fd844708f75b5ec154fa Mon Sep 17 00:00:00 2001 From: dm1sh Date: Sat, 12 Aug 2023 02:50:26 +0300 Subject: [PATCH 1/2] Trashboxes fetching fixes --- front/src/api/trashbox/index.ts | 6 +++--- front/src/components/LineDot.tsx | 2 +- front/src/components/Poetry.tsx | 2 +- front/src/hooks/api/useTrashboxes.ts | 24 ++---------------------- 4 files changed, 7 insertions(+), 27 deletions(-) diff --git a/front/src/api/trashbox/index.ts b/front/src/api/trashbox/index.ts index 7e45fa5..fb51234 100644 --- a/front/src/api/trashbox/index.ts +++ b/front/src/api/trashbox/index.ts @@ -6,9 +6,9 @@ import { Category } from '../../assets/category' const composeTrashboxURL = (position: LatLng, category: Category) => ( API_URL + '/trashbox?' + new URLSearchParams({ - lat: position.lat.toString(), - lng: position.lng.toString(), - category: category, + Lat: position.lat.toString(), + Lng: position.lng.toString(), + Category: category, }).toString() ) diff --git a/front/src/components/LineDot.tsx b/front/src/components/LineDot.tsx index 66b5ad7..dcb0778 100644 --- a/front/src/components/LineDot.tsx +++ b/front/src/components/LineDot.tsx @@ -3,7 +3,7 @@ import { colors, lineNames, lineByName } from '../assets/metro' function LineDot({ station }: { station: string }) { const line = lineByName(station) - if (line == undefined) { + if (line === undefined) { return <> } diff --git a/front/src/components/Poetry.tsx b/front/src/components/Poetry.tsx index 29659e5..10ea8db 100644 --- a/front/src/components/Poetry.tsx +++ b/front/src/components/Poetry.tsx @@ -26,7 +26,7 @@ function Poetry() { }} />

{poetry.data.author}

- Иллюстрация + Иллюстрация ) ) : ( diff --git a/front/src/hooks/api/useTrashboxes.ts b/front/src/hooks/api/useTrashboxes.ts index bd2929a..df88fc7 100644 --- a/front/src/hooks/api/useTrashboxes.ts +++ b/front/src/hooks/api/useTrashboxes.ts @@ -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 => ( // 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 From d5e19f45d21e376ce465c3db6585d1ce74a02d3f Mon Sep 17 00:00:00 2001 From: MatManSky Date: Sat, 12 Aug 2023 12:27:50 +0300 Subject: [PATCH 2/2] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=B2=20=D0=BC=D1=83=D1=81=D0=BE=D1=80=D0=BA=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/api.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/back/api.py b/back/api.py index 563bbfb..124151d 100644 --- a/back/api.py +++ b/back/api.py @@ -210,13 +210,13 @@ def get_trashboxes(Lat:float, Lng:float, Category:str):#крутая функц BASE_URL= "https://geointelect2.gate.petersburg.ru" my_token="eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJhU1RaZm42bHpTdURYcUttRkg1SzN5UDFhT0FxUkhTNm9OendMUExaTXhFIn0.eyJleHAiOjE3ODYyMjUzMzMsImlhdCI6M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dRrrGZc6G9Z1eFELUjNGEqKxSC1Phj9ATemKgbOKEttk-OGc-rFr9VPA8_SnfvLts6wTI2YK33YBIxCF5nCbnr4Qj3LeEQ0d6Hy8PO4ATrBF5EOeuAZRprvIEjXe_f8N9ONKckCPB-xFB4P2pZlVXGoCNoewGEcY3zXH4khezN6zcVr6tpc6G8dBv9EqT_v92IDSg-aXQk6ysA0cO0-6x5w1-_qU0iHGIAPsLNV9IKBoFbjc0JH6cWabldPRH12NP1trvYfqKDGQ" head = {'Authorization': 'Bearer {}'.format(my_token)} - + # Данные пользователя (местоположение, количество мусорок, которое пользователь хочет видеть) my_data={ 'x' : f"{Lng}", 'y' : f"{Lat}", 'limit' : '1' } - + # Перевод категории с фронта на категорию с сайта match Category: case "PORRIDGE": list_of_category = ["Опасные отходы", "Иное"] @@ -235,9 +235,10 @@ def get_trashboxes(Lat:float, Lng:float, Category:str):#крутая функц case "Всякая всячина": list_of_category = ["Металл", "Бумага", "Стекло", "Иное", "Тетра Пак", "Батарейки", "Крышечки", "Шины", "Опасные отходы", "Лампочки", "Пластик"] - - response = requests.post(f"{BASE_URL}/nearest_recycling/get", headers=head, data=my_data) + # Получение ответа от стороннего апи + response = requests.post(f"{BASE_URL}/nearest_recycling/get", headers=head, data=my_data, timeout=10) infos = response.json() + # Чтение ответа trashboxes = [] for trashbox in infos["results"]: temp_dict = {}