tweb-i2p/src/lib/appManagers/appSidebarLeft.ts

98 lines
3.6 KiB
TypeScript
Raw Normal View History

//import { logger } from "../polyfill";
2020-02-06 22:43:07 +07:00
import appDialogsManager from "./appDialogsManager";
import { $rootScope } from "../utils";
import appImManager from "./appImManager";
import apiManager from "../mtproto/apiManager";
import AppSearch, { SearchGroup } from "../../components/appSearch";
2020-02-06 22:43:07 +07:00
class AppSidebarLeft {
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;
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;
private searchInput = document.getElementById('global-search') as HTMLInputElement;
2020-02-08 18:58:22 +07:00
private menuEl = this.toolsBtn.querySelector('.btn-menu');
private savedBtn = this.menuEl.querySelector('.menu-saved');
private archivedBtn = this.menuEl.querySelector('.menu-archive');
private logOutBtn = this.menuEl.querySelector('.menu-logout');
public archivedCount = this.archivedBtn.querySelector('.archived-count') as HTMLSpanElement;
//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-07 13:38:55 +07:00
this.archivedBtn.addEventListener('click', (e) => {
appDialogsManager.chatsArchivedContainer.classList.add('active');
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');
});
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) => {
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
/* if(!this.globalSearch.searchInput.value) {
for(let i in this.globalSearch.searchGroups) {
this.globalSearch.searchGroups[i].clear();
}
} */
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) {
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
this.backBtn.addEventListener('click', (e) => {
appDialogsManager.chatsArchivedContainer.classList.remove('active');
this.toolsBtn.classList.add('active');
this.backBtn.classList.remove('active');
2020-02-17 19:18:06 +07:00
this.searchContainer.classList.remove('active');
this.globalSearch.reset();
2020-02-07 13:38:55 +07:00
});
$rootScope.$on('dialogs_archived_unread', (e: CustomEvent) => {
this.archivedCount.innerText = '' + e.detail.count;
});
/* 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;