From 5dbbbc1c8a37ccb3a00ea8cf058e305d96f152cd Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Sun, 3 May 2026 01:26:23 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20=D9=85=D9=8F=D8=B5=D8=A7=D8=AF?= =?UTF-8?q?=D9=8E=D9=82:=20=D8=AA=D8=AD=D8=AF=D9=8A=D8=AB=20=D8=A8=D8=B1?= =?UTF-8?q?=D9=85=D8=AC=D9=8A=20=D8=AC=D8=AF=D9=8A=D8=AF=202026-05-03=2001?= =?UTF-8?q?:26?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/assets/js/api.js | 2 +- public/shell.php | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/public/assets/js/api.js b/public/assets/js/api.js index 19bd972..779a3da 100644 --- a/public/assets/js/api.js +++ b/public/assets/js/api.js @@ -1,7 +1,7 @@ /** * مُصادَق — API Client with JWT Auth & Refresh Flow */ -const API = { +window.API = { baseUrl: '/Application/public/api.php', accessToken: localStorage.getItem('access_token'), diff --git a/public/shell.php b/public/shell.php index 63f015e..8b34f2b 100644 --- a/public/shell.php +++ b/public/shell.php @@ -231,13 +231,13 @@ const errorEl = document.getElementById('login-error'); try { - const result = await API.post('/auth/login', { email, password }); + const result = await window.API.post('/auth/login', { email, password }); if (result.success) { localStorage.setItem('access_token', result.data.access_token); if (result.data.refresh_token) { localStorage.setItem('refresh_token', result.data.refresh_token); } - API.accessToken = result.data.access_token; + window.API.accessToken = result.data.access_token; navigate(); } } catch (err) { @@ -250,6 +250,25 @@ } } + // ── AI Query Handler ───────────────────────────────────── + document.getElementById('ai-query').addEventListener('keydown', async (e) => { + if (e.key === 'Enter') { + const query = e.target.value; + const answerEl = document.getElementById('ai-answer'); + if (!query) return; + + answerEl.textContent = 'جاري التحليل...'; + e.target.value = ''; + + try { + const res = await window.API.post('/ai/query', { query }); + answerEl.textContent = res.data.answer; + } catch (err) { + answerEl.textContent = 'عذراً، حدث خطأ أثناء معالجة طلبك.'; + } + } + }); + // ── Start the app ──────────────────────────────────────── navigate();