diff --git a/frontend/src/app/api.tsx b/frontend/src/app/api.tsx index 7f1210f..651d3fe 100644 --- a/frontend/src/app/api.tsx +++ b/frontend/src/app/api.tsx @@ -1,9 +1,13 @@ import { API_URL } from "../domain/config"; export const api = { - async createConversation() { + async createConversation(userId: string) { const response = await fetch(`${API_URL}/conversation/create`, { method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ user_id: userId }), }); return response.json(); }, @@ -14,7 +18,7 @@ export const api = { headers: { 'Content-Type': 'application/json', }, - body: JSON.stringify({ conversation_id: conversationId, message }), + body: JSON.stringify({ conversation_id: conversationId, message:message }), }); return response.json(); }, @@ -25,4 +29,11 @@ export const api = { }); return response.json(); }, + + async getUserConversations(userId: string) { + const response = await fetch(`${API_URL}/conversation/user/${userId}`, { + method: 'GET', + }); + return response.json(); + }, }; \ No newline at end of file diff --git a/frontend/src/app/components/MessageList.tsx b/frontend/src/app/components/MessageList.tsx index 46a4faa..a53848b 100644 --- a/frontend/src/app/components/MessageList.tsx +++ b/frontend/src/app/components/MessageList.tsx @@ -12,7 +12,7 @@ type MessageListProps = { export default function MessageList({ messages }: MessageListProps) { return ( -
+
{messages.map((msg) => ( -
+
{msg.text}
diff --git a/frontend/src/app/components/Sidebar.tsx b/frontend/src/app/components/Sidebar.tsx index 5b959dc..1e7eefa 100644 --- a/frontend/src/app/components/Sidebar.tsx +++ b/frontend/src/app/components/Sidebar.tsx @@ -1,5 +1,6 @@ import { useRef } from 'react'; import Link from 'next/link'; +import { motion, AnimatePresence } from 'framer-motion'; type Conversation = { id: number; @@ -20,41 +21,98 @@ export default function Sidebar({ conversations, currentConversationId, onConver return ( ); diff --git a/frontend/src/app/globals.css b/frontend/src/app/globals.css index 91ec545..8c1045b 100644 --- a/frontend/src/app/globals.css +++ b/frontend/src/app/globals.css @@ -39,4 +39,16 @@ body { .hide-scrollbar::-webkit-scrollbar { display: none; +} + +body, input, button, textarea { + font-family: "Inter", sans-serif; +} + +* { + font-family: "Inter", sans-serif; +} + +body, input, button, textarea, select { + font-family: "Inter", sans-serif; } \ No newline at end of file diff --git a/frontend/src/app/layout.tsx b/frontend/src/app/layout.tsx index d6777db..fb7ea61 100644 --- a/frontend/src/app/layout.tsx +++ b/frontend/src/app/layout.tsx @@ -1,8 +1,10 @@ import type { Metadata } from "next"; +import { Roboto_Mono } from "next/font/google"; import { Inter } from "next/font/google"; import "./globals.css"; -const inter = Inter({ subsets: ["latin"] }); +const robotoMono = Roboto_Mono({ subsets: ["latin", "cyrillic"], weight: ['400', '700'], display: 'swap' }); +const inter = Inter({ subsets: ["latin", "cyrillic"] }); export const metadata: Metadata = { title: "afana-propdoc", diff --git a/frontend/src/app/page.tsx b/frontend/src/app/page.tsx index 16a19c1..67b815d 100644 --- a/frontend/src/app/page.tsx +++ b/frontend/src/app/page.tsx @@ -1,12 +1,11 @@ "use client"; -import { useState, useRef, useEffect } from 'react'; -import { motion, AnimatePresence } from 'framer-motion'; -import Link from 'next/link'; + +import { useState, useEffect } from 'react'; +import { v4 as uuidv4 } from 'uuid'; import { api } from './api'; import Sidebar from './components/Sidebar'; import MessageList from './components/MessageList'; - type Conversation = { id: number; name: string; @@ -15,24 +14,39 @@ type Conversation = { export default function Home() { const [conversations, setConversations] = useState([]); + const [currentConversationId, setCurrentConversationId] = useState(null); const [message, setMessage] = useState(''); const [messages, setMessages] = useState>([]); - const [currentConversationId, setCurrentConversationId] = useState(null); + const [userId, setUserId] = useState(null); useEffect(() => { - const createInitialChat = async () => { - if (conversations.length === 0) { - try { + const initializeUser = async () => { + let storedUserId = localStorage.getItem('userId'); + + if (!storedUserId) { + storedUserId = uuidv4(); + localStorage.setItem('userId', storedUserId); + } + + setUserId(storedUserId); + + try { + const userConversations = await api.getUserConversations(storedUserId); + if (userConversations.length > 0) { + setConversations(userConversations); + setCurrentConversationId(userConversations[0].id); + setMessages(userConversations[0].messages); + } else { const newConversation = await handleAddConversation(); setConversations([newConversation]); setCurrentConversationId(newConversation.id); - } catch (error) { - console.error('Ошибка при создании начального чата:', error); } + } catch (error) { + console.error('Ошибка при инициализации пользователя:', error); } }; - createInitialChat(); + initializeUser(); }, []); const handleSendMessage = async () => { @@ -40,13 +54,11 @@ export default function Home() { try { if (currentConversationId === null) { - await handleAddConversation(); - } - - if (currentConversationId === null) { - throw new Error('Не удалось создать или выбрать чат'); + const newConversation = await handleAddConversation(); + if (!newConversation) { + throw new Error('Не удалось создать новый чат'); + } } - const newMessage = { id: messages.length + 1, text: message, @@ -63,11 +75,13 @@ export default function Home() { ); const response = await api.sendMessage(currentConversationId!, message); + if (!response.task_id) { throw new Error('Ошибка при отправке сообщения'); } console.log('Сообщение успешно отправлено, task_id:', response.task_id); + setMessage(''); let botResponse; do { @@ -92,7 +106,6 @@ export default function Home() { ); } - setMessage(''); } catch (error) { console.error('Произошла ошибка:', error); setMessage(''); @@ -115,10 +128,11 @@ export default function Home() { const handleAddConversation = async () => { try { - const response = await api.createConversation(); + if (!userId) throw new Error('UserId не определен'); + const response = await api.createConversation(userId); if (response.conversation_id) { const newConversation = { - id: conversations.length + 1, + id: response.conversation_id, name: `Чат ${conversations.length + 1}`, messages: [] }; @@ -164,7 +178,7 @@ export default function Home() {
-
+
setMessage(e.target.value)} onKeyDown={handleKeyDown} placeholder="Введите ваш вопрос" - className="flex-grow p-2 border border-gray-300 rounded-l-2xl focus:outline-none" + className="flex-grow p-2 bg-gray-300 border border-gray-300 rounded-l-2xl focus:outline-none" style={{ color: 'black' }} />
diff --git a/frontend/src/app/search/page.tsx b/frontend/src/app/search/page.tsx index 4a22a9f..18efc92 100644 --- a/frontend/src/app/search/page.tsx +++ b/frontend/src/app/search/page.tsx @@ -11,15 +11,22 @@ export default function Search() { return (
-
+
-

Поиск документов

- - Вернуться на главную - +

Поиск по документам

+ + + + Вернуться на главную + + +
-
+
@@ -28,7 +35,7 @@ export default function Search() { type="text" id="Search" placeholder="Искать..." - className="w-full rounded-md border-gray-200 py-2.5 pe-10 shadow-sm sm:text-sm" + className="w-full rounded-full p-4 focus:outline-none py-2.5 text-black" /> diff --git a/frontend/src/domain/config/index.tsx b/frontend/src/domain/config/index.tsx index 0fbccde..02d1c08 100644 --- a/frontend/src/domain/config/index.tsx +++ b/frontend/src/domain/config/index.tsx @@ -1,3 +1,3 @@ -const API_URL = 'http://localhost:5000'; +const API_URL = process.env.NEXT_PUBLIC_API_URL ?? 'http://localhost:5000'; export { API_URL }; \ No newline at end of file