tweb/src/components/sidebarRight/tabs/search.ts

72 lines
2.3 KiB
TypeScript
Raw Normal View History

2021-08-03 03:44:13 +02:00
/*
* https://github.com/morethanwords/tweb
* Copyright (C) 2019-2021 Eduard Kuzmenko
* https://github.com/morethanwords/tweb/blob/master/LICENSE
*/
import appSidebarRight from "..";
import { attachClickEvent } from "../../../helpers/dom/clickEvent";
import AppSearch, { SearchGroup } from "../../appSearch";
import ButtonIcon from "../../buttonIcon";
import InputSearch from "../../inputSearch";
import PopupDatePicker from "../../popups/datePicker";
import { SliderSuperTab } from "../../slider";
export default class AppPrivateSearchTab extends SliderSuperTab {
private inputSearch: InputSearch;
private appSearch: AppSearch;
private btnPickDate: HTMLElement;
2021-10-21 15:16:43 +02:00
private peerId: PeerId;
2021-08-03 03:44:13 +02:00
private threadId = 0;
2021-09-14 06:36:43 +02:00
private query = '';
2021-08-03 03:44:13 +02:00
private onDatePick: (timestamp: number) => void;
onOpenAfterTimeout() {
2021-09-14 06:36:43 +02:00
this.appSearch.beginSearch(this.peerId, this.threadId, this.query);
2021-08-03 03:44:13 +02:00
}
protected init() {
this.container.id = 'search-private-container';
this.container.classList.add('chatlist-container');
this.inputSearch = new InputSearch('Search');
this.title.replaceWith(this.inputSearch.container);
this.btnPickDate = ButtonIcon('calendar sidebar-header-right');
this.header.append(this.btnPickDate);
const c = document.createElement('div');
c.classList.add('chatlist-container');
this.scrollable.container.replaceWith(c);
this.appSearch = new AppSearch(c, this.inputSearch, {
messages: new SearchGroup('Chat.Search.PrivateSearch', 'messages')
});
}
2021-10-21 15:16:43 +02:00
open(peerId: PeerId, threadId?: number, onDatePick?: AppPrivateSearchTab['onDatePick'], query?: string) {
2021-08-03 03:44:13 +02:00
const ret = super.open();
2021-09-14 06:36:43 +02:00
if(!this.peerId) {
this.query = query;
this.peerId = peerId;
this.threadId = threadId;
this.onDatePick = onDatePick;
this.btnPickDate.classList.toggle('hide', !this.onDatePick);
if(this.onDatePick) {
attachClickEvent(this.btnPickDate, () => {
new PopupDatePicker(new Date(), this.onDatePick).show();
});
}
2021-08-03 03:44:13 +02:00
2021-09-14 06:36:43 +02:00
query && this.appSearch.searchInput.inputField.setValueSilently(query);
appSidebarRight.toggleSidebar(true);
} else {
this.appSearch.beginSearch(this.peerId, this.threadId, query);
2021-08-03 03:44:13 +02:00
}
return ret;
}
}