From 7f1ea28b1ff9b87765e5fa0e0fdda5cd0a01e625 Mon Sep 17 00:00:00 2001 From: Eduard Kuzmenko Date: Thu, 19 Nov 2020 05:37:15 +0200 Subject: [PATCH] Hide recent search & top peers if empty --- src/components/appSearch.ts | 8 ++++++++ src/components/sidebarLeft/index.ts | 20 ++++++++++++-------- src/components/wrappers.ts | 4 ++-- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/components/appSearch.ts b/src/components/appSearch.ts index 6e4e429e..134a089f 100644 --- a/src/components/appSearch.ts +++ b/src/components/appSearch.ts @@ -48,6 +48,14 @@ export class SearchGroup { setActive() { this.container.style.display = ''; } + + toggle() { + if(this.list.childElementCount) { + this.setActive(); + } else { + this.clear(); + } + } } /** diff --git a/src/components/sidebarLeft/index.ts b/src/components/sidebarLeft/index.ts index acbc2b4f..856a4fea 100644 --- a/src/components/sidebarLeft/index.ts +++ b/src/components/sidebarLeft/index.ts @@ -174,7 +174,7 @@ export class AppSidebarLeft extends SidebarSlider { this.globalSearch = new AppSearch(this.searchContainer, this.searchInput, this.searchGroups, (count) => { if(!count && !this.searchInput.value.trim()) { this.globalSearch.reset(); - this.searchGroups.people.setActive(); + this.searchGroups.people.toggle(); this.renderRecentSearch(); } }); @@ -215,11 +215,13 @@ export class AppSidebarLeft extends SidebarSlider { appUsersManager.getTopPeers().then(peers => { //console.log('got top categories:', categories); - peers.forEach((peerID) => { - let {dialog, dom} = appDialogsManager.addDialog(peerID, this.searchGroups.people.list, false, true, true); - - this.searchGroups.people.setActive(); - }); + if(peers.length) { + peers.forEach((peerID) => { + appDialogsManager.addDialog(peerID, this.searchGroups.people.list, false, true, true); + }); + } + + this.searchGroups.people.toggle(); }); let hideNewBtnMenuTimeout: number; @@ -246,7 +248,7 @@ export class AppSidebarLeft extends SidebarSlider { transition(1); if(firstTime) { - this.searchGroups.people.setActive(); + this.searchGroups.people.toggle(); this.renderRecentSearch(); firstTime = false; } @@ -350,7 +352,9 @@ export class AppSidebarLeft extends SidebarSlider { dom.lastMessageSpan.innerText = peerID > 0 ? appUsersManager.getUserStatusString(peerID) : appChatsManager.getChatMembersString(peerID); }); - if(setActive) { + if(!this.recentSearch.length) { + this.searchGroups.recent.clear(); + } else if(setActive) { this.searchGroups.recent.setActive(); } }); diff --git a/src/components/wrappers.ts b/src/components/wrappers.ts index f60ae6d3..44af37c8 100644 --- a/src/components/wrappers.ts +++ b/src/components/wrappers.ts @@ -692,9 +692,9 @@ export function wrapSticker({doc, div, middleware, lazyLoadQueue, group, play, o img.classList.add('fade-in-transition'); img.style.opacity = '0'; - if(!div.firstElementChild) { + /* if(!div.firstElementChild) { div.append(img); - } + } */ img.addEventListener('load', () => { doc.downloaded = true;