From 02ad29e64b66230c49bc9919997908fb4a9a9453 Mon Sep 17 00:00:00 2001 From: dosai Date: Sat, 1 Nov 2025 20:18:57 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BD=D0=B0=D0=B2=D0=B8=D0=B3=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BC=D0=B5=D0=B6=D0=B4=D1=83=20=D0=BA=D0=B0?= =?UTF-8?q?=D0=BB=D1=8C=D0=BA=D1=83=D0=BB=D1=8F=D1=82=D0=BE=D1=80=D0=B0?= =?UTF-8?q?=D0=BC=D0=B8=20=D0=B8=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B0?= =?UTF-8?q?=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Добавлен компонент CalculatorNav для переключения между калькуляторами - Навигация сохраняет chat_id при переходах - Исправлен endpoint API (используется правильный путь с типом калькулятора) - Пересобран frontend для применения изменений --- frontend/app/[calculator]/layout.tsx | 11 +++++ frontend/app/page.tsx | 7 ++- frontend/components/CalculatorNav.tsx | 54 +++++++++++++++++++++++ frontend/components/DynamicCalculator.tsx | 4 ++ frontend/components/SoapCalculator.tsx | 2 +- 5 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 frontend/app/[calculator]/layout.tsx create mode 100644 frontend/components/CalculatorNav.tsx diff --git a/frontend/app/[calculator]/layout.tsx b/frontend/app/[calculator]/layout.tsx new file mode 100644 index 0000000..499faff --- /dev/null +++ b/frontend/app/[calculator]/layout.tsx @@ -0,0 +1,11 @@ +// app/[calculator]/layout.tsx +// Layout для страниц калькуляторов с сохранением chat_id + +export default function CalculatorLayout({ + children, +}: { + children: React.ReactNode; +}) { + return <>{children}; +} + diff --git a/frontend/app/page.tsx b/frontend/app/page.tsx index d3c321d..627a143 100644 --- a/frontend/app/page.tsx +++ b/frontend/app/page.tsx @@ -1,6 +1,11 @@ +// app/page.tsx +// Главная страница с выбором калькулятора + import { redirect } from 'next/navigation'; +import { getAvailableCalculators } from '@/lib/calculators'; export default function Home() { - // Редирект на калькулятор мыла по умолчанию + // Редирект на калькулятор мыла по умолчанию, если есть chat_id + // Иначе показываем список калькуляторов redirect('/soap'); } diff --git a/frontend/components/CalculatorNav.tsx b/frontend/components/CalculatorNav.tsx new file mode 100644 index 0000000..605f0fc --- /dev/null +++ b/frontend/components/CalculatorNav.tsx @@ -0,0 +1,54 @@ +// components/CalculatorNav.tsx +// Навигация между калькуляторами + +'use client'; + +import { usePathname, useSearchParams } from 'next/navigation'; + +export default function CalculatorNav() { + const pathname = usePathname(); + const searchParams = useSearchParams(); + const chatId = searchParams.get('chat_id'); + + // Сохраняем chat_id при переходах + const queryString = chatId ? `?chat_id=${chatId}` : ''; + + const calculators = [ + { id: 'soap', name: 'Мыло' }, + { id: 'candle', name: 'Свеча' }, + ]; + + const handleCalculatorChange = (calcId: string) => { + window.location.href = `/${calcId}${queryString}`; + }; + + return ( +
+

+ Выберите калькулятор: +

+
+ {calculators.map((calc) => { + const isActive = pathname === `/${calc.id}`; + + return ( + + ); + })} +
+
+ ); +} + diff --git a/frontend/components/DynamicCalculator.tsx b/frontend/components/DynamicCalculator.tsx index 652694f..184751b 100644 --- a/frontend/components/DynamicCalculator.tsx +++ b/frontend/components/DynamicCalculator.tsx @@ -8,6 +8,7 @@ import Image from 'next/image'; import { getCalculator } from '@/lib/calculators'; import { submitCalculator } from '@/lib/api'; import FormField from './FormField'; +import CalculatorNav from './CalculatorNav'; import type { Calculator } from '@/types/calculator'; interface DynamicCalculatorProps { @@ -215,6 +216,9 @@ export default function DynamicCalculator({ calculatorType }: DynamicCalculatorP /> + {/* Навигация между калькуляторами */} + + {/* Предупреждение о chat_id */} {chatId === null && (
diff --git a/frontend/components/SoapCalculator.tsx b/frontend/components/SoapCalculator.tsx index 683ed81..47296d4 100644 --- a/frontend/components/SoapCalculator.tsx +++ b/frontend/components/SoapCalculator.tsx @@ -162,7 +162,7 @@ export default function SoapCalculator() { } try { - const res = await fetch(`${API_BASE_URL}/api/submit`, { + const res = await fetch(`${API_BASE_URL}/api/submit/soap`, { method: 'POST', body: formData, });