feat: add global chat UI with i18n and translation indicators

This commit is contained in:
Adolfo Reyna
2026-02-20 23:16:05 -05:00
parent 06e620dbf6
commit f92d0fec0b
5 changed files with 228 additions and 4 deletions

26
API.js
View File

@@ -1,10 +1,11 @@
const baseUrl = "https://emiapi.reynafamily.com";
//const baseUrl = "http://localhost:3000";
import i18n from "./i18nMessages.js";
const baseUrl = "http://localhost:3000";
//const baseUrl = "https://emiapi.reynafamily.com";
const requestErrorCooldownMs = 30000;
const profileFailureCooldownMs = 60000;
const recentRequestErrors = {};
const failedProfileCache = {};
const getCurrentLanguage = () => (i18n?.locale || "en").toLowerCase();
const normalizePath = (path = "") => {
return path.replace(/[a-f0-9]{24}/gi, ":id");
@@ -47,6 +48,8 @@ let getCall = async (path = "", params = {}) => {
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept-Language': getCurrentLanguage(),
'x-app-language': getCurrentLanguage(),
}
}).then(async (response) => {
const normalizedPath = normalizePath(path);
@@ -75,6 +78,8 @@ let deleteCall = async (path = "", params = {}) => {
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept-Language': getCurrentLanguage(),
'x-app-language': getCurrentLanguage(),
}
}).then(async (response) => {
const normalizedPath = normalizePath(path);
@@ -100,6 +105,8 @@ let postCall = async (path, params) => {
body: JSON.stringify(params),
headers: {
'Content-Type': 'application/json',
'Accept-Language': getCurrentLanguage(),
'x-app-language': getCurrentLanguage(),
}
}).then(async (response) => {
const normalizedPath = normalizePath(path);
@@ -423,6 +430,19 @@ const API = {
},
paymentRegister(userid, result){
return postCall("/payments/register/", {userid, result});
},
//Chat
getChatMessages(limit = 100) {
return getCall("/chat/messages", { limit, lang: getCurrentLanguage() }).then((data) => Array.isArray(data?.messages) ? data.messages : []);
},
sendChatMessage(text) {
return postCall("/chat/messages", { text, sourceLang: getCurrentLanguage() });
},
getChatActiveUsers() {
return getCall("/chat/active").then((data) => Array.isArray(data?.activeUsers) ? data.activeUsers : []);
},
pingChatPresence() {
return postCall("/chat/ping", {}).then((data) => Array.isArray(data?.activeUsers) ? data.activeUsers : []);
}
}