Mark-Lasfar commited on
Commit
654af81
·
1 Parent(s): 0644199
Files changed (2) hide show
  1. static/css/chat/style.css +14 -56
  2. static/js/chat.js +31 -25
static/css/chat/style.css CHANGED
@@ -1,63 +1,21 @@
1
- /*
2
- * SPDX-FileCopyrightText: Hadad <hadad@linuxmail.org>
3
- * SPDX-License-Identifier: Apache-2.0
4
- */
5
-
6
- .chat-title {
7
- font-weight: 700;
8
- font-size: 1rem;
9
- color: #e6eefc;
10
- display: flex;
11
- align-items: center;
12
- gap: 0.5rem;
13
- text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
14
- white-space: nowrap;
15
- overflow: hidden;
16
- text-overflow: ellipsis;
17
- }
18
-
19
- html {
20
- -webkit-text-size-adjust: 100%;
21
- }
22
- .chat-controls {
23
- display: flex;
24
- align-items: center;
25
- gap: 0.5rem;
26
  }
27
 
28
- .chat-section {
29
- display: flex;
30
- flex-direction: column;
31
- width: 100%;
32
- height: 100%;
33
  }
34
 
35
- #chatArea {
36
- flex: 1;
37
- display: flex;
38
- flex-direction: column;
39
- overflow-y: auto;
40
- width: 100%;
41
- height: 100%;
42
- box-sizing: border-box;
43
- overflow-wrap: break-word;
44
- word-wrap: break-word;
45
- word-break: break-word;
46
- max-width: 100%;
47
- opacity: 1 !important; /* إضافة لضمان الظهور */
48
  }
49
 
50
- #chatBox {
51
- display: flex;
52
- flex-direction: column;
53
- width: 100%;
54
- height: 100%;
55
- overflow-y: auto;
56
- padding: 0.75rem 0.75rem calc(var(--footer-height) + 1rem) 1rem;
57
- box-sizing: border-box;
58
- max-width: 100%;
59
- overflow-wrap: break-word;
60
- word-wrap: break-word;
61
- word-break: break-word;
62
- opacity: 1 !important; /* إضافة لضمان الظهور */
63
  }
 
1
+ #chatArea {
2
+ display: flex !important;
3
+ opacity: 1 !important;
4
+ visibility: visible !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  }
6
 
7
+ #chatBox {
8
+ display: flex !important;
9
+ opacity: 1 !important;
10
+ visibility: visible !important;
 
11
  }
12
 
13
+ #footerForm {
14
+ display: flex !important;
15
+ opacity: 1 !important;
16
+ visibility: visible !important;
 
 
 
 
 
 
 
 
 
17
  }
18
 
19
+ .hidden {
20
+ display: none !important;
 
 
 
 
 
 
 
 
 
 
 
21
  }
static/js/chat.js CHANGED
@@ -4,12 +4,12 @@
4
  // Prism for code highlighting
5
  Prism.plugins.autoloader.languages_path = 'https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/';
6
 
