scheduled_messages_ui: Convert module to TypeScript.

This commit is contained in:
Varun Singh 2024-10-11 02:43:13 +05:30 committed by Tim Abbott
parent b3d75d619a
commit 697e7acaaa
2 changed files with 34 additions and 10 deletions

View File

@ -199,7 +199,7 @@ EXEMPT_FILES = make_set(
"web/src/scheduled_messages.ts", "web/src/scheduled_messages.ts",
"web/src/scheduled_messages_feed_ui.ts", "web/src/scheduled_messages_feed_ui.ts",
"web/src/scheduled_messages_overlay_ui.js", "web/src/scheduled_messages_overlay_ui.js",
"web/src/scheduled_messages_ui.js", "web/src/scheduled_messages_ui.ts",
"web/src/scroll_bar.ts", "web/src/scroll_bar.ts",
"web/src/scroll_util.ts", "web/src/scroll_util.ts",
"web/src/search.ts", "web/src/search.ts",

View File

@ -1,4 +1,5 @@
import $ from "jquery"; import $ from "jquery";
import assert from "minimalistic-assert";
import render_compose_banner from "../templates/compose_banner/compose_banner.hbs"; import render_compose_banner from "../templates/compose_banner/compose_banner.hbs";
@ -8,15 +9,30 @@ import {$t} from "./i18n";
import * as message_view from "./message_view"; import * as message_view from "./message_view";
import * as people from "./people"; import * as people from "./people";
import * as scheduled_messages from "./scheduled_messages"; import * as scheduled_messages from "./scheduled_messages";
import type {ScheduledMessage} from "./scheduled_messages";
import * as timerender from "./timerender"; import * as timerender from "./timerender";
export function hide_scheduled_message_success_compose_banner(scheduled_message_id) { type ScheduledMessageComposeArgs =
| {
message_type: "stream";
stream_id: number;
topic: string;
content: string;
}
| {
message_type: "private";
private_message_recipient: string;
content: string;
keep_composebox_empty: boolean;
};
export function hide_scheduled_message_success_compose_banner(scheduled_message_id: number): void {
$( $(
`.message_scheduled_success_compose_banner[data-scheduled-message-id=${scheduled_message_id}]`, `.message_scheduled_success_compose_banner[data-scheduled-message-id=${scheduled_message_id}]`,
).hide(); ).hide();
} }
function narrow_via_edit_scheduled_message(compose_args) { function narrow_via_edit_scheduled_message(compose_args: ScheduledMessageComposeArgs): void {
if (compose_args.message_type === "stream") { if (compose_args.message_type === "stream") {
message_view.show( message_view.show(
[ [
@ -35,11 +51,14 @@ function narrow_via_edit_scheduled_message(compose_args) {
} }
} }
export function open_scheduled_message_in_compose(scheduled_msg, should_narrow_to_recipient) { export function open_scheduled_message_in_compose(
scheduled_msg: ScheduledMessage,
should_narrow_to_recipient?: boolean,
): void {
let compose_args; let compose_args;
if (scheduled_msg.type === "stream") { if (scheduled_msg.type === "stream") {
compose_args = { compose_args = {
message_type: "stream", message_type: "stream" as const,
stream_id: scheduled_msg.to, stream_id: scheduled_msg.to,
topic: scheduled_msg.topic, topic: scheduled_msg.topic,
content: scheduled_msg.content, content: scheduled_msg.content,
@ -55,7 +74,7 @@ export function open_scheduled_message_in_compose(scheduled_msg, should_narrow_t
} }
} }
compose_args = { compose_args = {
message_type: scheduled_msg.type, message_type: "private" as const,
private_message_recipient: recipient_emails.join(","), private_message_recipient: recipient_emails.join(","),
content: scheduled_msg.content, content: scheduled_msg.content,
keep_composebox_empty: true, keep_composebox_empty: true,
@ -70,7 +89,7 @@ export function open_scheduled_message_in_compose(scheduled_msg, should_narrow_t
scheduled_messages.set_selected_schedule_timestamp(scheduled_msg.scheduled_delivery_timestamp); scheduled_messages.set_selected_schedule_timestamp(scheduled_msg.scheduled_delivery_timestamp);
} }
function show_message_unscheduled_banner(scheduled_delivery_timestamp) { function show_message_unscheduled_banner(scheduled_delivery_timestamp: number): void {
const deliver_at = timerender.get_full_datetime( const deliver_at = timerender.get_full_datetime(
new Date(scheduled_delivery_timestamp * 1000), new Date(scheduled_delivery_timestamp * 1000),
"time", "time",
@ -89,20 +108,25 @@ function show_message_unscheduled_banner(scheduled_delivery_timestamp) {
); );
} }
export function edit_scheduled_message(scheduled_message_id, should_narrow_to_recipient = true) { export function edit_scheduled_message(
scheduled_message_id: number,
should_narrow_to_recipient = true,
): void {
const scheduled_msg = scheduled_messages.scheduled_messages_data.get(scheduled_message_id); const scheduled_msg = scheduled_messages.scheduled_messages_data.get(scheduled_message_id);
assert(scheduled_msg !== undefined);
scheduled_messages.delete_scheduled_message(scheduled_message_id, () => { scheduled_messages.delete_scheduled_message(scheduled_message_id, () => {
open_scheduled_message_in_compose(scheduled_msg, should_narrow_to_recipient); open_scheduled_message_in_compose(scheduled_msg, should_narrow_to_recipient);
show_message_unscheduled_banner(scheduled_msg.scheduled_delivery_timestamp); show_message_unscheduled_banner(scheduled_msg.scheduled_delivery_timestamp);
}); });
} }
export function initialize() { export function initialize(): void {
$("body").on("click", ".undo_scheduled_message", (e) => { $("body").on("click", ".undo_scheduled_message", (e) => {
const scheduled_message_id = Number.parseInt( const scheduled_message_id = Number.parseInt(
$(e.target) $(e.target)
.parents(".message_scheduled_success_compose_banner") .parents(".message_scheduled_success_compose_banner")
.attr("data-scheduled-message-id"), .attr("data-scheduled-message-id")!,
10, 10,
); );
const should_narrow_to_recipient = false; const should_narrow_to_recipient = false;