parent
0c0aaa7048
commit
e4cc833ccc
4 changed files with 143 additions and 1 deletions
|
|
@ -1049,13 +1049,46 @@ function renderSounds(sounds) {
|
|||
sounds.forEach(sound => {
|
||||
const item = document.createElement('div');
|
||||
item.className = 'sound-item';
|
||||
|
||||
// Only show delete button if user is creator or owner
|
||||
const canDelete = state.user && (state.user.id === sound.created_by_user_id || (state.guilds.find(g => g.id === state.selectedGuildId)?.owner_user_id === state.user.id));
|
||||
|
||||
item.innerHTML = `
|
||||
<div class="sound-icon">${sound.icon}</div>
|
||||
<div class="sound-name">${sound.name}</div>
|
||||
${canDelete ? `<button class="sound-delete" title="Delete sound"><i data-lucide="x"></i></button>` : ''}
|
||||
`;
|
||||
item.onclick = () => playRemoteSound(sound.file_path);
|
||||
|
||||
item.onclick = (e) => {
|
||||
if (e.target.closest('.sound-delete')) {
|
||||
e.stopPropagation();
|
||||
if (confirm(`Are you sure you want to delete "${sound.name}"?`)) {
|
||||
deleteSound(sound.id);
|
||||
}
|
||||
return;
|
||||
}
|
||||
playRemoteSound(sound.file_path);
|
||||
};
|
||||
|
||||
el.soundboardGrid.appendChild(item);
|
||||
});
|
||||
lucide.createIcons();
|
||||
}
|
||||
|
||||
async function deleteSound(soundId) {
|
||||
if (!state.selectedGuildId) return;
|
||||
try {
|
||||
const response = await fetch(`/guilds/${state.selectedGuildId}/sounds/${soundId}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
if (!response.ok) {
|
||||
const err = await response.json();
|
||||
throw new Error(err.error || 'Delete failed');
|
||||
}
|
||||
await loadSounds();
|
||||
} catch (err) {
|
||||
alert(err.message);
|
||||
}
|
||||
}
|
||||
|
||||
function playRemoteSound(url) {
|
||||
|
|
|
|||
|
|
@ -729,6 +729,32 @@ select {
|
|||
transform: scale(0.95);
|
||||
}
|
||||
|
||||
.sound-delete {
|
||||
position: absolute;
|
||||
top: 4px;
|
||||
right: 4px;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
border-radius: 50%;
|
||||
background: rgba(0, 0, 0, 0.6);
|
||||
color: var(--text-muted);
|
||||
display: grid;
|
||||
place-items: center;
|
||||
opacity: 0;
|
||||
transition: all var(--transition);
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.sound-delete:hover {
|
||||
background: var(--danger);
|
||||
color: #fff;
|
||||
transform: scale(1.1);
|
||||
}
|
||||
|
||||
.sound-item:hover .sound-delete {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.sound-icon {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue