From b8e0850aa18ac43e063756373e00147dcb01cf15 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Singh Date: Sat, 9 Sep 2023 13:55:05 +0530 Subject: [PATCH] ts: Migrate `realm_icon` to TypeScript. --- tools/test-js-with-node | 2 +- web/src/page_params.ts | 3 +++ web/src/{realm_icon.js => realm_icon.ts} | 11 ++++++----- 3 files changed, 10 insertions(+), 6 deletions(-) rename web/src/{realm_icon.js => realm_icon.ts} (80%) diff --git a/tools/test-js-with-node b/tools/test-js-with-node index 03ba596e67..df7d71538e 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -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", diff --git a/web/src/page_params.ts b/web/src/page_params.ts index 772ff3ee9d..0d359a0ec1 100644 --- a/web/src/page_params.ts +++ b/web/src/page_params.ts @@ -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; diff --git a/web/src/realm_icon.js b/web/src/realm_icon.ts similarity index 80% rename from web/src/realm_icon.js rename to web/src/realm_icon.ts index c48e845835..eabea47d39 100644 --- a/web/src/realm_icon.js +++ b/web/src/realm_icon.ts @@ -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 { + return $("#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();