mirror of https://github.com/zulip/zulip.git
ts: Migrate `user_group_create_members_data.js` to TypeScript.
This commit is contained in:
parent
6178a245b0
commit
983c6b74ab
|
@ -219,7 +219,7 @@ EXEMPT_FILES = make_set(
|
|||
"web/src/url-template.d.ts",
|
||||
"web/src/user_group_create.js",
|
||||
"web/src/user_group_create_members.js",
|
||||
"web/src/user_group_create_members_data.js",
|
||||
"web/src/user_group_create_members_data.ts",
|
||||
"web/src/user_group_edit.js",
|
||||
"web/src/user_group_edit_members.js",
|
||||
"web/src/user_group_ui_updates.js",
|
||||
|
|
|
@ -1,21 +1,25 @@
|
|||
import assert from "minimalistic-assert";
|
||||
|
||||
import {page_params} from "./page_params";
|
||||
import * as people from "./people";
|
||||
import type {User} from "./people";
|
||||
|
||||
let user_id_set;
|
||||
let user_id_set: Set<number>;
|
||||
|
||||
export function initialize_with_current_user() {
|
||||
export function initialize_with_current_user(): void {
|
||||
const current_user_id = page_params.user_id;
|
||||
user_id_set = new Set();
|
||||
user_id_set = new Set<number>();
|
||||
assert(current_user_id !== undefined, "Current user's id is undefined");
|
||||
user_id_set.add(current_user_id);
|
||||
}
|
||||
|
||||
export function sorted_user_ids() {
|
||||
export function sorted_user_ids(): number[] {
|
||||
const users = people.get_users_from_ids([...user_id_set]);
|
||||
people.sort_but_pin_current_user_on_top(users);
|
||||
return users.map((user) => user.user_id);
|
||||
}
|
||||
|
||||
export function get_all_user_ids() {
|
||||
export function get_all_user_ids(): number[] {
|
||||
const potential_members = people.get_realm_users();
|
||||
const user_ids = potential_members.map((user) => user.user_id);
|
||||
// sort for determinism
|
||||
|
@ -23,17 +27,17 @@ export function get_all_user_ids() {
|
|||
return user_ids;
|
||||
}
|
||||
|
||||
export function get_principals() {
|
||||
export function get_principals(): number[] {
|
||||
// Return list of user ids which were selected by user.
|
||||
return [...user_id_set];
|
||||
}
|
||||
|
||||
export function get_potential_members() {
|
||||
export function get_potential_members(): User[] {
|
||||
const potential_members = people.get_realm_users();
|
||||
return potential_members.filter((user) => !user_id_set.has(user.user_id));
|
||||
}
|
||||
|
||||
export function add_user_ids(user_ids) {
|
||||
export function add_user_ids(user_ids: number[]): void {
|
||||
for (const user_id of user_ids) {
|
||||
if (!user_id_set.has(user_id)) {
|
||||
const user = people.maybe_get_user_by_id(user_id);
|
||||
|
@ -44,7 +48,7 @@ export function add_user_ids(user_ids) {
|
|||
}
|
||||
}
|
||||
|
||||
export function remove_user_ids(user_ids) {
|
||||
export function remove_user_ids(user_ids: number[]): void {
|
||||
for (const user_id of user_ids) {
|
||||
user_id_set.delete(user_id);
|
||||
}
|
Loading…
Reference in New Issue