diff --git a/src/App.jsx b/src/App.jsx index 46a7e57..8cc8083 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -8,6 +8,8 @@ export default function App() { const [editing, setEditing] = useState(null); const [showForm, setShowForm] = useState(false); + const [sortOrder, setSortOrder] = useState('asc'); + const handleAdd = () => { setEditing(null); setShowForm(true); }; const handleEdit = prod => { setEditing(prod); setShowForm(true); }; const handleDelete = id => remove(id); @@ -17,12 +19,21 @@ export default function App() { }; const handleCancel = () => setShowForm(false); + const sortedProducts = [...products].sort((a, b) => + sortOrder === 'asc' + ? a.price - b.price + : b.price - a.price + ); + + const toggleSortOrder = () => setSortOrder(prev => prev === 'asc' ? 'desc' : 'asc'); + return (
{/*

Каталог товаров

*/} - {showForm && } - + + {showForm && } +
); } \ No newline at end of file diff --git a/src/components/ProductForm.jsx b/src/components/ProductForm.jsx index 0538c32..9f3c04b 100644 --- a/src/components/ProductForm.jsx +++ b/src/components/ProductForm.jsx @@ -1,6 +1,6 @@ import React, { useState, useEffect } from 'react'; -export default function ProductForm({ initial, onSave, onCancel }) { +export default function ProductForm({ initial, onSave, onCancel, mode }) { const [form, setForm] = useState({ name: '', price: '' }); useEffect(() => { @@ -17,6 +17,9 @@ export default function ProductForm({ initial, onSave, onCancel }) { return (
+

+ {mode === 'edit' ? 'Редактирование товара' : 'Добавление товара'} +

diff --git a/Отчет4.docx b/Отчет4.docx new file mode 100644 index 0000000..6465016 Binary files /dev/null and b/Отчет4.docx differ diff --git a/Отчет5.docx b/Отчет5.docx new file mode 100644 index 0000000..52c0839 Binary files /dev/null and b/Отчет5.docx differ