tweb/src/components/popups/pickUser.ts

67 lines
1.9 KiB
TypeScript
Raw Normal View History

2021-04-08 15:52:31 +02:00
/*
* https://github.com/morethanwords/tweb
* Copyright (C) 2019-2021 Eduard Kuzmenko
* https://github.com/morethanwords/tweb/blob/master/LICENSE
*/
2021-03-02 16:34:02 +01:00
import { isTouchSupported } from "../../helpers/touchSupport";
import AppSelectPeers from "../appSelectPeers";
import PopupElement from ".";
2021-03-25 19:07:00 +01:00
import { LangPackKey, _i18n } from "../../lib/langPack";
2021-03-02 16:34:02 +01:00
export default class PopupPickUser extends PopupElement {
protected selector: AppSelectPeers;
constructor(options: {
peerTypes: AppSelectPeers['peerType'],
onSelect?: (peerId: number) => Promise<void> | void,
onClose?: () => void,
2021-03-25 19:07:00 +01:00
placeholder: LangPackKey,
2021-03-19 13:14:42 +01:00
chatRightsAction?: AppSelectPeers['chatRightsAction'],
peerId?: number,
2021-07-08 08:07:32 +02:00
selfPresence?: LangPackKey
2021-03-02 16:34:02 +01:00
}) {
super('popup-forward', null, {closable: true, overlayClosable: true, body: true});
if(options.onClose) this.onClose = options.onClose;
this.selector = new AppSelectPeers({
appendTo: this.body,
onChange: async() => {
const peerId = this.selector.getSelected()[0];
2021-03-23 17:13:35 +01:00
2021-03-02 16:34:02 +01:00
this.selector = null;
2021-03-23 17:13:35 +01:00
2021-03-02 16:34:02 +01:00
if(options.onSelect) {
const res = options.onSelect(peerId);
if(res instanceof Promise) {
await res;
}
}
2021-03-23 17:13:35 +01:00
this.hide();
2021-03-02 16:34:02 +01:00
},
peerType: options.peerTypes,
onFirstRender: () => {
this.show();
this.selector.checkForTriggers(); // ! due to zero height before mounting
if(!isTouchSupported) {
this.selector.input.focus();
}
},
chatRightsAction: options.chatRightsAction,
multiSelect: false,
2021-03-19 13:14:42 +01:00
rippleEnabled: false,
avatarSize: 46,
peerId: options.peerId,
2021-07-08 08:07:32 +02:00
placeholder: options.placeholder,
selfPresence: options.selfPresence
2021-03-02 16:34:02 +01:00
});
//this.scrollable = new Scrollable(this.body);
this.title.append(this.selector.input);
}
}