From 9937708da5010a9a72a31375d3030c1fa39065c0 Mon Sep 17 00:00:00 2001 From: MatManSky Date: Wed, 9 Aug 2023 01:37:57 +0300 Subject: [PATCH 1/6] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=8B=D1=82=D0=BA=D0=B0?= =?UTF-8?q?=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B=20=D1=81=20.env(=D0=BD?= =?UTF-8?q?=D0=B5=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82,=20?= =?UTF-8?q?=D0=BF=D0=BE=D1=8D=D1=82=D0=BE=D0=BC=D1=83=20=D0=BA=D0=BE=D0=BC?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/main.py | 9 +++++++-- back/unimportant.env | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 back/unimportant.env diff --git a/back/main.py b/back/main.py index 1d279f0..3c96541 100644 --- a/back/main.py +++ b/back/main.py @@ -20,6 +20,9 @@ import pathlib import shutil import os +from dotenv import load_dotenv +load_dotenv() + from .db import Base, engine, SessionLocal, database from .service import add_poems_to_db, generate_poem, check_obsolete, get_query_results from .scheduler import app as app_rocketry @@ -212,8 +215,10 @@ def poems_to_front(): # db: Annotated[Session, Depends(utils.get_db)] @app.get("/api/trashbox", response_model=List[schemas.TrashboxResponse]) def get_trashboxes(lat:float, lng:float):#крутая функция для работы с api - BASE_URL='https://geointelect2.gate.petersburg.ru'#адрес сайта и мой токин - my_token='eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJhU1RaZm42bHpTdURYcUttRkg1SzN5UDFhT0FxUkhTNm9OendMUExaTXhFIn0.eyJleHAiOjE3ODM3ODk4NjgsImlhdCI6MTY4OTA5NTQ2OCwianRpIjoiNDUzNjQzZTgtYTkyMi00NTI4LWIzYmMtYWJiYTNmY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Lx4bLtVbB4pdqgyJYcrDHg7sgwz4d1Z3tAeUfSpum9s5ZfELequfpLoZMXn6CaYZhePaoK-CxeU3KPBPTPOVPKZZ19s7QY10VdkxLULknqf9opdvLs4j8NMimtwoIiHNBFlgQz10Cr7bhDKWugfvSRsICouniIiBJo76wrj5T92s-ztf1FShJuqnQcKE_QLd2A' + #BASE_URL=os.getenv("DOMAIN") # адрес сайта + #my_token=os.getenv("TOKEN") # токен + BASE_URL= "https://geointelect2.gate.petersburg.ru" + my_token="eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJhU1RaZm42bHpTdURYcUttRkg1SzN5UDFhT0FxUkhTNm9OendMUExaTXhFIn0.eyJleHAiOjE3ODYyMjUzMzMsImlhdCI6MTY5MTUzMDkzMywianRpIjoiYjU0MmU3MTQtYzJkMS00NTY2LWJkY2MtYmQ5NzA0ODY1ZjgzIiwiaXNzIjoiaHR0cHM6Ly9rYy5wZXRlcnNidXJnLnJ1L3JlYWxtcy9lZ3MtYXBpIiwiYXVkIjoiYWNjb3VudCIsInN1YiI6ImJjYjQ2NzljLTU3ZGItNDU5ZC1iNWUxLWRlOGI4Yzg5MTMwMyIsInR5cCI6IkJlYXJlciIsImF6cCI6ImFkbWluLXJlc3QtY2xpZW50Iiwic2Vzc2lvbl9zdGF0ZSI6IjJhOTgwMzUyLTY1M2QtNGZlZC1iMDI1LWQ1N2U0NDRjZmM3NiIsImFjciI6IjEiLCJhbGxvd2VkLW9yaWdpbnMiOlsiLyoiXSwicmVhbG1fYWNjZXNzIjp7InJvbGVzIjpbImRlZmF1bHQtcm9sZXMtZWdzLWFwaSIsIm9mZmxpbmVfYWNjZXNzIiwidW1hX2F1dGhvcml6YXRpb24iXX0sInJlc291cmNlX2FjY2VzcyI6eyJhY2NvdW50Ijp7InJvbGVzIjpbIm1hbmFnZS1hY2NvdW50IiwibWFuYWdlLWFjY291bnQtbGlua3MiLCJ2aWV3LXByb2ZpbGUiXX19LCJzY29wZSI6ImVtYWlsIHByb2ZpbGUiLCJzaWQiOiIyYTk4MDM1Mi02NTNkLTRmZWQtYjAyNS1kNTdlNDQ0Y2ZjNzYiLCJlbWFpbF92ZXJpZmllZCI6ZmFsc2UsIm5hbWUiOiLQktC70LDQtNC40LzQuNGAINCv0LrQvtCy0LvQtdCyIiwicHJlZmVycmVkX3VzZXJuYW1lIjoiZTBmYzc2OGRhOTA4MjNiODgwZGQzOGVhMDJjMmQ5NTciLCJnaXZlbl9uYW1lIjoi0JLQu9Cw0LTQuNC80LjRgCIsImZhbWlseV9uYW1lIjoi0K_QutC-0LLQu9C10LIifQ.FTKiC1hpWcOkmSW9QZpC-RY7Ko50jw1mDMfXIWYxlQ-zehLm2CLmOnHvYoOoI39k2OzeCIAB9ZdRrrGZc6G9Z1eFELUjNGEqKxSC1Phj9ATemKgbOKEttk-OGc-rFr9VPA8_SnfvLts6wTI2YK33YBIxCF5nCbnr4Qj3LeEQ0d6Hy8PO4ATrBF5EOeuAZRprvIEjXe_f8N9ONKckCPB-xFB4P2pZlVXGoCNoewGEcY3zXH4khezN6zcVr6tpc6G8dBv9EqT_v92IDSg-aXQk6ysA0cO0-6x5w1-_qU0iHGIAPsLNV9IKBoFbjc0JH6cWabldPRH12NP1trvYfqKDGQ" head = {'Authorization': 'Bearer {}'.format(my_token)} my_data={ diff --git a/back/unimportant.env b/back/unimportant.env new file mode 100644 index 0000000..3e418f7 --- /dev/null +++ b/back/unimportant.env @@ -0,0 +1,2 @@ +TOKEN = "eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJhU1RaZm42bHpTdURYcUttRkg1SzN5UDFhT0FxUkhTNm9OendMUExaTXhFIn0.eyJleHAiOjE3ODYyMjUzMzMsImlhdCI6MTY5MTUzMDkzMywianRpIjoiYjU0MmU3MTQtYzJkMS00NTY2LWJkY2MtYmQ5NzA0ODY1ZjgzIiwiaXNzIjoiaHR0cHM6Ly9rYy5wZXRlcnNidXJnLnJ1L3J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IEjXe_f8N9ONKckCPB-xFB4P2pZlVXGoCNoewGEcY3zXH4khezN6zcVr6tpc6G8dBv9EqT_v92IDSg-aXQk6ysA0cO0-6x5w1-_qU0iHGIAPsLNV9IKBoFbjc0JH6cWabldPRH12NP1trvYfqKDGQ" +DOMAIN = "https://geointelect2.gate.petersburg.ru" \ No newline at end of file From 6478b4530174b69897c3eb3c79b8168aa9251ee8 Mon Sep 17 00:00:00 2001 From: dm1sh Date: Wed, 9 Aug 2023 14:24:44 +0300 Subject: [PATCH 2/6] Improved StarRating indication of rated mark --- front/src/components/AnnouncementDetails.tsx | 19 +++++++--- front/src/components/StarRating.tsx | 40 ++++++++++++++------ 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/front/src/components/AnnouncementDetails.tsx b/front/src/components/AnnouncementDetails.tsx index dd7b805..3a9ed35 100644 --- a/front/src/components/AnnouncementDetails.tsx +++ b/front/src/components/AnnouncementDetails.tsx @@ -25,10 +25,12 @@ const styles = { } type ViewProps = { + myId: number, announcement: Announcement, } const View = ({ + myId, announcement: { name, category, bestBy, description, lat, lng, address, metro, userId }, }: ViewProps) => ( <> @@ -41,7 +43,7 @@ const View = ({

{description}

- Рейтинг пользователя: + Рейтинг пользователя:

@@ -62,12 +64,14 @@ const View = ({ ) type ControlProps = { + myId: number, closeRefresh: () => void, announcement: Announcement, showDispose: () => void } function Control({ + myId, closeRefresh, announcement: { bookedBy, id, userId }, showDispose, @@ -76,8 +80,6 @@ function Control({ const { handleRemove, removeButton } = useRemoveAnnouncement(closeRefresh) - const myId = useId() - return ( <>

Забронировали {bookedBy + (bookButton.disabled ? 1 : 0)} чел.

@@ -111,6 +113,8 @@ function AnnouncementDetails({ const [disposeShow, setDisposeShow] = useState(false) + const myId = useId() + return (
- + - setDisposeShow(true)} announcement={announcement} /> + setDisposeShow(true)} + announcement={announcement} + /> setDisposeShow(false)} style={{ zIndex: 100000 }}> diff --git a/front/src/components/StarRating.tsx b/front/src/components/StarRating.tsx index 3154f6f..c433d7b 100644 --- a/front/src/components/StarRating.tsx +++ b/front/src/components/StarRating.tsx @@ -8,18 +8,17 @@ import styles from '../styles/StarRating.module.css' type StarProps = { filled: boolean, selected: boolean, - setMyRate?: () => void, + selectRate?: () => void, sendMyRate?: () => void, disabled: boolean } -function Star({ filled, selected, setMyRate, sendMyRate, disabled }: StarProps) { +function Star({ filled, selected, selectRate, disabled }: StarProps) { return ( // star ) @@ -28,21 +27,23 @@ function Star({ filled, selected, setMyRate, sendMyRate, disabled }: StarProps) type StarRatingProps = { userId: number, dynamic?: boolean, - style?: React.CSSProperties, } function StarRating({ userId, dynamic = false }: StarRatingProps) { const rating = useUserRating(userId) + const [selectedRate, setSelectedRate] = useState(0) const [myRate, setMyRate] = useState(0) + const rated = myRate > 0 const { doSendRate } = useSendRate() async function sendMyRate() { - const res = await doSendRate(myRate, userId) + const res = await doSendRate(selectedRate, userId) if (res) { rating.refetch() + setMyRate(selectedRate) } } @@ -59,15 +60,30 @@ function StarRating({ userId, dynamic = false }: StarRatingProps) { } return ( - setMyRate(0)}> + dynamic && !rated && void sendMyRate()} + + onMouseEnter={() => rated && setSelectedRate(myRate)} + onMouseLeave={() => setSelectedRate(0)} + + onFocus={() => rated && setSelectedRate(myRate)} + onBlur={() => setSelectedRate(0)} + + onTouchStart={() => rated && setSelectedRate(myRate)} + onTouchEnd={() => setSelectedRate(0)} + + title={`Пользователи: ${Math.round(rating.data)}\nВы: ${myRate}`} + tabIndex={0} + > {...Array(5).fill(5).map((_, i) => ( dynamic && setMyRate(i + 1)} - sendMyRate={() => dynamic && void sendMyRate()} - disabled={!dynamic} + selected={i < selectedRate} + selectRate={() => dynamic && !rated && setSelectedRate(i + 1)} + disabled={!dynamic || rated} /> ))} From fa98b392a887748fe4545f39ae96620700c6ea00 Mon Sep 17 00:00:00 2001 From: dm1sh Date: Wed, 9 Aug 2023 14:25:50 +0300 Subject: [PATCH 3/6] Added poetry picture, fixed spacing on UserPage --- front/src/components/Poetry.tsx | 5 +++-- front/src/components/Points.tsx | 25 ++++++++++--------------- front/src/components/StoriesPreview.tsx | 1 + front/src/pages/UserPage.tsx | 20 +++++++++++--------- front/src/styles/Poetry.module.css | 2 +- 5 files changed, 26 insertions(+), 27 deletions(-) diff --git a/front/src/components/Poetry.tsx b/front/src/components/Poetry.tsx index 2bd23aa..29659e5 100644 --- a/front/src/components/Poetry.tsx +++ b/front/src/components/Poetry.tsx @@ -7,7 +7,7 @@ function Poetry() { const poetry = usePoetry() return ( -
+

Поэзия

{ gotResponse(poetry) ? ( gotError(poetry) ? ( @@ -26,6 +26,7 @@ function Poetry() { }} />

{poetry.data.author}

+ Иллюстрация ) ) : ( @@ -33,7 +34,7 @@ function Poetry() { ) } -
+ ) } diff --git a/front/src/components/Points.tsx b/front/src/components/Points.tsx index deebc85..ecbb885 100644 --- a/front/src/components/Points.tsx +++ b/front/src/components/Points.tsx @@ -7,9 +7,6 @@ type PointsProps = { } const styles = { - container: { - paddingBottom: 8, - } as CSSProperties, points: { float: 'right', } as CSSProperties, @@ -22,18 +19,16 @@ const styles = { function Points({ points }: PointsProps) { return ( -
-
- Набрано очков: - - Иконка руки, дающей звёзды - {points} - -
-
+
+ Набрано очков: + + Иконка руки, дающей звёзды + {points} + +
) } diff --git a/front/src/components/StoriesPreview.tsx b/front/src/components/StoriesPreview.tsx index 306b71a..4bd6cf6 100644 --- a/front/src/components/StoriesPreview.tsx +++ b/front/src/components/StoriesPreview.tsx @@ -37,6 +37,7 @@ const styles = { objectFit: 'contain', borderRadius: 12, marginBottom: 5, + maxWidth: 'inherit', } as CSSProperties, title: { overflow: 'hidden', diff --git a/front/src/pages/UserPage.tsx b/front/src/pages/UserPage.tsx index 2ed6dba..7d9f198 100644 --- a/front/src/pages/UserPage.tsx +++ b/front/src/pages/UserPage.tsx @@ -26,15 +26,15 @@ function UserPage() { - +
+ -
Ваша оценка: @@ -45,7 +45,9 @@ function UserPage() { ))} - +
+ +
) } diff --git a/front/src/styles/Poetry.module.css b/front/src/styles/Poetry.module.css index a452425..8057f48 100644 --- a/front/src/styles/Poetry.module.css +++ b/front/src/styles/Poetry.module.css @@ -3,5 +3,5 @@ } .text { - white-space: 'pre-wrap'; + white-space: pre-wrap; } \ No newline at end of file From f8235ca7f4e06acf07ec30d11906c58e23e9eca6 Mon Sep 17 00:00:00 2001 From: dm1sh Date: Wed, 9 Aug 2023 17:55:54 +0300 Subject: [PATCH 4/6] Fixed fetch loading ending before result saving --- front/src/hooks/useFetch.ts | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/front/src/hooks/useFetch.ts b/front/src/hooks/useFetch.ts index 82a5106..c0e9319 100644 --- a/front/src/hooks/useFetch.ts +++ b/front/src/hooks/useFetch.ts @@ -1,4 +1,4 @@ -import { useEffect, useState } from 'react' +import { useCallback, useEffect, useState } from 'react' import useSend from './useSend' @@ -54,7 +54,9 @@ function useFetch>( ): UseFetchReturn { const [data, setData] = useState(initialData) - const { doSend, loading, error } = useSend( + const [fetchLoading, setFetchLoading] = useState(true) + + const { doSend, error } = useSend( url, method, needAuth, @@ -64,20 +66,26 @@ function useFetch>( params, ) - function refetch() { + const refetch = useCallback(() => { + setFetchLoading(true) doSend().then( - data => { if (data !== undefined) setData(data) } + data => { + if (data !== undefined) { + setData(data) + } + setFetchLoading(false) + } ).catch( // must never occur err => import.meta.env.DEV && console.error('Failed to do fetch request', err) ) - } + }, [doSend]) - useEffect(refetch, [doSend]) + useEffect(refetch, [refetch]) - if (loading === true) { + if (fetchLoading === true) { return { data: undefined, - loading, + loading: fetchLoading, error: null, refetch, } @@ -86,7 +94,7 @@ function useFetch>( if (error !== null) { return { data: undefined, - loading, + loading: fetchLoading, error, refetch, } @@ -94,7 +102,7 @@ function useFetch>( return { data: data!, - loading, + loading: fetchLoading, error, refetch, } From 8cfac08e8da06d0e9356d4d6d631a902d347e970 Mon Sep 17 00:00:00 2001 From: MatManSky Date: Wed, 9 Aug 2023 19:54:27 +0300 Subject: [PATCH 5/6] =?UTF-8?q?=D0=9D=D0=B0=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=BF=D0=BE=20=D0=BC=D1=83=D1=81=D0=BE=D1=80?= =?UTF-8?q?=D0=BA=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/main.py | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/back/main.py b/back/main.py index 3c96541..57524b5 100644 --- a/back/main.py +++ b/back/main.py @@ -214,7 +214,7 @@ def poems_to_front(): # db: Annotated[Session, Depends(utils.get_db)] raise HTTPException(status_code=404, detail="Poems not found") @app.get("/api/trashbox", response_model=List[schemas.TrashboxResponse]) -def get_trashboxes(lat:float, lng:float):#крутая функция для работы с api +def get_trashboxes(lat:float, lng:float, category:str):#крутая функция для работы с api #BASE_URL=os.getenv("DOMAIN") # адрес сайта #my_token=os.getenv("TOKEN") # токен BASE_URL= "https://geointelect2.gate.petersburg.ru" @@ -226,11 +226,38 @@ def get_trashboxes(lat:float, lng:float):#крутая функция для р 'y' : f"{lat}", 'limit' : '1' } + + list_of_category = [] # лист по которому будет отбираться uniq_trashboxes + match category: + case "PORRIDGE": + list_of_category=["Опасные отходы", "Иное"] + case "Конспекты": + list_of_category=["Бумага"] + case "Молочные продукты": + list_of_category=["Стекло","Тетра Пак", "Иное"] + case "Хлебобулочные изделия": + list_of_category=["Пластик", "Иное"] + case "Моющие средства": + list_of_category=["Пластик", "Опасные отходы", "Иное"] + case "Одежда": + list_of_category=["Одежда"] + case "Фрукты и овощи": + list_of_category=["Иное"] + case "Супы": + list_of_category=["Опасные отходы", "Иное"] + case "Ужин": + list_of_category=["Опасные отходы", "Иное"] + case "Консервы": + list_of_category=["Металл", "Стекло", "Иное"] + case "Канцелярия": + list_of_category=["Пластик", "Бумага"] + case "Всякая всячина": + list_of_category=["Металл", "Бумага", "Стекло","Иное", "Тетра Пак", "Батарейки", "Крышечки", "Шины", "Опасные отходы", "Лампочки", "Пластик"] response = requests.post(f"{BASE_URL}/nearest_recycling/get", headers=head, data=my_data) infos = response.json() - trashboxes = [] + for trashbox in infos["results"]: temp_dict = {} for obj in trashbox["Objects"]: @@ -245,6 +272,7 @@ def get_trashboxes(lat:float, lng:float):#крутая функция для р trashboxes.append(temp_dict) uniq_trashboxes = [ast.literal_eval(el1) for el1 in set([str(el2) for el2 in trashboxes])] + return JSONResponse(uniq_trashboxes) @app.get("/{rest_of_path:path}") From 77312268641ce4fcaf9742732ea79aa463ef5afd Mon Sep 17 00:00:00 2001 From: MatManSky Date: Thu, 10 Aug 2023 01:06:00 +0300 Subject: [PATCH 6/6] =?UTF-8?q?=D0=9D=D0=B0=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=BF=D0=BE=20=D0=BC=D1=83=D1=81=D0=BE=D1=80?= =?UTF-8?q?=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/main.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/back/main.py b/back/main.py index 57524b5..16a10e7 100644 --- a/back/main.py +++ b/back/main.py @@ -217,9 +217,9 @@ def poems_to_front(): # db: Annotated[Session, Depends(utils.get_db)] def get_trashboxes(lat:float, lng:float, category:str):#крутая функция для работы с api #BASE_URL=os.getenv("DOMAIN") # адрес сайта #my_token=os.getenv("TOKEN") # токен - BASE_URL= "https://geointelect2.gate.petersburg.ru" + BASE_URL= "https://geointelect2.gate.petersburg.ru/nearest_recycling/get" my_token="eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJhU1RaZm42bHpTdURYcUttRkg1SzN5UDFhT0FxUkhTNm9OendMUExaTXhFIn0.eyJleHAiOjE3ODYyMjUzMzMsImlhdCI6MTY5MTUzMDkzMywianRpIjoiYjU0MmU3MTQtYzJkMS00N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ttk-OGc-rFr9VPA8_SnfvLts6wTI2YK33YBIxCF5nCbnr4Qj3LeEQ0d6Hy8PO4ATrBF5EOeuAZRprvIEjXe_f8N9ONKckCPB-xFB4P2pZlVXGoCNoewGEcY3zXH4khezN6zcVr6tpc6G8dBv9EqT_v92IDSg-aXQk6ysA0cO0-6x5w1-_qU0iHGIAPsLNV9IKBoFbjc0JH6cWabldPRH12NP1trvYfqKDGQ" - head = {'Authorization': 'Bearer {}'.format(my_token)} + head = {'accept': 'application/json','Authorization': 'Bearer {}'.format(my_token), 'Content-Type': 'application/x-www-form-urlencoded'} my_data={ 'x' : f"{lng}", @@ -254,7 +254,7 @@ 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}", headers=head, data=my_data) infos = response.json() trashboxes = [] @@ -264,7 +264,6 @@ def get_trashboxes(lat:float, lng:float, category:str):#крутая функц coord_list = obj["geometry"] temp_dict["Lat"] = coord_list["coordinates"][1] temp_dict["Lng"] = coord_list["coordinates"][0] - properties = obj["properties"] temp_dict["Name"] = properties["title"] temp_dict["Address"] = properties["address"]