Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

profile_settings: Convert timezone picker to dropdownwidget.

kash210430479667ae1b
diff --git a/web/src/settings_account.ts b/web/src/settings_account.ts
index 2ef70bf29a7..75b738bca9d 100644
--- a/web/src/settings_account.ts
+++ b/web/src/settings_account.ts
@@ -2,6 +2,7 @@ import $ from "jquery";
import assert from "minimalistic-assert";
import * as z from "zod/mini";
+import timezones from "../generated/timezones.json";
import render_change_email_modal from "../templates/change_email_modal.hbs";
import render_demo_organization_add_email_modal from "../templates/demo_organization_add_email_modal.hbs";
import render_dialog_change_password from "../templates/dialog_change_password.hbs";
@@ -16,7 +17,8 @@ import {csrf_token} from "./csrf.ts";
import * as custom_profile_fields_ui from "./custom_profile_fields_ui.ts";
import type {CustomProfileFieldData, PillUpdateField} from "./custom_profile_fields_ui.ts";
import * as dialog_widget from "./dialog_widget.ts";
-import {$t_html} from "./i18n.ts";
+import * as dropdown_widget from "./dropdown_widget.ts";
+import {$t, $t_html} from "./i18n.ts";
import * as keydown_util from "./keydown_util.ts";
import * as modals from "./modals.ts";
import * as overlays from "./overlays.ts";
@@ -41,6 +43,7 @@ let password_quality:
| ((password: string, $bar: JQuery | undefined, $password_field: JQuery) => boolean)
| undefined; // Loaded asynchronously
let user_avatar_widget_created = false;
+let user_timezone_dropdown_widget: dropdown_widget.DropdownWidget | undefined;
export function update_email(new_email: string): void {
const $email_input = $("#email_field_container");
@@ -256,6 +259,47 @@ export function update_privacy_settings_box(property: PrivacySettingName): void
settings_components.set_input_element_value($input_elem, user_settings[property]);
}
+export function render_user_timezone_dropdown_widget(): void {
+ const timezone_items = timezones.timezones.map((tz: {name: string; utc_offset: string}) => ({
+ name: `${tz.name} (${tz.utc_offset})`,
+ unique_id: tz.name,
+ }));
+
+ const opts: dropdown_widget.DropdownWidgetOptions = {
+ widget_name: "user_timezone",
+ get_options: () => timezone_items,
+ item_click_callback(event, dropdown, widget) {
+ dropdown.hide();
+ event.preventDefault();
+ event.stopPropagation();
+ const selected = widget.value()!;
+
+ widget.render(selected);
+ settings_ui.do_settings_change(
+ channel.patch,
+ "/json/settings",
+ {timezone: selected},
+ $(".timezone-setting-status").expectOne(),
+ {
+ error_continuation() {
+ widget.render(user_settings.timezone);
+ },
+ },
+ );
+ },
+ $events_container: $("#profile-settings"),
+ default_id: user_settings.timezone,
+ unique_id_type: "string",
+ search_placeholder_text: $t({defaultMessage: "Your time zone"}),
+ text_if_current_value_not_in_options: $t({
+ defaultMessage: "Select a time zone",
+ }),
+ };
+
+ user_timezone_dropdown_widget = new dropdown_widget.DropdownWidget(opts);
+ user_timezone_dropdown_widget.setup();
+}
+
export function set_up(): void {
// Add custom profile fields elements to user account settings.
add_custom_profile_fields_to_settings();
@@ -824,21 +868,7 @@ export function set_up(): void {
user_avatar_widget_created = true;
}
- $("#user_timezone").val(user_settings.timezone);
-
- $<HTMLSelectElement>("select#user_timezone").on("change", function (e) {
- e.preventDefault();
- e.stopPropagation();
-
- const data = {timezone: this.value};
-
- settings_ui.do_settings_change(
- channel.patch,
- "/json/settings",
- data,
- $(".timezone-setting-status").expectOne(),
- );
- });
+ render_user_timezone_dropdown_widget();
$<HTMLInputElement>("#automatically_offer_update_time_zone").on("change", function (e) {
e.preventDefault();
diff --git a/web/styles/settings.css b/web/styles/settings.css
index 54edc59ed3a..26e74876ff2 100644
--- a/web/styles/settings.css
+++ b/web/styles/settings.css
@@ -810,6 +810,10 @@ input[type="checkbox"] {
border: none;
}
+.user_timezone-dropdown-list-container {
+ width: calc(var(--modal-input-width));
+}
+
#profile-settings {
.custom-profile-fields-form .custom_user_field label,
.full-name-change-container label,
diff --git a/web/templates/settings/profile_settings.hbs b/web/templates/settings/profile_settings.hbs
index 398f18cc89d..290814b7214 100644
--- a/web/templates/settings/profile_settings.hbs
+++ b/web/templates/settings/profile_settings.hbs
@@ -18,19 +18,16 @@
<form class="timezone-setting-form">
<div class="input-group grid">
- <label for="user_timezone" class="settings-field-label inline-block">{{t "Time zone" }}</label>
+ <label for="user_timezone_widget" class="settings-field-label inline-block">{{t "Time zone" }}</label>
<div class="alert-notification timezone-setting-status"></div>
<div class="timezone-input">
- <select name="timezone" id="user_timezone" class="bootstrap-focus-style settings_select">
- {{#unless settings_object.timezone}}
- <option></option>
- {{/unless}}
-
- {{#each timezones}}
- <option value="{{ this.name }}">{{ this.name }} ({{ this.utc_offset }})</option>
-
- {{/each}}
- </select>
+ {{> ../dropdown_widget_with_label
+ widget_name="user_timezone"
+ label=""
+ value_type="string"
+ value=settings_object.timezone
+ custom_classes="timezone-dropdown-widget"
+ }}
</div>
</div>
<div id="automatically_offer_update_time_zone_container">