mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	ts: Migrate avatar.js module to TypeScript.
				
					
				
			This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							8d7a9162e2
						
					
				
				
					commit
					5c2ba6c8fa
				
			@@ -53,7 +53,7 @@ EXEMPT_FILES = make_set(
 | 
				
			|||||||
        "web/src/archive.js",
 | 
					        "web/src/archive.js",
 | 
				
			||||||
        "web/src/assets.d.ts",
 | 
					        "web/src/assets.d.ts",
 | 
				
			||||||
        "web/src/attachments_ui.ts",
 | 
					        "web/src/attachments_ui.ts",
 | 
				
			||||||
        "web/src/avatar.js",
 | 
					        "web/src/avatar.ts",
 | 
				
			||||||
        "web/src/billing/event_status.ts",
 | 
					        "web/src/billing/event_status.ts",
 | 
				
			||||||
        "web/src/billing/helpers.ts",
 | 
					        "web/src/billing/helpers.ts",
 | 
				
			||||||
        "web/src/billing/upgrade.ts",
 | 
					        "web/src/billing/upgrade.ts",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,12 +8,13 @@ import {$t_html} from "./i18n";
 | 
				
			|||||||
import {page_params} from "./page_params";
 | 
					import {page_params} from "./page_params";
 | 
				
			||||||
import * as settings_data from "./settings_data";
 | 
					import * as settings_data from "./settings_data";
 | 
				
			||||||
import * as upload_widget from "./upload_widget";
 | 
					import * as upload_widget from "./upload_widget";
 | 
				
			||||||
 | 
					import type {UploadFunction, UploadWidget} from "./upload_widget";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function build_bot_create_widget() {
 | 
					export function build_bot_create_widget(): UploadWidget {
 | 
				
			||||||
    // We have to do strange gyrations with the file input to clear it,
 | 
					    // We have to do strange gyrations with the file input to clear it,
 | 
				
			||||||
    // where we replace it wholesale, so we generalize the file input with
 | 
					    // where we replace it wholesale, so we generalize the file input with
 | 
				
			||||||
    // a callback function.
 | 
					    // a callback function.
 | 
				
			||||||
    const get_file_input = function () {
 | 
					    const get_file_input = function (): JQuery<HTMLInputElement> {
 | 
				
			||||||
        return $("#bot_avatar_file_input");
 | 
					        return $("#bot_avatar_file_input");
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -34,9 +35,9 @@ export function build_bot_create_widget() {
 | 
				
			|||||||
    );
 | 
					    );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function build_bot_edit_widget($target) {
 | 
					export function build_bot_edit_widget($target: JQuery): UploadWidget {
 | 
				
			||||||
    const get_file_input = function () {
 | 
					    const get_file_input = function (): JQuery<HTMLInputElement> {
 | 
				
			||||||
        return $target.find(".edit_bot_avatar_file_input");
 | 
					        return $target.find<HTMLInputElement>(".edit_bot_avatar_file_input");
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const $file_name_field = $target.find(".edit_bot_avatar_file");
 | 
					    const $file_name_field = $target.find(".edit_bot_avatar_file");
 | 
				
			||||||
@@ -57,20 +58,20 @@ export function build_bot_edit_widget($target) {
 | 
				
			|||||||
    );
 | 
					    );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function display_avatar_delete_complete() {
 | 
					function display_avatar_delete_complete(): void {
 | 
				
			||||||
    $("#user-avatar-upload-widget .upload-spinner-background").css({visibility: "hidden"});
 | 
					    $("#user-avatar-upload-widget .upload-spinner-background").css({visibility: "hidden"});
 | 
				
			||||||
    $("#user-avatar-upload-widget .image-upload-text").show();
 | 
					    $("#user-avatar-upload-widget .image-upload-text").show();
 | 
				
			||||||
    $("#user-avatar-source").show();
 | 
					    $("#user-avatar-source").show();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function display_avatar_delete_started() {
 | 
					function display_avatar_delete_started(): void {
 | 
				
			||||||
    $("#user-avatar-upload-widget .upload-spinner-background").css({visibility: "visible"});
 | 
					    $("#user-avatar-upload-widget .upload-spinner-background").css({visibility: "visible"});
 | 
				
			||||||
    $("#user-avatar-upload-widget .image-upload-text").hide();
 | 
					    $("#user-avatar-upload-widget .image-upload-text").hide();
 | 
				
			||||||
    $("#user-avatar-upload-widget .image-delete-button").hide();
 | 
					    $("#user-avatar-upload-widget .image-delete-button").hide();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function build_user_avatar_widget(upload_function) {
 | 
					export function build_user_avatar_widget(upload_function: UploadFunction): void {
 | 
				
			||||||
    const get_file_input = function () {
 | 
					    const get_file_input = function (): JQuery<HTMLInputElement> {
 | 
				
			||||||
        return $("#user-avatar-upload-widget .image_file_input").expectOne();
 | 
					        return $("#user-avatar-upload-widget .image_file_input").expectOne();
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -88,9 +89,9 @@ export function build_user_avatar_widget(upload_function) {
 | 
				
			|||||||
    $("#user-avatar-upload-widget .image-delete-button").on("click", (e) => {
 | 
					    $("#user-avatar-upload-widget .image-delete-button").on("click", (e) => {
 | 
				
			||||||
        e.preventDefault();
 | 
					        e.preventDefault();
 | 
				
			||||||
        e.stopPropagation();
 | 
					        e.stopPropagation();
 | 
				
			||||||
        function delete_user_avatar() {
 | 
					        function delete_user_avatar(): void {
 | 
				
			||||||
            display_avatar_delete_started();
 | 
					            display_avatar_delete_started();
 | 
				
			||||||
            channel.del({
 | 
					            void channel.del({
 | 
				
			||||||
                url: "/json/users/me/avatar",
 | 
					                url: "/json/users/me/avatar",
 | 
				
			||||||
                success() {
 | 
					                success() {
 | 
				
			||||||
                    display_avatar_delete_complete();
 | 
					                    display_avatar_delete_complete();
 | 
				
			||||||
@@ -106,7 +107,7 @@ export function build_user_avatar_widget(upload_function) {
 | 
				
			|||||||
                },
 | 
					                },
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        const html_body = render_confirm_delete_user_avatar();
 | 
					        const html_body = render_confirm_delete_user_avatar({});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        confirm_dialog.launch({
 | 
					        confirm_dialog.launch({
 | 
				
			||||||
            html_heading: $t_html({defaultMessage: "Delete profile picture"}),
 | 
					            html_heading: $t_html({defaultMessage: "Delete profile picture"}),
 | 
				
			||||||
@@ -3,6 +3,7 @@ import $ from "jquery";
 | 
				
			|||||||
const t1 = performance.now();
 | 
					const t1 = performance.now();
 | 
				
			||||||
export const page_params: {
 | 
					export const page_params: {
 | 
				
			||||||
    apps_page_url: string;
 | 
					    apps_page_url: string;
 | 
				
			||||||
 | 
					    avatar_source: string;
 | 
				
			||||||
    corporate_enabled: boolean;
 | 
					    corporate_enabled: boolean;
 | 
				
			||||||
    development_environment: boolean;
 | 
					    development_environment: boolean;
 | 
				
			||||||
    language_list: {
 | 
					    language_list: {
 | 
				
			||||||
@@ -19,6 +20,7 @@ export const page_params: {
 | 
				
			|||||||
    is_moderator: boolean;
 | 
					    is_moderator: boolean;
 | 
				
			||||||
    is_owner: boolean;
 | 
					    is_owner: boolean;
 | 
				
			||||||
    is_spectator: boolean;
 | 
					    is_spectator: boolean;
 | 
				
			||||||
 | 
					    max_avatar_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;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,16 @@
 | 
				
			|||||||
import {$t} from "./i18n";
 | 
					import {$t} from "./i18n";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export type UploadWidget = {
 | 
				
			||||||
 | 
					    clear(): void;
 | 
				
			||||||
 | 
					    close(): void;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export type UploadFunction = (
 | 
				
			||||||
 | 
					    $file_input: JQuery<HTMLInputElement>,
 | 
				
			||||||
 | 
					    night: boolean | null,
 | 
				
			||||||
 | 
					    icon: boolean,
 | 
				
			||||||
 | 
					) => void;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const default_max_file_size = 5;
 | 
					const default_max_file_size = 5;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const supported_types = ["image/jpeg", "image/png", "image/gif", "image/tiff"];
 | 
					const supported_types = ["image/jpeg", "image/png", "image/gif", "image/tiff"];
 | 
				
			||||||
@@ -26,7 +37,7 @@ export function build_widget(
 | 
				
			|||||||
    $preview_text?: JQuery,
 | 
					    $preview_text?: JQuery,
 | 
				
			||||||
    $preview_image?: JQuery,
 | 
					    $preview_image?: JQuery,
 | 
				
			||||||
    max_file_upload_size = default_max_file_size,
 | 
					    max_file_upload_size = default_max_file_size,
 | 
				
			||||||
): {clear(): void; close(): void} {
 | 
					): UploadWidget {
 | 
				
			||||||
    function accept(file: File): void {
 | 
					    function accept(file: File): void {
 | 
				
			||||||
        $file_name_field.text(file.name);
 | 
					        $file_name_field.text(file.name);
 | 
				
			||||||
        $input_error.hide();
 | 
					        $input_error.hide();
 | 
				
			||||||
@@ -123,11 +134,7 @@ export function build_direct_upload_widget(
 | 
				
			|||||||
    $input_error: JQuery,
 | 
					    $input_error: JQuery,
 | 
				
			||||||
    // jQuery button to open file dialog
 | 
					    // jQuery button to open file dialog
 | 
				
			||||||
    $upload_button: JQuery,
 | 
					    $upload_button: JQuery,
 | 
				
			||||||
    upload_function: (
 | 
					    upload_function: UploadFunction,
 | 
				
			||||||
        $file_input: JQuery<HTMLInputElement>,
 | 
					 | 
				
			||||||
        night: boolean | null,
 | 
					 | 
				
			||||||
        icon: boolean,
 | 
					 | 
				
			||||||
    ) => void,
 | 
					 | 
				
			||||||
    max_file_upload_size = default_max_file_size,
 | 
					    max_file_upload_size = default_max_file_size,
 | 
				
			||||||
): void {
 | 
					): void {
 | 
				
			||||||
    // default value of max uploaded file size
 | 
					    // default value of max uploaded file size
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user