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/read_receipts.js",
"web/src/ready.ts",
"web/src/realm_icon.js",
"web/src/realm_icon.ts",
"web/src/realm_logo.js",
"web/src/realm_playground.ts",
"web/src/realm_user_settings_defaults.ts",

View File

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

View File

@ -3,10 +3,11 @@ import $ from "jquery";
import * as channel from "./channel";
import {page_params} from "./page_params";
import * as upload_widget from "./upload_widget";
import type {UploadFunction} from "./upload_widget";
export function build_realm_icon_widget(upload_function) {
const get_file_input = function () {
return $("#realm-icon-upload-widget .image_file_input").expectOne();
export function build_realm_icon_widget(upload_function: UploadFunction): void {
const get_file_input = function (): JQuery<HTMLInputElement> {
return $<HTMLInputElement>("#realm-icon-upload-widget .image_file_input").expectOne();
};
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) => {
e.preventDefault();
e.stopPropagation();
channel.del({
void channel.del({
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);
if (page_params.realm_icon_source === "U") {
$("#realm-icon-upload-widget .image-delete-button").show();