Commit 6d88756f authored by Mahmoud Aglan's avatar Mahmoud Aglan

fix: opponent bar friend request shows feedback + opens profile

- Add friend button shows success/already-sent/already-friends status
- Profile button navigates to player profile view
- Report button shows confirmation before dismissing
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 1ae4c0ac
......@@ -5,6 +5,7 @@ import * as net from './net.js';
import * as store from './store.js';
import * as audio from './audio.js';
import * as juice from './juice.js';
import * as scene from './scene.js';
import { emoji } from './theme.js';
let currentMatchId = null;
......@@ -66,20 +67,30 @@ function showOpponentActions(container, opponent) {
menu.appendChild(style);
menu.querySelector('[data-action="friend"]').addEventListener('click', async () => {
await addFriendFromGame(opponent.id);
menu.querySelector('[data-action="friend"]').textContent = '✓ تم الإرسال';
const btn = menu.querySelector('[data-action="friend"]');
btn.style.opacity = '0.5';
btn.style.pointerEvents = 'none';
const result = await addFriendFromGame(opponent.id);
if (result === true) {
btn.textContent = '✓ تم الإرسال';
btn.style.color = '#34D399';
} else {
btn.textContent = result || '✓ مرسل سابقاً';
btn.style.color = '#64748b';
}
juice.hapticLight();
setTimeout(() => menu.remove(), 1000);
setTimeout(() => menu.remove(), 1500);
});
menu.querySelector('[data-action="report"]').addEventListener('click', () => {
reportOpponent(opponent.id);
menu.remove();
menu.querySelector('[data-action="report"]').textContent = '✓ تم الإبلاغ';
setTimeout(() => menu.remove(), 1000);
});
menu.querySelector('[data-action="profile"]').addEventListener('click', () => {
menu.remove();
// Could navigate to profile scene
scene.push('profile-view', { playerId: opponent.id });
});
// Close on outside click
......@@ -184,10 +195,19 @@ export function checkForRematch(gameState, myUserId) {
// ========== FRIEND ADD ==========
export async function addFriendFromGame(opponentId) {
try {
await net.post('friends.php', { action: 'request', target_id: opponentId });
const res = await net.post('friends.php', { action: 'request', target_id: opponentId });
if (res.error) {
if (res.error.includes('Already friends')) return 'صديق بالفعل';
if (res.error.includes('pending')) return 'مرسل سابقاً';
return res.error;
}
juice.hapticLight();
return true;
} catch (e) { return false; }
} catch (e) {
const msg = e.message || '';
if (msg.includes('Already') || msg.includes('pending')) return 'مرسل سابقاً';
return false;
}
}
// ========== REPORT ==========
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment