some visual fixes

This commit is contained in:
Andrey Kondratev
2025-08-29 18:11:04 +05:00
parent 8e3c927cf1
commit 9bdf522f59
4 changed files with 32 additions and 28 deletions

View File

@@ -45,6 +45,7 @@ class QuixoticApp {
private results!: HTMLElement;
private noResults!: HTMLElement;
private welcomePlaceholder!: HTMLElement;
private searchTimeout?: NodeJS.Timeout;
constructor() {
this.tg = (window as WindowWithTelegram).Telegram?.WebApp;
@@ -76,17 +77,35 @@ class QuixoticApp {
}
private bindEvents(): void {
this.searchBtn.addEventListener('click', () => this.search());
this.searchInput.addEventListener('keypress', (e: KeyboardEvent) => {
if (e.key === 'Enter') {
this.search();
// Auto search with debounce timeout
this.searchInput.addEventListener('input', () => {
// Clear previous timeout
if (this.searchTimeout) {
clearTimeout(this.searchTimeout);
}
const query = this.searchInput.value.trim();
// If input is empty, reset to welcome state immediately
if (query === '') {
this.resetToWelcomeState();
return;
}
// Set new timeout for search (500ms delay)
this.searchTimeout = setTimeout(() => {
this.search();
}, 500);
});
// Reset to welcome state when input is cleared
this.searchInput.addEventListener('input', () => {
if (this.searchInput.value.trim() === '') {
this.resetToWelcomeState();
// Still handle Enter key for immediate search
this.searchInput.addEventListener('keypress', (e: KeyboardEvent) => {
if (e.key === 'Enter') {
// Clear timeout and search immediately
if (this.searchTimeout) {
clearTimeout(this.searchTimeout);
}
this.search();
}
});
}
@@ -104,8 +123,7 @@ class QuixoticApp {
this.noResults.classList.add('tg-hidden');
this.noResults.style.display = 'none';
// Enable search button
this.searchBtn.disabled = false;
}
private async search(): Promise<void> {
@@ -159,7 +177,7 @@ class QuixoticApp {
this.noResults.classList.add('tg-hidden');
this.noResults.style.display = 'none';
this.searchBtn.disabled = true;
}
private hideLoading(): void {
@@ -272,13 +290,6 @@ class QuixoticApp {
if (data.audioUrl) {
if (this.tg) {
// Try WebApp method first (might not work)
const payload = {
action: 'send_audio',
audioUrl: data.audioUrl,
title: title
};
const userId = this.tg?.initDataUnsafe?.user?.id;
if (!userId) {
this.showMessage('❌ Ошибка: не удается определить пользователя', 'error');
@@ -302,7 +313,7 @@ class QuixoticApp {
} else {
this.showMessage('❌ Ошибка отправки в Telegram', 'error');
}
} catch (directError) {
} catch {
this.showMessage('❌ Ошибка соединения с ботом', 'error');
}
} else {