Update frontend/src/App.js
Browse files- frontend/src/App.js +12 -9
frontend/src/App.js
CHANGED
@@ -30,7 +30,7 @@ useEffect(() => {
|
|
30 |
|
31 |
fetchConversations();
|
32 |
|
33 |
-
console.log("Role
|
34 |
}
|
35 |
}, []);
|
36 |
|
@@ -57,6 +57,10 @@ useEffect(() => {
|
|
57 |
console.error('Erreur:', error);
|
58 |
}
|
59 |
};
|
|
|
|
|
|
|
|
|
60 |
|
61 |
const loadConversationMessages = async (conversationId) => {
|
62 |
try {
|
@@ -97,7 +101,6 @@ useEffect(() => {
|
|
97 |
let conversationId = activeConversationId;
|
98 |
|
99 |
if (!conversationId) {
|
100 |
-
// Créer une nouvelle conversation
|
101 |
const newChatData = {
|
102 |
title: message.length > 15 ? message.substring(0, 15) + "..." : message,
|
103 |
date: new Date().toLocaleDateString('fr-FR', { day: '2-digit', month: 'short' }),
|
@@ -141,7 +144,7 @@ useEffect(() => {
|
|
141 |
}
|
142 |
} catch (error) {
|
143 |
console.error('Erreur lors de la création de la conversation:', error);
|
144 |
-
return;
|
145 |
}
|
146 |
} else {
|
147 |
try {
|
@@ -162,8 +165,8 @@ useEffect(() => {
|
|
162 |
return conversationId;
|
163 |
};
|
164 |
|
165 |
-
const saveBotResponse = async (conversationId, botResponse) => {
|
166 |
-
if (!conversationId) return;
|
167 |
|
168 |
try {
|
169 |
await fetch(`/api/conversations/${conversationId}/messages`, {
|
@@ -197,7 +200,6 @@ useEffect(() => {
|
|
197 |
};
|
198 |
const handleLogout = async () => {
|
199 |
try {
|
200 |
-
// Appeler l'API de déconnexion
|
201 |
await fetch('/api/logout', {
|
202 |
method: 'POST',
|
203 |
credentials: 'include',
|
@@ -207,7 +209,6 @@ useEffect(() => {
|
|
207 |
localStorage.removeItem('userId');
|
208 |
localStorage.removeItem('userRole');
|
209 |
|
210 |
-
// Réinitialiser l'état
|
211 |
setIsAuthenticated(false);
|
212 |
setUserName('');
|
213 |
setUserRole('');
|
@@ -246,7 +247,7 @@ useEffect(() => {
|
|
246 |
onToggleCollapse={toggleCollapse}
|
247 |
userName={userName}
|
248 |
onLogout={handleLogout}
|
249 |
-
setPage={setPage}
|
250 |
/>
|
251 |
)}
|
252 |
|
@@ -287,7 +288,9 @@ useEffect(() => {
|
|
287 |
saveBotResponse={saveBotResponse}
|
288 |
userName={userName}
|
289 |
toLogin={handleLogout}
|
290 |
-
onNewChat={handleNewChat}
|
|
|
|
|
291 |
|
292 |
/>
|
293 |
}
|
|
|
30 |
|
31 |
fetchConversations();
|
32 |
|
33 |
+
console.log("Role localStorage:", storedUserRole);
|
34 |
}
|
35 |
}, []);
|
36 |
|
|
|
57 |
console.error('Erreur:', error);
|
58 |
}
|
59 |
};
|
60 |
+
|
61 |
+
const refreshConversationList = async () => {
|
62 |
+
await fetchConversations();
|
63 |
+
};
|
64 |
|
65 |
const loadConversationMessages = async (conversationId) => {
|
66 |
try {
|
|
|
101 |
let conversationId = activeConversationId;
|
102 |
|
103 |
if (!conversationId) {
|
|
|
104 |
const newChatData = {
|
105 |
title: message.length > 15 ? message.substring(0, 15) + "..." : message,
|
106 |
date: new Date().toLocaleDateString('fr-FR', { day: '2-digit', month: 'short' }),
|
|
|
144 |
}
|
145 |
} catch (error) {
|
146 |
console.error('Erreur lors de la création de la conversation:', error);
|
147 |
+
return;
|
148 |
}
|
149 |
} else {
|
150 |
try {
|
|
|
165 |
return conversationId;
|
166 |
};
|
167 |
|
168 |
+
const saveBotResponse = async (conversationId, botResponse, shouldSave = false) => {
|
169 |
+
if (!conversationId || !shouldSave) return;
|
170 |
|
171 |
try {
|
172 |
await fetch(`/api/conversations/${conversationId}/messages`, {
|
|
|
200 |
};
|
201 |
const handleLogout = async () => {
|
202 |
try {
|
|
|
203 |
await fetch('/api/logout', {
|
204 |
method: 'POST',
|
205 |
credentials: 'include',
|
|
|
209 |
localStorage.removeItem('userId');
|
210 |
localStorage.removeItem('userRole');
|
211 |
|
|
|
212 |
setIsAuthenticated(false);
|
213 |
setUserName('');
|
214 |
setUserRole('');
|
|
|
247 |
onToggleCollapse={toggleCollapse}
|
248 |
userName={userName}
|
249 |
onLogout={handleLogout}
|
250 |
+
setPage={setPage}
|
251 |
/>
|
252 |
)}
|
253 |
|
|
|
288 |
saveBotResponse={saveBotResponse}
|
289 |
userName={userName}
|
290 |
toLogin={handleLogout}
|
291 |
+
onNewChat={handleNewChat}
|
292 |
+
refreshConversationList={refreshConversationList}
|
293 |
+
|
294 |
|
295 |
/>
|
296 |
}
|