Update frontend/src/components/Panel.jsx
Browse files- frontend/src/components/Panel.jsx +147 -118
frontend/src/components/Panel.jsx
CHANGED
@@ -1,118 +1,147 @@
|
|
1 |
-
import React from 'react';
|
2 |
-
import '../App.css';
|
3 |
-
|
4 |
-
const Panel = ({
|
5 |
-
conversations = [],
|
6 |
-
setConversations = () => {},
|
7 |
-
activeConversationId,
|
8 |
-
setActiveConversationId,
|
9 |
-
onToggleCollapse,
|
10 |
-
isCollapsed,
|
11 |
-
onNewChat
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
const
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
<
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
</
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import React from 'react';
|
2 |
+
import '../App.css';
|
3 |
+
|
4 |
+
const Panel = ({
|
5 |
+
conversations = [],
|
6 |
+
setConversations = () => {},
|
7 |
+
activeConversationId,
|
8 |
+
setActiveConversationId,
|
9 |
+
onToggleCollapse,
|
10 |
+
isCollapsed,
|
11 |
+
onNewChat,
|
12 |
+
userName, // Nouvelle prop pour le nom d'utilisateur
|
13 |
+
onLogout // Nouvelle prop pour la fonction de déconnexion
|
14 |
+
}) => {
|
15 |
+
|
16 |
+
|
17 |
+
|
18 |
+
// Fonctions existantes
|
19 |
+
const createNewChat = () => {
|
20 |
+
onNewChat();
|
21 |
+
};
|
22 |
+
|
23 |
+
const deleteConversation = async (conversationId) => {
|
24 |
+
try {
|
25 |
+
const response = await fetch(`http://localhost:7860/api/conversations/${conversationId}`, {
|
26 |
+
method: 'DELETE',
|
27 |
+
credentials: 'include',
|
28 |
+
});
|
29 |
+
|
30 |
+
if (response.ok) {
|
31 |
+
// Supprimer la conversation localement
|
32 |
+
setConversations(prev => prev.filter(chat => chat.id !== conversationId));
|
33 |
+
|
34 |
+
// Si la conversation active est supprimée, réinitialiser
|
35 |
+
if (activeConversationId === conversationId) {
|
36 |
+
setActiveConversationId(null);
|
37 |
+
}
|
38 |
+
}
|
39 |
+
} catch (error) {
|
40 |
+
console.error('Erreur lors de la suppression:', error);
|
41 |
+
}
|
42 |
+
};
|
43 |
+
|
44 |
+
return (
|
45 |
+
<div className={`sidebar-panel ${isCollapsed ? 'collapsed' : ''}`}>
|
46 |
+
<div className="sidebar-header">
|
47 |
+
{!isCollapsed && (
|
48 |
+
<>
|
49 |
+
<button className="collapse-button" onClick={onToggleCollapse}>
|
50 |
+
{/* SVG existant */}
|
51 |
+
<svg
|
52 |
+
fill="#FFFF"
|
53 |
+
width="20"
|
54 |
+
height="20"
|
55 |
+
viewBox="0 0 32 32"
|
56 |
+
xmlns="http://www.w3.org/2000/svg"
|
57 |
+
>
|
58 |
+
<defs>
|
59 |
+
<style>{`.cls-1{fill:none;}`}</style>
|
60 |
+
</defs>
|
61 |
+
<title>open-panel--solid--left</title>
|
62 |
+
<path d="M28,4H4A2,2,0,0,0,2,6V26a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V6A2,2,0,0,0,28,4Zm0,22H12V6H28Z" />
|
63 |
+
<rect
|
64 |
+
id="_Transparent_Rectangle_"
|
65 |
+
data-name="<Transparent Rectangle>"
|
66 |
+
className="cls-1"
|
67 |
+
width="20"
|
68 |
+
height="20"
|
69 |
+
/>
|
70 |
+
</svg>
|
71 |
+
</button>
|
72 |
+
|
73 |
+
{/* Affichage du nom d'utilisateur */}
|
74 |
+
{userName && (
|
75 |
+
<div className="user-info">
|
76 |
+
<span className="username">{userName}</span>
|
77 |
+
<button onClick={onLogout} className="logout-btn">
|
78 |
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
79 |
+
<path d="M8.90002 7.56001C9.21002 3.96001 11.06 2.49001 15.11 2.49001H15.24C19.71 2.49001 21.5 4.28001 21.5 8.75001V15.27C21.5 19.74 19.71 21.53 15.24 21.53H15.11C11.09 21.53 9.24002 20.08 8.91002 16.54" stroke="#FF5252" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round"/>
|
80 |
+
<path d="M15 12H3.62" stroke="#FF5252" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round"/>
|
81 |
+
<path d="M5.85 8.65002L2.5 12L5.85 15.35" stroke="#FF5252" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round"/>
|
82 |
+
</svg>
|
83 |
+
Déconnexion
|
84 |
+
</button>
|
85 |
+
</div>
|
86 |
+
)}
|
87 |
+
</>
|
88 |
+
)}
|
89 |
+
|
90 |
+
<button className="new-chat-button" onClick={createNewChat}>
|
91 |
+
{!isCollapsed && (
|
92 |
+
<span>
|
93 |
+
<svg
|
94 |
+
viewBox="0 0 512 512"
|
95 |
+
xmlns="http://www.w3.org/2000/svg"
|
96 |
+
width="24"
|
97 |
+
height="24"
|
98 |
+
fill="currentColor"
|
99 |
+
>
|
100 |
+
<path d="M495.6 49.23l-32.82-32.82C451.8 5.471 437.5 0 423.1 0c-14.33 0-28.66 5.469-39.6 16.41L167.5 232.5C159.1 240 154.8 249.5 152.4 259.8L128.3 367.2C126.5 376.1 133.4 384 141.1 384c.916 0 1.852-.0918 2.797-.2813c0 0 74.03-15.71 107.4-23.56c10.1-2.377 19.13-7.459 26.46-14.79l217-217C517.5 106.5 517.4 71.1 495.6 49.23zM461.7 94.4L244.7 311.4C243.6 312.5 242.5 313.1 241.2 313.4c-13.7 3.227-34.65 7.857-54.3 12.14l12.41-55.2C199.6 268.9 200.3 267.5 201.4 266.5l216.1-216.1C419.4 48.41 421.6 48 423.1 48s3.715 .4062 5.65 2.342l32.82 32.83C464.8 86.34 464.8 91.27 461.7 94.4zM424 288c-13.25 0-24 10.75-24 24v128c0 13.23-10.78 24-24 24h-304c-13.22 0-24-10.77-24-24v-304c0-13.23 10.78-24 24-24h144c13.25 0 24-10.75 24-24S229.3 64 216 64L71.1 63.99C32.31 63.99 0 96.29 0 135.1v304C0 479.7 32.31 512 71.1 512h303.1c39.69 0 71.1-32.3 71.1-72L448 312C448 298.8 437.3 288 424 288z" />
|
101 |
+
</svg>
|
102 |
+
</span>
|
103 |
+
)}
|
104 |
+
</button>
|
105 |
+
</div>
|
106 |
+
|
107 |
+
{/* Reste du composant inchangé */}
|
108 |
+
<div className="conversations-list">
|
109 |
+
<div className="conversation-today">
|
110 |
+
<h6 className="conversation-today-title">Aujourd'hui</h6>
|
111 |
+
{conversations.map(chat => (
|
112 |
+
<div
|
113 |
+
key={chat.id}
|
114 |
+
className={`conversation-item ${activeConversationId === chat.id ? 'active' : ''}`}
|
115 |
+
onClick={() => setActiveConversationId(chat.id)}
|
116 |
+
>
|
117 |
+
{!isCollapsed && (
|
118 |
+
<>
|
119 |
+
<div className="conversation-icon">
|
120 |
+
<span className="material-icons">{chat.time}</span>
|
121 |
+
</div>
|
122 |
+
<div className="conversation-details">
|
123 |
+
<div className="conversation-title">{chat.title}</div>
|
124 |
+
<div className="conversation-date">{chat.date}</div>
|
125 |
+
</div>
|
126 |
+
<button className="delete-button" onClick={(e) => {
|
127 |
+
e.stopPropagation();
|
128 |
+
deleteConversation(chat.id);
|
129 |
+
}}>
|
130 |
+
<span>
|
131 |
+
<svg width="15px" height="15px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" stroke="#ff0000"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path d="M10 12V17" stroke="#ff0000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path> <path d="M14 12V17" stroke="#ff0000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path> <path d="M4 7H20" stroke="#ff0000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path> <path d="M6 10V18C6 19.6569 7.34315 21 9 21H15C16.6569 21 18 19.6569 18 18V10" stroke="#ff0000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path> <path d="M9 5C9 3.89543 9.89543 3 11 3H13C14.1046 3 15 3.89543 15 5V7H9V5Z" stroke="#ff0000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path> </g></svg>
|
132 |
+
</span>
|
133 |
+
</button>
|
134 |
+
</>
|
135 |
+
)}
|
136 |
+
</div>
|
137 |
+
))}
|
138 |
+
</div>
|
139 |
+
<div className="conversation-before">
|
140 |
+
<h6 className="conversation-before-title">Les 30 derniers jours</h6>
|
141 |
+
</div>
|
142 |
+
</div>
|
143 |
+
</div>
|
144 |
+
);
|
145 |
+
};
|
146 |
+
|
147 |
+
export default Panel;
|