fix(front,back) Добавил на бек выгрузку категорий, начало разработки shop

This commit is contained in:
2026-06-09 15:42:18 +03:00
parent ea70e6914e
commit 04b1be4c54
5 changed files with 57 additions and 5 deletions
+12
View File
@@ -1,6 +1,18 @@
import PageLayout from "../components/PageLayout";
import { useState, useEffect } from "react"
import * as api from '../api/index'
export default function Shop() {
const [items, setItems] = useState([])
const [loading, setLoading] = useState(true);
useEffect(() => {
pa
})
return (
<PageLayout>
<main className="px-16 grow w-full">
+29 -5
View File
@@ -1,14 +1,38 @@
import PageLayout from "../components/PageLayout";
import * as api from "../api/index";
import { useState, useEffect } from "react";
export default function Shop() {
const [items, setItems] = useState([]);
const [categories, setCategories] = useState([]);
const [activeCategory, setActiveCategory] = useState("all");
const [loading, setLoading] = useState(true);
useEffect(() => {
Promise.all([api.getAllItems(), api.getAllCategories()])
.then((itemsRes, categoriesRes) => {
setItems(itemsRes.data);
setCategories(categoriesRes.data);
setLoading(false);
})
.catch((err) => {
console.error("Ошибка при загрузке товара", err);
setLoading(false);
});
}, []);
const filteredItems =
activeCategory === "all"
? items
: items.fitler(
(item) =>
item.category?.toLowerCase() === activeCategory.toLowerCase(),
);
return (
<PageLayout>
<main className="px-16 grow w-full">
<div className="flex flex-row text-white">
<div className="text-4xl flex-col">
<h1 className="uppercase">fish fish</h1>
</div>
</div>
<div className="flex flex-row text-white"></div>
</main>
</PageLayout>
);