diff --git a/backend/handlers/item_handlers.go b/backend/handlers/item_handlers.go
index 0bff0bd..77246ab 100644
--- a/backend/handlers/item_handlers.go
+++ b/backend/handlers/item_handlers.go
@@ -91,7 +91,7 @@ func DeleteItem(c *gin.Context) {
func GetCategories(c *gin.Context) {
var item models.Item
- var categories []string
+ categories := make([]string, 0)
err := database.DB.Model(&item).Where("category IS NOT NULL AND category != ''").Distinct().Pluck("category", &categories).Error
if err != nil {
diff --git a/frontend/src/api/index.js b/frontend/src/api/index.js
index 14c6330..cc51a59 100644
--- a/frontend/src/api/index.js
+++ b/frontend/src/api/index.js
@@ -37,4 +37,4 @@ export const updateItem = (id, itemData) =>
export const deleteItem = (id) => axios.delete(`${API_URL}/items/${id}`);
-export const getAllCategories = () => axios.get(`${API_URL}/getCategory`)
+export const getAllCategories = () => axios.get(`${API_URL}/getCategories`)
diff --git a/frontend/src/components/CardItem.jsx b/frontend/src/components/CardItem.jsx
new file mode 100644
index 0000000..99a7e77
--- /dev/null
+++ b/frontend/src/components/CardItem.jsx
@@ -0,0 +1,80 @@
+import { useState } from 'react';
+
+export default function CardItem({ item, onAddToCart }) {
+ // Начальный вес — 100 грамм (0.100 кг)
+ const [weight, setWeight] = useState(0.100);
+
+ // Увеличение веса с шагом 100 грамм
+ const handleIncrement = () => {
+ setWeight((prev) => parseFloat((prev + 0.100).toFixed(3)));
+ };
+
+ // Уменьшение веса (не позволяет опуститься ниже минимальных 100 грамм)
+ const handleDecrement = () => {
+ setWeight((prev) => (prev > 0.100 ? parseFloat((prev - 0.100).toFixed(3)) : 0.100));
+ };
+
+ return (
+
+
+ {/* Заглушка для изображения товара */}
+
+
+
+ Изображение товара
+
+
+
+ {/* Блок с информацией о товаре */}
+
+
+
{item.name}
+ {item.origin &&
{item.origin}
}
+
+
+
+ {Number(item.price || 0).toLocaleString('ru-RU')} ₽
+
+ / {item.unit || 'кг'}
+
+
+
+ {/* Инпут управления весом и кнопка добавления */}
+
+
+ {/* Шаговый переключатель веса */}
+
+
+
+ {weight.toFixed(3)}
+
+
+
+
+ {/* Кнопка действия "В корзину" */}
+
+
+
+
+ );
+}
diff --git a/frontend/src/components/CategoryTabs.jsx b/frontend/src/components/CategoryTabs.jsx
new file mode 100644
index 0000000..9e0dd2b
--- /dev/null
+++ b/frontend/src/components/CategoryTabs.jsx
@@ -0,0 +1,38 @@
+import PropTypes from "prop-types";
+
+export default function CategoryTabs({
+ categories,
+ activeCategory,
+ onSelectCategory,
+}) {
+ return (
+
+
+ {categories.map((cat) => (
+
+ ))}
+
+ );
+}
+
+CategoryTabs.propTypes = {
+ categories: PropTypes.arrayOf(PropTypes.string).isRequired,
+ activeCategory: PropTypes.string.isRequired,
+ onSelectCategory: PropTypes.func.isRequired,
+};
diff --git a/frontend/src/pages/Shop.jsx b/frontend/src/pages/Shop.jsx
index efb935d..d24eea3 100644
--- a/frontend/src/pages/Shop.jsx
+++ b/frontend/src/pages/Shop.jsx
@@ -1,6 +1,8 @@
import PageLayout from "../components/PageLayout";
import * as api from "../api/index";
import { useState, useEffect } from "react";
+import CategoryTabs from "../components/CategoryTabs";
+import CardItem from "../components/CardItem";
export default function Shop() {
const [items, setItems] = useState([]);
@@ -10,29 +12,43 @@ export default function Shop() {
useEffect(() => {
Promise.all([api.getAllItems(), api.getAllCategories()])
- .then((itemsRes, categoriesRes) => {
- setItems(itemsRes.data);
- setCategories(categoriesRes.data);
+ .then(([itemsRes, categoriesRes]) => {
+ setItems(itemsRes?.data || []);
+ setCategories(categoriesRes?.data || []);
setLoading(false);
})
.catch((err) => {
console.error("Ошибка при загрузке товара", err);
+ alert(err);
setLoading(false);
});
}, []);
const filteredItems =
activeCategory === "all"
- ? items
- : items.fitler(
- (item) =>
- item.category?.toLowerCase() === activeCategory.toLowerCase(),
- );
+ ? items || []
+ : (items || []).filter((item) => {
+ if (!item || !item.category) return false;
+
+ return item.category.toLowerCase() === activeCategory.toLowerCase();
+ });
+
+ const handleAddToCart = (product, selectedWeight) => {
+ console.log(`Добавлен товар ${product.name}, Вес ${selectedWeight} кг`);
+ };
return (
-
+ Ассортимент
+
+ {filteredItems.map((item) => (
+
+ ))}
);