mirror of https://github.com/zulip/zulip.git
add_subscribers_pill: Convert module to TypeScript.
This commit is contained in:
parent
bf3eb2c269
commit
d36e19389d
|
@ -47,7 +47,7 @@ EXEMPT_FILES = make_set(
|
||||||
"web/shared/src/poll_data.ts",
|
"web/shared/src/poll_data.ts",
|
||||||
"web/src/about_zulip.ts",
|
"web/src/about_zulip.ts",
|
||||||
"web/src/add_stream_options_popover.ts",
|
"web/src/add_stream_options_popover.ts",
|
||||||
"web/src/add_subscribers_pill.js",
|
"web/src/add_subscribers_pill.ts",
|
||||||
"web/src/admin.js",
|
"web/src/admin.js",
|
||||||
"web/src/alert_popup.ts",
|
"web/src/alert_popup.ts",
|
||||||
"web/src/alert_words_ui.ts",
|
"web/src/alert_words_ui.ts",
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
import * as input_pill from "./input_pill";
|
import * as input_pill from "./input_pill";
|
||||||
import * as keydown_util from "./keydown_util";
|
import * as keydown_util from "./keydown_util";
|
||||||
|
import type {User} from "./people";
|
||||||
import * as pill_typeahead from "./pill_typeahead";
|
import * as pill_typeahead from "./pill_typeahead";
|
||||||
import * as stream_pill from "./stream_pill";
|
import * as stream_pill from "./stream_pill";
|
||||||
|
import type {CombinedPillContainer, CombinedPillItem} from "./typeahead_helper";
|
||||||
import * as user_group_pill from "./user_group_pill";
|
import * as user_group_pill from "./user_group_pill";
|
||||||
import * as user_pill from "./user_pill";
|
import * as user_pill from "./user_pill";
|
||||||
|
|
||||||
function create_item_from_text(text, current_items) {
|
function create_item_from_text(
|
||||||
|
text: string,
|
||||||
|
current_items: CombinedPillItem[],
|
||||||
|
): CombinedPillItem | undefined {
|
||||||
const funcs = [
|
const funcs = [
|
||||||
stream_pill.create_item_from_stream_name,
|
stream_pill.create_item_from_stream_name,
|
||||||
user_group_pill.create_item_from_group_name,
|
user_group_pill.create_item_from_group_name,
|
||||||
|
@ -20,22 +25,31 @@ function create_item_from_text(text, current_items) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_text_from_item(item) {
|
function get_text_from_item(item: CombinedPillItem): string {
|
||||||
const funcs = [
|
let text: string;
|
||||||
stream_pill.get_stream_name_from_item,
|
switch (item.type) {
|
||||||
user_group_pill.get_group_name_from_item,
|
case "stream":
|
||||||
user_pill.get_email_from_item,
|
text = stream_pill.get_stream_name_from_item(item);
|
||||||
];
|
break;
|
||||||
for (const func of funcs) {
|
case "user_group":
|
||||||
const text = func(item);
|
text = user_group_pill.get_group_name_from_item(item);
|
||||||
if (text) {
|
break;
|
||||||
return text;
|
case "user":
|
||||||
}
|
text = user_pill.get_email_from_item(item);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return undefined;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
function set_up_pill_typeahead({pill_widget, $pill_container, get_users}) {
|
function set_up_pill_typeahead({
|
||||||
|
pill_widget,
|
||||||
|
$pill_container,
|
||||||
|
get_users,
|
||||||
|
}: {
|
||||||
|
pill_widget: CombinedPillContainer;
|
||||||
|
$pill_container: JQuery;
|
||||||
|
get_users: () => User[];
|
||||||
|
}): void {
|
||||||
const opts = {
|
const opts = {
|
||||||
user_source: get_users,
|
user_source: get_users,
|
||||||
stream: true,
|
stream: true,
|
||||||
|
@ -45,14 +59,19 @@ function set_up_pill_typeahead({pill_widget, $pill_container, get_users}) {
|
||||||
pill_typeahead.set_up($pill_container.find(".input"), pill_widget, opts);
|
pill_typeahead.set_up($pill_container.find(".input"), pill_widget, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function create({$pill_container, get_potential_subscribers}) {
|
export function create({
|
||||||
const pill_widget = input_pill.create({
|
$pill_container,
|
||||||
|
get_potential_subscribers,
|
||||||
|
}: {
|
||||||
|
$pill_container: JQuery;
|
||||||
|
get_potential_subscribers: () => User[];
|
||||||
|
}): input_pill.InputPillContainer<CombinedPillItem> {
|
||||||
|
const pill_widget = input_pill.create<CombinedPillItem>({
|
||||||
$container: $pill_container,
|
$container: $pill_container,
|
||||||
create_item_from_text,
|
create_item_from_text,
|
||||||
get_text_from_item,
|
get_text_from_item,
|
||||||
});
|
});
|
||||||
|
function get_users(): User[] {
|
||||||
function get_users() {
|
|
||||||
const potential_subscribers = get_potential_subscribers();
|
const potential_subscribers = get_potential_subscribers();
|
||||||
return user_pill.filter_taken_users(potential_subscribers, pill_widget);
|
return user_pill.filter_taken_users(potential_subscribers, pill_widget);
|
||||||
}
|
}
|
||||||
|
@ -80,7 +99,7 @@ export function create({$pill_container, get_potential_subscribers}) {
|
||||||
return pill_widget;
|
return pill_widget;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_pill_user_ids(pill_widget) {
|
function get_pill_user_ids(pill_widget: CombinedPillContainer): number[] {
|
||||||
const user_ids = user_pill.get_user_ids(pill_widget);
|
const user_ids = user_pill.get_user_ids(pill_widget);
|
||||||
const stream_user_ids = stream_pill.get_user_ids(pill_widget);
|
const stream_user_ids = stream_pill.get_user_ids(pill_widget);
|
||||||
const group_user_ids = user_group_pill.get_user_ids(pill_widget);
|
const group_user_ids = user_group_pill.get_user_ids(pill_widget);
|
||||||
|
@ -93,7 +112,13 @@ export function set_up_handlers({
|
||||||
pill_selector,
|
pill_selector,
|
||||||
button_selector,
|
button_selector,
|
||||||
action,
|
action,
|
||||||
}) {
|
}: {
|
||||||
|
get_pill_widget: () => CombinedPillContainer;
|
||||||
|
$parent_container: JQuery;
|
||||||
|
pill_selector: string;
|
||||||
|
button_selector: string;
|
||||||
|
action: ({pill_user_ids}: {pill_user_ids: number[]}) => void;
|
||||||
|
}): void {
|
||||||
/*
|
/*
|
||||||
This function handles events for any UI that looks like
|
This function handles events for any UI that looks like
|
||||||
this:
|
this:
|
||||||
|
@ -121,7 +146,7 @@ export function set_up_handlers({
|
||||||
* user group
|
* user group
|
||||||
* stream (i.e. subscribed users for the stream)
|
* stream (i.e. subscribed users for the stream)
|
||||||
*/
|
*/
|
||||||
function callback() {
|
function callback(): void {
|
||||||
const pill_widget = get_pill_widget();
|
const pill_widget = get_pill_widget();
|
||||||
const pill_user_ids = get_pill_user_ids(pill_widget);
|
const pill_user_ids = get_pill_user_ids(pill_widget);
|
||||||
action({pill_user_ids});
|
action({pill_user_ids});
|
Loading…
Reference in New Issue