forked from snxraven/LinkUp-P2P-Chat
Add the beginnings of guilds
This commit is contained in:
191
index.html
191
index.html
@ -17,10 +17,10 @@
|
||||
</header>
|
||||
<main>
|
||||
<div id="sidebar">
|
||||
<ul id="room-list">
|
||||
<!-- Room list will be populated dynamically -->
|
||||
<ul id="guild-list" class="list-group">
|
||||
<!-- Guild list will be populated dynamically -->
|
||||
</ul>
|
||||
<button id="toggle-setup-btn">Create/Join Room</button>
|
||||
<button id="toggle-setup-btn">Create/Join Guild</button>
|
||||
</div>
|
||||
<div id="content">
|
||||
<div id="register" class="hidden">
|
||||
@ -35,12 +35,12 @@
|
||||
<div id="user-info">
|
||||
<!-- User info will be populated dynamically -->
|
||||
</div>
|
||||
<button id="create-chat-room">Create Room</button>
|
||||
<button id="create-guild-btn">Create Guild</button>
|
||||
<div id="or">- or -</div>
|
||||
<div id="join-chat-room-container">
|
||||
<label for="connection-topic">Topic:</label>
|
||||
<input type="text" id="join-chat-room-topic" placeholder="connection topic">
|
||||
<button id="join-chat-room">Join Room</button>
|
||||
<div id="join-guild-container">
|
||||
<label for="join-guild-topic">Guild Topic:</label>
|
||||
<input type="text" id="join-guild-topic" placeholder="guild topic">
|
||||
<button id="join-guild">Join Guild</button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="chat" class="hidden">
|
||||
@ -49,11 +49,10 @@
|
||||
<div style="display: inline;">
|
||||
<strong><span id="chat-room-name"></span></strong> | <a href="#" id="copy-topic-link" class="mini-button">Copy Topic</a>
|
||||
<span id="chat-room-topic" style="display: none;"></span>
|
||||
<span id="chat-guild-topic" style="display: none;"></span>
|
||||
<span id="chat-guild-name" style="display: none;"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div id="user-list">
|
||||
<!-- User list will be populated here -->
|
||||
</div>
|
||||
</div>
|
||||
<div id="messages-container">
|
||||
<div id="messages"></div>
|
||||
@ -62,7 +61,7 @@
|
||||
<textarea id="message" rows="4"></textarea>
|
||||
<input type="file" id="file-input" style="display:none;">
|
||||
<button type="button" id="attach-file">Attach File</button>
|
||||
<button type="button" id="talk-btn">Talk</button> <!-- New Talk button -->
|
||||
<button type="button" id="talk-btn">Talk</button>
|
||||
<input type="submit" value="Send" />
|
||||
</form>
|
||||
<button id="remove-room-btn">Leave Room</button>
|
||||
@ -70,11 +69,46 @@
|
||||
<div id="loading" class="hidden">Loading ...</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<!-- Create Guild Modal -->
|
||||
<div id="create-guild-modal" class="modal hidden">
|
||||
<div class="modal-content">
|
||||
<span class="close-btn" id="close-create-guild-modal">×</span>
|
||||
<h2>Create Guild</h2>
|
||||
<form id="create-guild-form">
|
||||
<label for="guild-name">Guild Name:</label>
|
||||
<input type="text" id="guild-name" required>
|
||||
<button type="submit">Create</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Manage Guild Modal -->
|
||||
<div id="manage-guild-modal" class="modal hidden">
|
||||
<div class="modal-content">
|
||||
<span class="close-btn" id="close-manage-guild-modal">×</span>
|
||||
<h2>Manage Guild</h2>
|
||||
<div id="guild-info">
|
||||
<!-- Guild info will be populated dynamically -->
|
||||
</div>
|
||||
<button id="copy-guild-id" class="mini-button">Copy Guild ID</button>
|
||||
<form id="add-room-form">
|
||||
<label for="room-name">Room Name:</label>
|
||||
<input type="text" id="room-name" required>
|
||||
<button type="submit">Add Room</button>
|
||||
</form>
|
||||
<ul id="room-list">
|
||||
<!-- Room list will be populated dynamically -->
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const messageInput = document.getElementById('message');
|
||||
const copyTopicLink = document.getElementById('copy-topic-link');
|
||||
const chatRoomTopic = document.getElementById('chat-room-topic');
|
||||
const copyGuildIdButton = document.getElementById('copy-guild-id');
|
||||
|
||||
if (messageInput) {
|
||||
messageInput.addEventListener('keydown', function(event) {
|
||||
@ -101,32 +135,123 @@
|
||||
});
|
||||
}
|
||||
|
||||
const switchRoom = (topic) => {
|
||||
console.log('Switching to room:', topic); // Debugging log
|
||||
const chatRoomTopic = document.querySelector('#chat-room-topic');
|
||||
const chatRoomName = document.querySelector('#chat-room-name');
|
||||
if (copyGuildIdButton) {
|
||||
copyGuildIdButton.addEventListener('click', function(event) {
|
||||
event.preventDefault();
|
||||
const guildTopic = document.getElementById('manage-guild-modal').dataset.guildTopic;
|
||||
navigator.clipboard.writeText(guildTopic).then(() => {
|
||||
console.log('Guild ID copied to clipboard:', guildTopic);
|
||||
}).catch(err => {
|
||||
console.error('Failed to copy guild ID:', err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (chatRoomTopic) {
|
||||
chatRoomTopic.innerText = topic; // Set full topic here
|
||||
} else {
|
||||
console.error('Element #chat-room-topic not found');
|
||||
}
|
||||
|
||||
// Show chat UI elements
|
||||
document.querySelector('#chat').classList.remove('hidden');
|
||||
document.querySelector('#setup').classList.add('hidden');
|
||||
};
|
||||
|
||||
const roomList = document.querySelector('#room-list');
|
||||
if (roomList) {
|
||||
roomList.addEventListener('click', function(event) {
|
||||
const roomItem = event.target.closest('li');
|
||||
const guildList = document.querySelector('#guild-list');
|
||||
if (guildList) {
|
||||
guildList.addEventListener('click', function(event) {
|
||||
const roomItem = event.target.closest('.room-item');
|
||||
if (roomItem) {
|
||||
switchRoom(roomItem.dataset.topic);
|
||||
const guildTopic = roomItem.dataset.guildTopic;
|
||||
const roomTopic = roomItem.dataset.topic;
|
||||
switchRoom(guildTopic, roomTopic);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const createGuildBtn = document.getElementById('create-guild-btn');
|
||||
const createGuildModal = document.getElementById('create-guild-modal');
|
||||
const closeCreateGuildModal = document.getElementById('close-create-guild-modal');
|
||||
const createGuildForm = document.getElementById('create-guild-form');
|
||||
|
||||
createGuildBtn.addEventListener('click', () => {
|
||||
createGuildModal.classList.remove('hidden');
|
||||
});
|
||||
|
||||
closeCreateGuildModal.addEventListener('click', () => {
|
||||
createGuildModal.classList.add('hidden');
|
||||
});
|
||||
|
||||
createGuildForm.addEventListener('submit', (event) => {
|
||||
event.preventDefault();
|
||||
const guildName = document.getElementById('guild-name').value.trim();
|
||||
if (guildName) {
|
||||
createGuild(guildName);
|
||||
createGuildModal.classList.add('hidden');
|
||||
}
|
||||
});
|
||||
|
||||
const joinGuildBtn = document.getElementById('join-guild');
|
||||
joinGuildBtn.addEventListener('click', async (event) => {
|
||||
const guildTopic = document.getElementById('join-guild-topic').value.trim();
|
||||
if (guildTopic) {
|
||||
await processGuild(guildTopic);
|
||||
}
|
||||
});
|
||||
|
||||
const manageGuildModal = document.getElementById('manage-guild-modal');
|
||||
const closeManageGuildModal = document.getElementById('close-manage-guild-modal');
|
||||
const addRoomForm = document.getElementById('add-room-form');
|
||||
const roomNameInput = document.getElementById('room-name');
|
||||
|
||||
closeManageGuildModal.addEventListener('click', () => {
|
||||
manageGuildModal.classList.add('hidden');
|
||||
});
|
||||
|
||||
addRoomForm.addEventListener('submit', (event) => {
|
||||
event.preventDefault();
|
||||
const roomName = roomNameInput.value.trim();
|
||||
const guildTopic = manageGuildModal.dataset.guildTopic;
|
||||
if (roomName && guildTopic) {
|
||||
addRoomToGuild(guildTopic, roomName);
|
||||
roomNameInput.value = '';
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function createGuild(guildName) {
|
||||
const event = new CustomEvent('createGuild', { detail: { guildName } });
|
||||
document.dispatchEvent(event);
|
||||
}
|
||||
|
||||
function addRoomToGuild(guildTopic, roomName) {
|
||||
const event = new CustomEvent('addRoomToGuild', { detail: { guildTopic, roomName } });
|
||||
document.dispatchEvent(event);
|
||||
}
|
||||
|
||||
function manageGuild(guildTopic) {
|
||||
const event = new CustomEvent('manageGuild', { detail: { guildTopic } });
|
||||
document.dispatchEvent(event);
|
||||
}
|
||||
|
||||
function switchRoom(guildTopic, roomTopic) {
|
||||
const event = new CustomEvent('switchRoom', { detail: { guildTopic, roomTopic } });
|
||||
document.dispatchEvent(event);
|
||||
}
|
||||
|
||||
function openManageGuildModal(guildTopic) {
|
||||
const manageGuildModal = document.getElementById('manage-guild-modal');
|
||||
const guildInfo = document.getElementById('guild-info');
|
||||
const roomList = document.getElementById('room-list');
|
||||
|
||||
manageGuildModal.dataset.guildTopic = guildTopic;
|
||||
guildInfo.innerHTML = `<h3>${config.guilds[guildTopic].alias}</h3>`;
|
||||
roomList.innerHTML = '';
|
||||
|
||||
config.guilds[guildTopic].rooms.forEach(room => {
|
||||
const roomItem = document.createElement('li');
|
||||
roomItem.textContent = room.alias;
|
||||
roomItem.dataset.guildTopic = guildTopic;
|
||||
roomItem.dataset.topic = room.topic;
|
||||
|
||||
roomItem.addEventListener('dblclick', () => enterEditMode(roomItem, guildTopic));
|
||||
roomItem.addEventListener('click', () => switchRoom(guildTopic, room.topic));
|
||||
|
||||
roomList.appendChild(roomItem);
|
||||
});
|
||||
|
||||
manageGuildModal.classList.remove('hidden');
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
Reference in New Issue
Block a user