퍼팩트 당구장

최고의 당구 경험을 제공합니다

로그인

) { console.error('Login error:', error); } } // 탭 전환 function showTab(tabName) { // 모든 탭 컨텐츠 숨기기 const tabContents = document.querySelectorAll('.tab-content'); tabContents.forEach(content => content.classList.add('hidden')); // 모든 탭 버튼 비활성화 const tabs = document.querySelectorAll('.tab'); tabs.forEach(tab => tab.classList.remove('active')); // 선택된 탭 보이기 document.getElementById(tabName).classList.remove('hidden'); // 클릭된 탭 버튼 활성화 const clickedTab = Array.from(tabs).find(tab => tab.textContent.includes(getTabName(tabName))); if (clickedTab) { clickedTab.classList.add('active'); } } // 탭 이름 매핑 function getTabName(tabId) { const tabNames = { 'members': '회원목록', 'chat': '채팅', 'shorts': '쇼트영상', 'info': '당구장정보' }; return tabNames[tabId] || tabId; } // 회원목록 로드 async function loadMembers() { try { const response = await fetch('api.php?request=members'); const members = await response.json(); const membersList = document.getElementById('membersList'); membersList.innerHTML = ''; members.forEach(member => { const memberCard = document.createElement('div'); memberCard.className = 'member-card'; memberCard.innerHTML = `

${member.nickname}

점수: ${member.score}

전화: ${member.phone}

`; membersList.appendChild(memberCard); }); } catch (error) { console.error('Error loading members:', error); } } // 채팅 메시지 로드 async function loadChatMessages() { try { const response = await fetch('api.php?request=chat'); const messages = await response.json(); const chatContainer = document.getElementById('chatContainer'); chatContainer.innerHTML = ''; messages.forEach(message => { const messageDiv = document.createElement('div'); messageDiv.className = 'chat-message'; messageDiv.innerHTML = ` ${message.nickname}: ${message.message} ${new Date(message.timestamp).toLocaleTimeString()} `; chatContainer.appendChild(messageDiv); }); chatContainer.scrollTop = chatContainer.scrollHeight; } catch (error) { console.error('Error loading chat messages:', error); } } // 메시지 전송 async function sendMessage() { if (!currentUser) return; const chatInput = document.getElementById('chatInput'); const message = chatInput.value.trim(); if (!message) return; try { const response = await fetch('api.php?request=chat', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ phone: currentUser.phone, nickname: currentUser.nickname, message: message }) }); const result = await response.json(); if (result.success) { chatInput.value = ''; loadChatMessages(); } } catch (error) { console.error('Error sending message:', error); } } // 쇼트 영상 로드 async function loadShorts() { try { const response = await fetch('api.php?request=shorts'); const shorts = await response.json(); const shortsGrid = document.getElementById('shortsGrid'); shortsGrid.innerHTML = ''; shorts.forEach(short => { const shortCard = document.createElement('div'); shortCard.className = 'short-card'; shortCard.innerHTML = `

${short.title}

${short.nickname}

⭐ ${parseFloat(short.avg_rating || 0).toFixed(1)} (${short.rating_count})

댓글: ${short.comment_count}

조회수: ${short.views}

${new Date(short.created_at).toLocaleDateString()}
`; shortsGrid.appendChild(shortCard); }); } catch (error) { console.error('Error loading shorts:', error); } } // 쇼트 영상 업로드 async function uploadShort() { if (!currentUser) return; const title = document.getElementById('shortTitle').value; const videoUrl = document.getElementById('shortUrl').value; if (!title || !videoUrl) { alert('제목과 영상 URL을 입력해주세요.'); return; } try { const response = await fetch('api.php?request=shorts', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ phone: currentUser.phone, nickname: currentUser.nickname, title: title, video_url: videoUrl }) }); const result = await response.json(); if (result.success) { document.getElementById('shortTitle').value = ''; document.getElementById('shortUrl').value = ''; loadShorts(); } } catch (error