ts: Migrate `realm_logo` to TypeScript.

This commit is contained in:
Lalit Kumar Singh 2023-09-09 14:02:13 +05:30 committed by Tim Abbott
parent b8e0850aa1
commit c47a18eb2b
3 changed files with 22 additions and 10 deletions

View File

@ -142,7 +142,7 @@ EXEMPT_FILES = make_set(
"web/src/read_receipts.js",
"web/src/ready.ts",
"web/src/realm_icon.ts",
"web/src/realm_logo.js",
"web/src/realm_logo.ts",
"web/src/realm_playground.ts",
"web/src/realm_user_settings_defaults.ts",
"web/src/recent_view_ui.js",

View File

@ -22,6 +22,7 @@ export const page_params: {
is_spectator: boolean;
max_avatar_file_size_mib: number;
max_icon_file_size_mib: number;
max_logo_file_size_mib: number;
muted_users: {id: number; timestamp: number}[];
needs_tutorial: boolean;
page_load_time: number;
@ -41,6 +42,10 @@ export const page_params: {
realm_invite_to_realm_policy: number;
realm_invite_to_stream_policy: number;
realm_is_zephyr_mirror_realm: boolean;
realm_logo_source: string;
realm_logo_url: string;
realm_night_logo_source: string;
realm_night_logo_url: string;
realm_move_messages_between_streams_policy: number;
realm_name_changes_disabled: boolean;
realm_name: string;

View File

@ -5,8 +5,9 @@ import {page_params} from "./page_params";
import * as settings_data from "./settings_data";
import * as ui_util from "./ui_util";
import * as upload_widget from "./upload_widget";
import type {UploadFunction} from "./upload_widget";
export function build_realm_logo_widget(upload_function, is_night) {
export function build_realm_logo_widget(upload_function: UploadFunction, is_night: boolean): void {
let logo_section_id = "#realm-day-logo-upload-widget";
let logo_source = page_params.realm_logo_source;
@ -16,11 +17,11 @@ export function build_realm_logo_widget(upload_function, is_night) {
}
const $delete_button_elem = $(logo_section_id + " .image-delete-button");
const $file_input_elem = $(logo_section_id + " .image_file_input");
const $file_input_elem = $<HTMLInputElement>(logo_section_id + " .image_file_input");
const $file_input_error_elem = $(logo_section_id + " .image_file_input_error");
const $upload_button_elem = $(logo_section_id + " .image_upload_button");
const get_file_input = function () {
const get_file_input = function (): JQuery<HTMLInputElement> {
return $file_input_elem.expectOne();
};
@ -38,7 +39,7 @@ export function build_realm_logo_widget(upload_function, is_night) {
$delete_button_elem.on("click", (e) => {
e.preventDefault();
e.stopPropagation();
channel.del({
void channel.del({
url: "/json/realm/logo",
data,
});
@ -53,7 +54,11 @@ export function build_realm_logo_widget(upload_function, is_night) {
);
}
function change_logo_delete_button(logo_source, $logo_delete_button, $file_input) {
function change_logo_delete_button(
logo_source: string,
$logo_delete_button: JQuery,
$file_input: JQuery<HTMLInputElement>,
): void {
if (logo_source === "U") {
$logo_delete_button.show();
} else {
@ -64,9 +69,11 @@ function change_logo_delete_button(logo_source, $logo_delete_button, $file_input
}
}
export function render() {
const $file_input = $("#realm-day-logo-upload-widget .image_file_input");
const $night_file_input = $("#realm-night-logo-upload-widget .realm-logo-file-input");
export function render(): void {
const $file_input = $<HTMLInputElement>("#realm-day-logo-upload-widget .image_file_input");
const $night_file_input = $<HTMLInputElement>(
"#realm-night-logo-upload-widget .realm-logo-file-input",
);
$("#realm-day-logo-upload-widget .image-block").attr("src", page_params.realm_logo_url);
if (page_params.realm_night_logo_source === "D" && page_params.realm_logo_source !== "D") {
@ -101,7 +108,7 @@ export function render() {
);
}
export function initialize() {
export function initialize(): void {
// render once
render();