Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into test-12
Browse files Browse the repository at this point in the history
  • Loading branch information
Kseen715 committed Dec 4, 2024
2 parents 0cb0403 + f14ae61 commit 59bd2d4
Show file tree
Hide file tree
Showing 45 changed files with 2,255 additions and 1,125 deletions.
4 changes: 4 additions & 0 deletions frontend/public/arrow-down-svgrepo-com.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions frontend/public/arrow-left-svgrepo-com.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions frontend/public/arrow-right-svgrepo-com.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions frontend/public/arrow-up-svgrepo-com.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/favicon.ico
Binary file not shown.
Binary file removed frontend/public/favicon.jpg
Binary file not shown.
Binary file added frontend/public/ferma.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion frontend/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.jpg" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
Expand Down
1 change: 1 addition & 0 deletions frontend/public/search.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions frontend/public/tamprog-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed frontend/public/tenor.gif
Binary file not shown.
Binary file added frontend/public/user_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/user_plus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion frontend/src/App.css

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions frontend/src/App.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "./App.css";
import MainPage from "./components/main-page/MainPage";
import LandingPage from "./components/main-page/LandingPage/LandingPage";
import AuthForm from "./components/auth/login/auth";
import { Routes, Route } from "react-router-dom";
import Header from "./components/header/Header";
Expand All @@ -15,7 +15,7 @@ function App() {
return (
<div className="App">
<Routes>
<Route path="/" element={<MainPage />} />
<Route path="/" element={<LandingPage />} />
<Route path="/login" element={<AuthForm />} />
<Route path="/register" element={<RegisterForm />} />

Expand Down
4 changes: 1 addition & 3 deletions frontend/src/components/api/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios from "axios";

const Instance = axios.create({
baseURL: "http://127.0.0.1:8000/api/v1",
timeout: 5000,
timeout: 15000,
headers: {
"Content-Type": "application/json",
},
Expand Down Expand Up @@ -42,12 +42,10 @@ Instance.interceptors.response.use(
localStorage.setItem("accessToken", response.data.access);
originalRequest.headers.Authorization = `Bearer ${response.data.access}`;

// Повторяем оригинальный запрос с новым токеном
return axios(originalRequest);
} catch (refreshError) {
console.error("Token refresh failed:", refreshError);

// Необходимо перенаправить на страницу логина
return Promise.reject(refreshError);
}
}
Expand Down
16 changes: 8 additions & 8 deletions frontend/src/components/auth/login/components/auth-style.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
.auth-page-wrapper {
background: linear-gradient(
315deg,
rgba(238, 223, 94, 1) 0%,
rgba(40, 158, 127, 1) 16%,
rgba(11, 137, 142, 1) 33%,
rgba(0, 212, 255, 1) 50%,
rgba(255, 150, 150, 1) 66%,
rgba(153, 102, 204, 1) 83%,
rgba(0, 75, 160, 1) 91%,
rgba(255, 120, 80, 1) 100%
rgba(58, 80, 45, 1) 0%,
rgba(85, 110, 67, 1) 16%,
rgba(3, 106, 99, 1) 33%,
rgba(0, 48, 73, 1) 50%,
rgba(179, 57, 57, 1) 66%,
rgba(128, 0, 128, 1) 83%,
rgba(54, 69, 79, 1) 91%,
rgba(153, 92, 56, 1) 100%
);
background-size: 400% 400%; /* Увеличиваем размер градиента для эффекта переливания */
background-attachment: fixed;
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/components/auth/login/components/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ export default function Form() {
try {
localStorage.removeItem("accessToken");
localStorage.removeItem("refreshToken");
localStorage.removeItem("wallet_balance");
localStorage.removeItem("user_id");
const response = await Instance.post("/login/", {
username,
password,
});
localStorage.setItem("accessToken", response.data.access);
localStorage.setItem("refreshToken", response.data.refresh);
localStorage.setItem("wallet_balance", response.data.wallet_balance);
localStorage.setItem("user_id", response.data.id);
navigate("/navigate/garden");
//alert("Приветствуем вас!");
} catch (error) {
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/components/auth/logout/Logout.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import React from "react";
import { useNavigate } from "react-router-dom";
import Instance from "../../api/instance";
import {useBasket} from "../../basket-context/BasketContext";
export default function Logout() {
const navigate = useNavigate();
const {clearBasket} = useBasket();

const handleLogout = async () => {
try {
await Instance.post("/logout/");

localStorage.removeItem("accessToken");
localStorage.removeItem("refreshToken");

clearBasket();
navigate("/");
} catch (error) {
console.error("Ошибка при выходе:", error);
Expand Down
65 changes: 24 additions & 41 deletions frontend/src/components/basket-context/BasketContext.js
Original file line number Diff line number Diff line change
@@ -1,74 +1,57 @@
import React, { createContext, useState, useContext, useEffect } from "react";

// Создаем контекст
const BasketContext = createContext();

// Провайдер контекста для оборачивания компонентов
export const BasketProvider = ({ children }) => {
// Получаем данные из localStorage или начинаем с пустого массива
const loadBasketItems = () => {
const savedItems = localStorage.getItem("basketItems");
return savedItems ? JSON.parse(savedItems) : [];
};

const [basketItems, setBasketItems] = useState(loadBasketItems);

// Сохраняем корзину в localStorage при изменении состояния
// Сохраняем корзину в localStorage при любом изменении состояния
useEffect(() => {
if (basketItems.length > 0) {
localStorage.setItem("basketItems", JSON.stringify(basketItems));
}
localStorage.setItem("basketItems", JSON.stringify(basketItems));
}, [basketItems]);

const addToBasket = (item) => {
const currentDate = new Date().toLocaleDateString("ru-RU"); // Получаем дату в формате "день.месяц.год"
const currentDate = new Date().toLocaleDateString("ru-RU");

setBasketItems((prevItems) => {
const existingItem = prevItems.find((i) => i.id === item.id);
if (existingItem) {
const exists = prevItems.some((i) => i.id === item.id);
if (exists) {
return prevItems.map((i) =>
i.id === item.id
? { ...i, quantity: i.quantity + 1, dateAdded: currentDate } // Добавляем или обновляем дату
: i
i.id === item.id ? { ...i, dateAdded: currentDate } : i
);
}
return [
...prevItems,
{ ...item, quantity: 1, dateAdded: currentDate }, // Добавляем дату добавления
];
return [...prevItems, { ...item, dateAdded: currentDate }];
});
};

// Функция для удаления 1 единицы элемента из корзины
const removeOneFromBasket = (id) => {
setBasketItems((prevItems) => {
const updatedItems = prevItems
.map((item) =>
item.id === id ? { ...item, quantity: item.quantity - 1 } : item
)
.filter((item) => item.quantity > 0); // Убираем элементы с нулевым количеством
return updatedItems;
});
const removeFromBasket = (id) => {
setBasketItems((prevItems) => prevItems.filter((item) => item.id !== id));
};

// Функция для полного удаления элемента из корзины
const removeFromBasket = (id) => {
setBasketItems((prevItems) => prevItems.filter((item) => item.id !== id)); // Удаляем элемент по id
const totalItems = basketItems.length;

const clearBasket = () => {
setBasketItems([]);
};

return (
<BasketContext.Provider
value={{
basketItems,
addToBasket,
removeFromBasket,
removeOneFromBasket,
}}
>
{children}
</BasketContext.Provider>
<BasketContext.Provider
value={{
totalItems,
basketItems,
addToBasket,
removeFromBasket,
clearBasket,
}}
>
{children}
</BasketContext.Provider>
);
};

// Хук для использования контекста
export const useBasket = () => useContext(BasketContext);
29 changes: 18 additions & 11 deletions frontend/src/components/card/Card.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from 'react'
import './style-card.css'
import { useState, useEffect } from 'react'
import Modal from './modal/Modal'
import React from "react";
import "./style-card.css";
import { useState, useEffect } from "react";
import Modal from "./modal/Modal";

export default function Card(props) {
const [modalActive, setModalActive] = useState(false)
const [modalActive, setModalActive] = useState(false);

const [isVisible, setIsVisible] = useState(false);
useEffect(() => {
Expand All @@ -16,14 +17,20 @@ export default function Card(props) {

return (
<>
<div className={`card-wrapper ${isVisible ? 'fade-in' : ''}`} onClick={() => setModalActive(true)}>
<img src={process.env.PUBLIC_URL + '/man.jpg'} alt='Placeholder' />
<div
className={`card-wrapper ${isVisible ? "fade-in" : ""}`}
onClick={() => setModalActive(true)}
>
<img src={process.env.PUBLIC_URL + "/man.jpg"} alt="Placeholder" />
<h2>{props.label}</h2>
<p>{props.description}</p>
</div>
<Modal active={modalActive} setActive={setModalActive}
label={props.label} description={props.description}/>

<Modal
active={modalActive}
setActive={setModalActive}
label={props.label}
description={props.description}
/>
</>
)
);
}
Loading

0 comments on commit 59bd2d4

Please sign in to comment.