ts: Migrate `realm_icon` to TypeScript.

This commit is contained in:
Lalit Kumar Singh 2023-09-09 13:55:05 +05:30 committed by Tim Abbott
parent 1305fe74b6
commit b8e0850aa1
3 changed files with 10 additions and 6 deletions

View File

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

View File

@ -21,6 +21,7 @@ export const page_params: {
is_owner: boolean; is_owner: boolean;
is_spectator: boolean; is_spectator: boolean;
max_avatar_file_size_mib: number; max_avatar_file_size_mib: number;
max_icon_file_size_mib: number;
muted_users: {id: number; timestamp: number}[]; muted_users: {id: number; timestamp: number}[];
needs_tutorial: boolean; needs_tutorial: boolean;
page_load_time: number; page_load_time: number;
@ -35,6 +36,8 @@ export const page_params: {
realm_edit_topic_policy: number; realm_edit_topic_policy: number;
realm_email_changes_disabled: boolean; realm_email_changes_disabled: boolean;
realm_enable_spectator_access: boolean; realm_enable_spectator_access: boolean;
realm_icon_source: string;
realm_icon_url: string;
realm_invite_to_realm_policy: number; realm_invite_to_realm_policy: number;
realm_invite_to_stream_policy: number; realm_invite_to_stream_policy: number;
realm_is_zephyr_mirror_realm: boolean; realm_is_zephyr_mirror_realm: boolean;

View File

@ -3,10 +3,11 @@ import $ from "jquery";
import * as channel from "./channel"; import * as channel from "./channel";
import {page_params} from "./page_params"; import {page_params} from "./page_params";
import * as upload_widget from "./upload_widget"; import * as upload_widget from "./upload_widget";
import type {UploadFunction} from "./upload_widget";
export function build_realm_icon_widget(upload_function) { export function build_realm_icon_widget(upload_function: UploadFunction): void {
const get_file_input = function () { const get_file_input = function (): JQuery<HTMLInputElement> {
return $("#realm-icon-upload-widget .image_file_input").expectOne(); return $<HTMLInputElement>("#realm-icon-upload-widget .image_file_input").expectOne();
}; };
if (!page_params.is_admin) { if (!page_params.is_admin) {
@ -20,7 +21,7 @@ export function build_realm_icon_widget(upload_function) {
$("#realm-icon-upload-widget .image-delete-button").on("click", (e) => { $("#realm-icon-upload-widget .image-delete-button").on("click", (e) => {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
channel.del({ void channel.del({
url: "/json/realm/icon", url: "/json/realm/icon",
}); });
}); });
@ -34,7 +35,7 @@ export function build_realm_icon_widget(upload_function) {
); );
} }
export function rerender() { export function rerender(): void {
$("#realm-icon-upload-widget .image-block").attr("src", page_params.realm_icon_url); $("#realm-icon-upload-widget .image-block").attr("src", page_params.realm_icon_url);
if (page_params.realm_icon_source === "U") { if (page_params.realm_icon_source === "U") {
$("#realm-icon-upload-widget .image-delete-button").show(); $("#realm-icon-upload-widget .image-delete-button").show();