hide messages

This commit is contained in:
Andrey Kondratev
2025-11-10 17:22:10 +05:00
parent 21a32ffc79
commit cd2c3b6989
3 changed files with 71 additions and 6 deletions

View File

@@ -1026,7 +1026,7 @@ class QuixoticApp {
// Remove existing message if any
const existingMessage = document.querySelector('.tg-status-message');
if (existingMessage) {
existingMessage.remove();
this.hideMessage(existingMessage as HTMLElement);
}
// Create message element
@@ -1034,15 +1034,37 @@ class QuixoticApp {
messageEl.className = `tg-status-message tg-status-message--${type}`;
messageEl.textContent = message;
// Add click handler to dismiss
let hideTimeout: NodeJS.Timeout;
const hideHandler = () => {
clearTimeout(hideTimeout);
this.hideMessage(messageEl);
};
messageEl.addEventListener('click', hideHandler);
// Add to body (fixed position, won't affect layout)
document.body.appendChild(messageEl);
// Auto-remove after 5 seconds
// Auto-remove after 3 seconds (было 5)
hideTimeout = setTimeout(() => {
if (messageEl.parentNode) {
this.hideMessage(messageEl);
}
}, 3000);
}
private hideMessage(messageEl: HTMLElement): void {
// Add hiding class for fade-out animation
messageEl.classList.add('tg-status-message--hiding');
// Remove after animation completes (300ms)
setTimeout(() => {
if (messageEl.parentNode) {
messageEl.remove();
}
}, 5000);
}, 300);
}
private escapeHtml(text: string): string {
@@ -1133,13 +1155,27 @@ class QuixoticApp {
this.stopAudioPreview();
});
// Play audio
await this.currentAudio.play();
this.triggerHaptic('light');
// Play audio with autoplay error handling
try {
await this.currentAudio.play();
this.triggerHaptic('light');
} catch (playError: any) {
console.error('Autoplay error:', playError);
// If autoplay is blocked, show message and clean up
if (playError.name === 'NotAllowedError') {
this.stopAudioPreview();
item.classList.remove('tg-list-item--loading-preview');
this.showMessage('🔇 Воспроизведение заблокировано. Нажмите еще раз.', 'warning');
return;
}
throw playError;
}
} catch (error) {
console.error('Preview error:', error);
item.classList.remove('tg-list-item--loading-preview');
this.stopAudioPreview();
this.showMessage('❌ Не удалось воспроизвести превью', 'error');
}
}