refactor: Extract remove_subscriber.

This commit is contained in:
Steve Howell 2021-12-19 13:48:01 +00:00 committed by Tim Abbott
parent e742ebb8e8
commit d7f90acbf6
1 changed files with 53 additions and 49 deletions

View File

@ -263,28 +263,7 @@ function submit_add_subscriber_form(stream_id) {
invite_user_to_stream(user_ids, sub, invite_success, invite_failure);
}
export function initialize() {
$("#subscriptions_table").on("keyup", ".subscriber_list_add form", (e) => {
if (e.key === "Enter") {
e.preventDefault();
const stream_id = get_stream_id(e.target);
submit_add_subscriber_form(stream_id);
}
});
$("#subscriptions_table").on("submit", ".subscriber_list_add form", (e) => {
e.preventDefault();
const stream_id = get_stream_id(e.target);
submit_add_subscriber_form(stream_id);
});
$("#subscriptions_table").on("submit", ".subscriber_list_remove form", (e) => {
e.preventDefault();
const list_entry = $(e.target).closest("tr");
const target_user_id = Number.parseInt(list_entry.attr("data-subscriber-id"), 10);
const stream_id = get_stream_id(e.target);
function remove_subscriber({stream_id, target_user_id, list_entry}) {
const sub = get_sub(stream_id);
if (!sub) {
return;
@ -334,5 +313,30 @@ export function initialize() {
}
remove_user_from_stream(target_user_id, sub, removal_success, removal_failure);
}
export function initialize() {
$("#subscriptions_table").on("keyup", ".subscriber_list_add form", (e) => {
if (e.key === "Enter") {
e.preventDefault();
const stream_id = get_stream_id(e.target);
submit_add_subscriber_form(stream_id);
}
});
$("#subscriptions_table").on("submit", ".subscriber_list_add form", (e) => {
e.preventDefault();
const stream_id = get_stream_id(e.target);
submit_add_subscriber_form(stream_id);
});
$("#subscriptions_table").on("submit", ".subscriber_list_remove form", (e) => {
e.preventDefault();
const list_entry = $(e.target).closest("tr");
const target_user_id = Number.parseInt(list_entry.attr("data-subscriber-id"), 10);
const stream_id = get_stream_id(e.target);
remove_subscriber({stream_id, target_user_id, list_entry});
});
}