From fee7fb6c87b9530a95b1bb3650538d60189c24a0 Mon Sep 17 00:00:00 2001 From: Varun Singh Date: Tue, 11 Jun 2024 02:14:51 +0530 Subject: [PATCH] user_group_create_members: Convert module to TypeScript. --- tools/test-js-with-node | 2 +- ...embers.js => user_group_create_members.ts} | 29 ++++++++++--------- 2 files changed, 17 insertions(+), 14 deletions(-) rename web/src/{user_group_create_members.js => user_group_create_members.ts} (82%) diff --git a/tools/test-js-with-node b/tools/test-js-with-node index 8c4119868e..744d670101 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -269,7 +269,7 @@ EXEMPT_FILES = make_set( "web/src/user_events.js", "web/src/user_group_components.ts", "web/src/user_group_create.js", - "web/src/user_group_create_members.js", + "web/src/user_group_create_members.ts", "web/src/user_group_create_members_data.ts", "web/src/user_group_edit.js", "web/src/user_group_edit_members.js", diff --git a/web/src/user_group_create_members.js b/web/src/user_group_create_members.ts similarity index 82% rename from web/src/user_group_create_members.js rename to web/src/user_group_create_members.ts index 4d3890c67f..e91fd1a340 100644 --- a/web/src/user_group_create_members.js +++ b/web/src/user_group_create_members.ts @@ -4,44 +4,47 @@ import render_new_user_group_user from "../templates/stream_settings/new_stream_ import render_new_user_group_users from "../templates/user_group_settings/new_user_group_users.hbs"; import * as add_subscribers_pill from "./add_subscribers_pill"; +import type {InputPillContainer} from "./input_pill"; import * as ListWidget from "./list_widget"; +import type {ListWidget as ListWidgetType} from "./list_widget"; import * as people from "./people"; import {current_user} from "./state_data"; +import type {CombinedPillItem} from "./typeahead_helper"; import * as user_group_create_members_data from "./user_group_create_members_data"; import * as user_sort from "./user_sort"; -let pill_widget; -let all_users_list_widget; +let pill_widget: InputPillContainer; +let all_users_list_widget: ListWidgetType; -export function get_principals() { +export function get_principals(): number[] { return user_group_create_members_data.get_principals(); } -function redraw_member_list() { +function redraw_member_list(): void { all_users_list_widget.replace_list_data(user_group_create_members_data.sorted_user_ids()); } -function add_user_ids(user_ids) { +function add_user_ids(user_ids: number[]): void { user_group_create_members_data.add_user_ids(user_ids); redraw_member_list(); } -function add_all_users() { +function add_all_users(): void { const user_ids = user_group_create_members_data.get_all_user_ids(); add_user_ids(user_ids); } -function remove_user_ids(user_ids) { +function remove_user_ids(user_ids: number[]): void { user_group_create_members_data.remove_user_ids(user_ids); redraw_member_list(); } -export function clear_member_list() { +export function clear_member_list(): void { user_group_create_members_data.initialize_with_current_user(); redraw_member_list(); } -function build_pill_widget({$parent_container}) { +function build_pill_widget({$parent_container}: {$parent_container: JQuery}): void { const $pill_container = $parent_container.find(".pill-container"); const get_potential_members = user_group_create_members_data.get_potential_members; @@ -51,7 +54,7 @@ function build_pill_widget({$parent_container}) { }); } -export function create_handlers($container) { +export function create_handlers($container: JQuery): void { $container.on("click", ".add_all_users_to_user_group", (e) => { e.preventDefault(); add_all_users(); @@ -61,11 +64,11 @@ export function create_handlers($container) { $container.on("click", ".remove_potential_subscriber", (e) => { e.preventDefault(); const $elem = $(e.target); - const user_id = Number.parseInt($elem.attr("data-user-id"), 10); + const user_id = Number.parseInt($elem.attr("data-user-id")!, 10); remove_user_ids([user_id]); }); - function add_users({pill_user_ids}) { + function add_users({pill_user_ids}: {pill_user_ids: number[]}): void { add_user_ids(pill_user_ids); pill_widget.clear(); } @@ -79,7 +82,7 @@ export function create_handlers($container) { }); } -export function build_widgets() { +export function build_widgets(): void { const $add_people_container = $("#people_to_add_in_group"); $add_people_container.html(render_new_user_group_users({}));