From e2e509f51de04ea731728796a2f321a4b6530e50 Mon Sep 17 00:00:00 2001 From: FanisNgv Date: Sun, 8 Sep 2024 14:25:21 +0300 Subject: [PATCH 1/3] redesign, again --- frontend/src/app/components/MessageList.tsx | 2 +- frontend/src/app/components/Sidebar.tsx | 50 +++++++++++++----- frontend/src/app/page.tsx | 56 +++++++++++++-------- frontend/src/domain/config/index.tsx | 2 +- 4 files changed, 74 insertions(+), 36 deletions(-) diff --git a/frontend/src/app/components/MessageList.tsx b/frontend/src/app/components/MessageList.tsx index 46a4faa..6ec9e1d 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) => (

История чатов

- - Перейти к поиску - + + + Перейти к поиску + + + - + + Новый чат + +
-
    + {conversations.map((conversation) => ( -
  • + -
  • + ))} -
+
); diff --git a/frontend/src/app/page.tsx b/frontend/src/app/page.tsx index 16a19c1..d3c3763 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() {
-
+
Date: Sun, 8 Sep 2024 17:28:40 +0300 Subject: [PATCH 2/3] redesign #3 --- frontend/src/app/components/MessageList.tsx | 6 +- frontend/src/app/components/Sidebar.tsx | 108 +++++++++++++------- frontend/src/app/globals.css | 12 +++ frontend/src/app/layout.tsx | 4 +- frontend/src/app/page.tsx | 14 ++- 5 files changed, 100 insertions(+), 44 deletions(-) diff --git a/frontend/src/app/components/MessageList.tsx b/frontend/src/app/components/MessageList.tsx index 6ec9e1d..a53848b 100644 --- a/frontend/src/app/components/MessageList.tsx +++ b/frontend/src/app/components/MessageList.tsx @@ -21,9 +21,11 @@ export default function MessageList({ messages }: MessageListProps) { animate={{ opacity: 1, y: 0 }} exit={{ opacity: 0 }} transition={{ duration: 0.5 }} - className={`mb-4 ${msg.sender === 'user' ? 'text-right' : 'text-left'}`} + className={`mb-4 ${msg.sender === 'user' ? 'flex justify-end' : ''}`} > -
+
{msg.text}
diff --git a/frontend/src/app/components/Sidebar.tsx b/frontend/src/app/components/Sidebar.tsx index 69e616c..1e7eefa 100644 --- a/frontend/src/app/components/Sidebar.tsx +++ b/frontend/src/app/components/Sidebar.tsx @@ -23,62 +23,96 @@ export default function Sidebar({ conversations, currentConversationId, onConver ref={menuRef} className="w-64 h-screen bg-[#17153B] flex flex-col overflow-hidden" > +

AFANA

+
-

История чатов

+

История чатов

- Перейти к поиску +

+ Перейти к поиску +

-
- - {conversations.map((conversation) => ( - - - - - ))} - + + + ))} + +
); diff --git a/frontend/src/app/globals.css b/frontend/src/app/globals.css index 91ec545..13b9d83 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: "SF Pro Display", -apple-system, BlinkMacSystemFont, "Helvetica", sans-serif; +} + +* { + font-family: "SF Pro Display", -apple-system, BlinkMacSystemFont, "Helvetica", sans-serif; +} + +body, input, button, textarea, select { + font-family: "SF Pro Display", -apple-system, BlinkMacSystemFont, "Helvetica", 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 d3c3763..67b815d 100644 --- a/frontend/src/app/page.tsx +++ b/frontend/src/app/page.tsx @@ -178,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' }} />
From 63768d87842e929e6656e49e3854f538b06deafa Mon Sep 17 00:00:00 2001 From: FanisNgv Date: Sun, 8 Sep 2024 18:10:27 +0300 Subject: [PATCH 3/3] search page particularly redesigned --- frontend/src/app/api.tsx | 15 +++++++++++++-- frontend/src/app/globals.css | 6 +++--- frontend/src/app/search/page.tsx | 21 ++++++++++++++------- 3 files changed, 30 insertions(+), 12 deletions(-) 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/globals.css b/frontend/src/app/globals.css index 13b9d83..8c1045b 100644 --- a/frontend/src/app/globals.css +++ b/frontend/src/app/globals.css @@ -42,13 +42,13 @@ body { } body, input, button, textarea { - font-family: "SF Pro Display", -apple-system, BlinkMacSystemFont, "Helvetica", sans-serif; + font-family: "Inter", sans-serif; } * { - font-family: "SF Pro Display", -apple-system, BlinkMacSystemFont, "Helvetica", sans-serif; + font-family: "Inter", sans-serif; } body, input, button, textarea, select { - font-family: "SF Pro Display", -apple-system, BlinkMacSystemFont, "Helvetica", sans-serif; + font-family: "Inter", sans-serif; } \ No newline at end of file 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" />