From fa73477a9e05326c9607d52f58f01f4a07b672a8 Mon Sep 17 00:00:00 2001 From: morethanwords Date: Mon, 15 Jun 2020 14:21:40 +0300 Subject: [PATCH] Fix add members --- src/components/sidebarLeft/addMembers.ts | 16 +++++++++++----- src/components/sidebarLeft/newGroup.ts | 19 ++++++++----------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/components/sidebarLeft/addMembers.ts b/src/components/sidebarLeft/addMembers.ts index 1f0a5f1d..41d0b926 100644 --- a/src/components/sidebarLeft/addMembers.ts +++ b/src/components/sidebarLeft/addMembers.ts @@ -13,11 +13,16 @@ export default class AppAddMembersTab implements SliderTab { private peerType: 'channel' | 'chat'; private peerID: number; // always positive private takeOut: (peerIDs: number[]) => void + private skippable: boolean; constructor() { this.nextBtn.addEventListener('click', () => { - let peerIDs = this.selector.getSelected(); - + if(this.skippable) { + this.backBtn.click(); + return; + } + + const peerIDs = this.selector.getSelected(); if(peerIDs.length) { if(this.takeOut) { this.takeOut(peerIDs); @@ -43,13 +48,14 @@ export default class AppAddMembersTab implements SliderTab { } } - public init(id: number, type: 'channel' | 'chat', skipable: boolean, takeOut?: AppAddMembersTab['takeOut']) { + public init(id: number, type: 'channel' | 'chat', skippable: boolean, takeOut?: AppAddMembersTab['takeOut']) { this.peerID = Math.abs(id); this.peerType = type; this.takeOut = takeOut; + this.skippable = skippable; this.onCloseAfterTimeout(); - this.selector = new AppSelectPeers(this.contentDiv, skipable ? null : (length) => { + this.selector = new AppSelectPeers(this.contentDiv, skippable ? null : (length) => { if(length) { this.nextBtn.classList.add('is-visible'); } else { @@ -60,7 +66,7 @@ export default class AppAddMembersTab implements SliderTab { this.nextBtn.innerHTML = ''; this.nextBtn.disabled = false; this.nextBtn.classList.add('tgico-next'); - if(skipable) { + if(skippable) { this.nextBtn.classList.add('is-visible'); } else { this.nextBtn.classList.remove('is-visible'); diff --git a/src/components/sidebarLeft/newGroup.ts b/src/components/sidebarLeft/newGroup.ts index 9ee60fd8..123b3ee5 100644 --- a/src/components/sidebarLeft/newGroup.ts +++ b/src/components/sidebarLeft/newGroup.ts @@ -13,7 +13,7 @@ export default class AppNewGroupTab implements SliderTab { private canvas = this.container.querySelector('.avatar-edit-canvas') as HTMLCanvasElement; private groupNameInput = this.container.querySelector('.new-group-name') as HTMLInputElement; private nextBtn = this.container.querySelector('.btn-corner') as HTMLButtonElement; - private searchGroup = new SearchGroup('', 'contacts', true, 'new-group-members disable-hover', false); + private searchGroup = new SearchGroup(' ', 'contacts', true, 'new-group-members disable-hover', false); private uploadAvatar: () => Promise = null; private userIDs: number[]; @@ -25,16 +25,12 @@ export default class AppNewGroupTab implements SliderTab { }); this.groupNameInput.addEventListener('input', () => { - let value = this.groupNameInput.value; - if(value.length) { - this.nextBtn.classList.add('is-visible'); - } else { - this.nextBtn.classList.remove('is-visible'); - } + const value = this.groupNameInput.value; + this.nextBtn.classList.toggle('is-visible', !!value.length); }); this.nextBtn.addEventListener('click', () => { - let title = this.groupNameInput.value; + const title = this.groupNameInput.value; this.nextBtn.disabled = true; appChatsManager.createChat(title, this.userIDs).then((chatID) => { @@ -48,11 +44,11 @@ export default class AppNewGroupTab implements SliderTab { }); }); - let chatsContainer = document.createElement('div'); + const chatsContainer = document.createElement('div'); chatsContainer.classList.add('chats-container'); chatsContainer.append(this.searchGroup.container); - let scrollable = new Scrollable(chatsContainer); + const scrollable = new Scrollable(chatsContainer); this.contentDiv.append(chatsContainer); } @@ -64,12 +60,13 @@ export default class AppNewGroupTab implements SliderTab { public onCloseAfterTimeout() { this.searchGroup.clear(); - let ctx = this.canvas.getContext('2d'); + const ctx = this.canvas.getContext('2d'); ctx.clearRect(0, 0, this.canvas.width, this.canvas.height); this.uploadAvatar = null; this.groupNameInput.value = ''; this.nextBtn.disabled = false; + this.searchGroup.clear(); } public init(userIDs: number[]) {