7
- // UI elements
8
  const uiElements = {
9
- chatArea: document.getElementById('chatArea'),
10
- chatBox: document.getElementById('chatBox'),
11
- initialContent: document.getElementById('initialContent'),
12
- form: document.getElementById('footerForm'),
13
  input: document.getElementById('userInput'),
14
  sendBtn: document.getElementById('sendBtn'),
15
  stopBtn: document.getElementById('stopBtn'),
@@ -49,7 +49,7 @@ let currentAssistantText = '';
49
  let isSidebarOpen = window.innerWidth >= 768;
50
  let abortController = null;
51
 
52
- // Initialize AOS and load initial conversation
53
  document.addEventListener('DOMContentLoaded', async () => {
54
  AOS.init({
55
  duration: 800,
@@ -58,19 +58,20 @@ document.addEventListener('DOMContentLoaded', async () => {
58
  offset: 50,
59
  });
60
 
 
 
 
61
  if (await checkAuth() && currentConversationId) {
62
  console.log('Loading conversation with ID:', currentConversationId);
63
  await loadConversation(currentConversationId);
64
  } else if (!(await checkAuth()) && conversationHistory.length > 0) {
65
  console.log('Restoring conversation history from sessionStorage:', conversationHistory);
66
- enterChatView();
67
  conversationHistory.forEach(msg => {
68
  console.log('Adding message from history:', msg);
69
  addMsg(msg.role, msg.content);
70
  });
71
  } else {
72
  console.log('No conversation history or ID, starting fresh');
73
- enterChatView(); // تأكيد إظهار المحادثة حتى لو فارغة
74
  }
75
 
76
  autoResizeTextarea();
@@ -162,11 +163,11 @@ function renderMarkdown(el) {
162
  behavior: 'smooth',
163
  });
164
  }
165
- el.style.display = 'block'; // إجبار عرض الفقاعة
166
  }
167
 
168
- // Toggle chat view
169
- function enterChatView() {
170
  if (uiElements.chatHeader) {
171
  uiElements.chatHeader.classList.remove('hidden');
172
  uiElements.chatHeader.setAttribute('aria-hidden', 'false');
@@ -176,19 +177,28 @@ function enterChatView() {
176
  }
177
  if (uiElements.chatArea) {
178
  uiElements.chatArea.classList.remove('hidden');
179
- uiElements.chatArea.style.display = 'flex';
180
  uiElements.chatArea.style.opacity = '1';
 
181
  }
182
  if (uiElements.chatBox) {
183
  uiElements.chatBox.classList.remove('hidden');
184
- uiElements.chatBox.style.display = 'flex';
185
  uiElements.chatBox.style.opacity = '1';
 
186
  }
187
  if (uiElements.initialContent) uiElements.initialContent.classList.add('hidden');
188
  if (uiElements.form) {
189
  uiElements.form.classList.remove('hidden');
190
- uiElements.form.style.display = 'flex';
 
 
191
  }
 
 
 
 
 
192
  }
193
 
194
  // Toggle home view
@@ -212,9 +222,10 @@ function addMsg(who, text) {
212
  div.style.display = 'block';
213
  if (uiElements.chatBox) {
214
  uiElements.chatBox.appendChild(div);
215
- uiElements.chatBox.scrollTop = uiElements.chatBox.scrollHeight; // تمرير تلقائي
216
  } else {
217
- console.error('chatBox is not found in DOM');
 
218
  }
219
  return div;
220
  }
@@ -240,7 +251,7 @@ function clearAllMessages() {
240
  currentConversationId = null;
241
  currentConversationTitle = null;
242
  if (uiElements.conversationTitle) uiElements.conversationTitle.textContent = 'MGZon AI Assistant';
243
- enterChatView(); // تأكيد إظهار المحادثة بعد المسح
244
  autoResizeTextarea();
245
  }
246
 
@@ -452,7 +463,7 @@ function handleRequestError(error) {
452
  uiElements.sendBtn.disabled = false;
453
  }
454
  if (uiElements.stopBtn) uiElements.stopBtn.style.display = 'none';
455
- enterChatView(); // إعادة إظهار المحادثة بعد الخطأ
456
  }
457
 
458
  // Load conversations for sidebar
@@ -700,12 +711,7 @@ async function submitMessage() {
700
  return;
701
  }
702
 
703
- // إظهار واجهة المحادثة عند أول رسالة
704
- if (uiElements.initialContent && !uiElements.initialContent.classList.contains('hidden')) {
705
- enterChatView();
706
- } else {
707
- enterChatView(); // تأكيد إظهار المحادثة في كل مرة
708
- }
709
 
710
  if (uiElements.fileInput?.files.length > 0) {
711
  const file = uiElements.fileInput.files[0];
@@ -843,7 +849,7 @@ function stopStream(forceCancel = false) {
843
  if (uiElements.stopBtn) uiElements.stopBtn.style.display = 'none';
844
  if (uiElements.sendBtn) uiElements.sendBtn.style.display = 'inline-flex';
845
  if (uiElements.stopBtn) uiElements.stopBtn.style.pointerEvents = 'auto';
846
- enterChatView(); // إعادة إظهار المحادثة بعد الإلغاء
847
  }
848
 
849
  // Logout handler
 
4
  // Prism for code highlighting
5
  Prism.plugins.autoloader.languages_path = 'https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/';
6
 
7
+ // UI elements with fallback check
8
  const uiElements = {
9
+ chatArea: document.getElementById('chatArea') || document.createElement('div'),
10
+ chatBox: document.getElementById('chatBox') || document.createElement('div'),
11
+ initialContent: document.getElementById('initialContent') || document.createElement('div'),
12
+ form: document.getElementById('footerForm') || document.createElement('form'),
13
  input: document.getElementById('userInput'),
14
  sendBtn: document.getElementById('sendBtn'),
15
  stopBtn: document.getElementById('stopBtn'),
 
49
  let isSidebarOpen = window.innerWidth >= 768;
50
  let abortController = null;
51
 
52
+ // Forcefully initialize chat view on load
53
  document.addEventListener('DOMContentLoaded', async () => {
54
  AOS.init({
55
  duration: 800,
 
58
  offset: 50,
59
  });
60
 
61
+ // Force chat view to be visible immediately
62
+ enterChatView(true);
63
+
64
  if (await checkAuth() && currentConversationId) {
65
  console.log('Loading conversation with ID:', currentConversationId);
66
  await loadConversation(currentConversationId);
67
  } else if (!(await checkAuth()) && conversationHistory.length > 0) {
68
  console.log('Restoring conversation history from sessionStorage:', conversationHistory);
 
69
  conversationHistory.forEach(msg => {
70
  console.log('Adding message from history:', msg);
71
  addMsg(msg.role, msg.content);
72
  });
73
  } else {
74
  console.log('No conversation history or ID, starting fresh');
 
75
  }
76
 
77
  autoResizeTextarea();
 
163
  behavior: 'smooth',
164
  });
165
  }
166
+ el.style.display = 'block';
167
  }
168
 
169
+ // Toggle chat view with force option
170
+ function enterChatView(force = false) {
171
  if (uiElements.chatHeader) {
172
  uiElements.chatHeader.classList.remove('hidden');
173
  uiElements.chatHeader.setAttribute('aria-hidden', 'false');
 
177
  }
178
  if (uiElements.chatArea) {
179
  uiElements.chatArea.classList.remove('hidden');
180
+ uiElements.chatArea.style.display = force ? 'flex !important' : 'flex';
181
  uiElements.chatArea.style.opacity = '1';
182
+ uiElements.chatArea.style.visibility = 'visible';
183
  }
184
  if (uiElements.chatBox) {
185
  uiElements.chatBox.classList.remove('hidden');
186
+ uiElements.chatBox.style.display = force ? 'flex !important' : 'flex';
187
  uiElements.chatBox.style.opacity = '1';
188
+ uiElements.chatBox.style.visibility = 'visible';
189
  }
190
  if (uiElements.initialContent) uiElements.initialContent.classList.add('hidden');
191
  if (uiElements.form) {
192
  uiElements.form.classList.remove('hidden');
193
+ uiElements.form.style.display = force ? 'flex !important' : 'flex';
194
+ uiElements.form.style.opacity = '1';
195
+ uiElements.form.style.visibility = 'visible';
196
  }
197
+ console.log('Chat view forced to enter:', {
198
+ chatArea: uiElements.chatArea?.style.display,
199
+ chatBox: uiElements.chatBox?.style.display,
200
+ form: uiElements.form?.style.display
201
+ });
202
  }
203
 
204
  // Toggle home view
 
222
  div.style.display = 'block';
223
  if (uiElements.chatBox) {
224
  uiElements.chatBox.appendChild(div);
225
+ uiElements.chatBox.scrollTop = uiElements.chatBox.scrollHeight;
226
  } else {
227
+ console.error('chatBox not found, appending to a fallback container');
228
+ document.body.appendChild(div); // فال باك إذا فشل العثور
229
  }
230
  return div;
231
  }
 
251
  currentConversationId = null;
252
  currentConversationTitle = null;
253
  if (uiElements.conversationTitle) uiElements.conversationTitle.textContent = 'MGZon AI Assistant';
254
+ enterChatView();
255
  autoResizeTextarea();
256
  }
257
 
 
463
  uiElements.sendBtn.disabled = false;
464
  }
465
  if (uiElements.stopBtn) uiElements.stopBtn.style.display = 'none';
466
+ enterChatView();
467
  }
468
 
469
  // Load conversations for sidebar
 
711
  return;
712
  }
713
 
714
+ enterChatView(); // دايمًا إظهار المحادثة قبل الإرسال
 
 
 
 
 
715
 
716
  if (uiElements.fileInput?.files.length > 0) {
717
  const file = uiElements.fileInput.files[0];
 
849
  if (uiElements.stopBtn) uiElements.stopBtn.style.display = 'none';
850
  if (uiElements.sendBtn) uiElements.sendBtn.style.display = 'inline-flex';
851
  if (uiElements.stopBtn) uiElements.stopBtn.style.pointerEvents = 'auto';
852
+ enterChatView();
853
  }
854
 
855
  // Logout handler