2020-04-24 03:48:48 +03:00
|
|
|
//import { logger } from "../polyfill";
|
2020-02-06 22:43:07 +07:00
|
|
|
import appDialogsManager from "./appDialogsManager";
|
2020-04-24 03:48:48 +03:00
|
|
|
import { $rootScope } from "../utils";
|
2020-02-08 13:03:09 +07:00
|
|
|
import appImManager from "./appImManager";
|
2020-04-19 00:55:20 +03:00
|
|
|
import apiManager from "../mtproto/apiManager";
|
2020-04-24 03:48:48 +03:00
|
|
|
import AppSearch, { SearchGroup } from "../../components/appSearch";
|
2020-02-06 22:43:07 +07:00
|
|
|
|
|
|
|
class AppSidebarLeft {
|
2020-04-24 03:48:48 +03:00
|
|
|
private sidebarEl = document.getElementById('column-left') as HTMLDivElement;
|
2020-02-06 22:43:07 +07:00
|
|
|
private toolsBtn = this.sidebarEl.querySelector('.sidebar-tools-button') as HTMLButtonElement;
|
2020-02-15 22:20:38 +07:00
|
|
|
private backBtn = this.sidebarEl.querySelector('.sidebar-back-button') as HTMLButtonElement;
|
2020-02-06 22:43:07 +07:00
|
|
|
private searchContainer = this.sidebarEl.querySelector('#search-container') as HTMLDivElement;
|
2020-04-24 03:48:48 +03:00
|
|
|
private searchInput = document.getElementById('global-search') as HTMLInputElement;
|
2020-02-08 18:58:22 +07:00
|
|
|
|
2020-02-08 13:03:09 +07:00
|
|
|
private menuEl = this.toolsBtn.querySelector('.btn-menu');
|
|
|
|
private savedBtn = this.menuEl.querySelector('.menu-saved');
|
2020-02-11 22:35:57 +07:00
|
|
|
private archivedBtn = this.menuEl.querySelector('.menu-archive');
|
2020-04-19 00:55:20 +03:00
|
|
|
private logOutBtn = this.menuEl.querySelector('.menu-logout');
|
2020-02-15 22:20:38 +07:00
|
|
|
public archivedCount = this.archivedBtn.querySelector('.archived-count') as HTMLSpanElement;
|
2020-02-09 13:45:43 +07:00
|
|
|
|
2020-04-24 03:48:48 +03:00
|
|
|
//private log = logger('SL');
|
|
|
|
|
|
|
|
private globalSearch = new AppSearch(this.searchContainer, this.searchInput, {
|
|
|
|
contacts: new SearchGroup('Contacts and Chats', 'contacts'),
|
|
|
|
globalContacts: new SearchGroup('Global Search', 'contacts'),
|
|
|
|
messages: new SearchGroup('Global Search', 'messages')
|
|
|
|
});
|
2020-02-21 15:25:19 +07:00
|
|
|
|
2020-02-06 22:43:07 +07:00
|
|
|
constructor() {
|
2020-02-10 14:56:15 +07:00
|
|
|
this.savedBtn.addEventListener('click', (e) => {
|
2020-02-17 19:18:06 +07:00
|
|
|
///////this.log('savedbtn click');
|
2020-02-10 14:56:15 +07:00
|
|
|
setTimeout(() => { // menu doesn't close if no timeout (lol)
|
2020-02-13 22:42:39 +07:00
|
|
|
let dom = appDialogsManager.getDialogDom(appImManager.myID);
|
2020-04-08 18:46:43 +03:00
|
|
|
appImManager.setPeer(appImManager.myID);
|
2020-02-10 14:56:15 +07:00
|
|
|
}, 0);
|
2020-02-08 13:03:09 +07:00
|
|
|
});
|
2020-02-07 13:38:55 +07:00
|
|
|
|
2020-02-11 22:35:57 +07:00
|
|
|
this.archivedBtn.addEventListener('click', (e) => {
|
2020-04-20 00:40:00 +03:00
|
|
|
appDialogsManager.chatsArchivedContainer.classList.add('active');
|
2020-02-15 22:20:38 +07:00
|
|
|
this.toolsBtn.classList.remove('active');
|
|
|
|
this.backBtn.classList.add('active');
|
|
|
|
//this.toolsBtn.classList.remove('tgico-menu', 'btn-menu-toggle');
|
|
|
|
//this.toolsBtn.classList.add('tgico-back');
|
2020-02-11 22:35:57 +07:00
|
|
|
});
|
2020-04-19 00:55:20 +03:00
|
|
|
|
|
|
|
this.logOutBtn.addEventListener('click', (e) => {
|
|
|
|
apiManager.logOut();
|
|
|
|
});
|
2020-02-22 18:20:43 +07:00
|
|
|
|
2020-02-06 22:43:07 +07:00
|
|
|
this.searchInput.addEventListener('focus', (e) => {
|
2020-02-15 22:20:38 +07:00
|
|
|
this.toolsBtn.classList.remove('active');
|
|
|
|
this.backBtn.classList.add('active');
|
2020-02-06 22:43:07 +07:00
|
|
|
this.searchContainer.classList.add('active');
|
2020-02-07 13:38:55 +07:00
|
|
|
|
2020-04-24 03:48:48 +03:00
|
|
|
/* if(!this.globalSearch.searchInput.value) {
|
|
|
|
for(let i in this.globalSearch.searchGroups) {
|
|
|
|
this.globalSearch.searchGroups[i].clear();
|
2020-02-11 22:35:57 +07:00
|
|
|
}
|
2020-04-24 03:48:48 +03:00
|
|
|
} */
|
2020-02-09 17:30:24 +07:00
|
|
|
|
2020-02-06 22:43:07 +07:00
|
|
|
this.searchInput.addEventListener('blur', (e) => {
|
|
|
|
if(!this.searchInput.value) {
|
2020-02-15 22:20:38 +07:00
|
|
|
this.toolsBtn.classList.add('active');
|
|
|
|
this.backBtn.classList.remove('active');
|
2020-02-06 22:43:07 +07:00
|
|
|
this.searchContainer.classList.remove('active');
|
2020-02-17 19:18:06 +07:00
|
|
|
this.backBtn.click();
|
2020-02-06 22:43:07 +07:00
|
|
|
}
|
2020-02-07 13:38:55 +07:00
|
|
|
|
|
|
|
/* this.peerID = 0;
|
|
|
|
this.loadedCount = 0;
|
|
|
|
this.minMsgID = 0; */
|
2020-02-06 22:43:07 +07:00
|
|
|
}, {once: true});
|
|
|
|
});
|
2020-02-10 14:56:15 +07:00
|
|
|
|
2020-02-15 22:20:38 +07:00
|
|
|
this.backBtn.addEventListener('click', (e) => {
|
2020-04-20 00:40:00 +03:00
|
|
|
appDialogsManager.chatsArchivedContainer.classList.remove('active');
|
2020-02-15 22:20:38 +07:00
|
|
|
this.toolsBtn.classList.add('active');
|
|
|
|
this.backBtn.classList.remove('active');
|
2020-02-17 19:18:06 +07:00
|
|
|
this.searchContainer.classList.remove('active');
|
2020-04-24 03:48:48 +03:00
|
|
|
this.globalSearch.reset();
|
2020-02-07 13:38:55 +07:00
|
|
|
});
|
2020-02-11 22:35:57 +07:00
|
|
|
|
2020-04-20 00:40:00 +03:00
|
|
|
$rootScope.$on('dialogs_archived_unread', (e: CustomEvent) => {
|
|
|
|
this.archivedCount.innerText = '' + e.detail.count;
|
|
|
|
});
|
|
|
|
|
2020-02-11 22:35:57 +07:00
|
|
|
/* appUsersManager.getTopPeers().then(categories => {
|
|
|
|
this.log('got top categories:', categories);
|
|
|
|
}); */
|
2020-02-07 13:38:55 +07:00
|
|
|
}
|
2020-02-06 22:43:07 +07:00
|
|
|
}
|
|
|
|
|
2020-04-08 18:46:43 +03:00
|
|
|
const appSidebarLeft = new AppSidebarLeft();
|
|
|
|
|
|
|
|
(window as any).appSidebarLeft = appSidebarLeft;
|
|
|
|
|
|
|
|
export default appSidebarLeft;
|