From 241715582837056dfb10ba3fd33a1c3a6da5201a Mon Sep 17 00:00:00 2001 From: Sayam Samal Date: Thu, 20 Jun 2024 01:59:48 +0530 Subject: [PATCH] theme: Rename dark_theme.ts -> theme.ts. The dark_theme module now contains logic for light, dark, and automatic theme switching. Thus, we rename it a more generic name, `theme.ts`. --- tools/test-js-with-node | 2 +- web/src/gear_menu.js | 4 ++-- web/src/server_events_dispatch.js | 4 ++-- web/src/{dark_theme.ts => theme.ts} | 0 web/src/ui_init.js | 4 ++-- web/src/zcommand.ts | 6 +++--- web/tests/dispatch.test.js | 8 ++++---- 7 files changed, 14 insertions(+), 14 deletions(-) rename web/src/{dark_theme.ts => theme.ts} (100%) diff --git a/tools/test-js-with-node b/tools/test-js-with-node index 554459d668..13f7160b52 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -91,7 +91,6 @@ EXEMPT_FILES = make_set( "web/src/css_variables.d.ts", "web/src/css_variables.js", "web/src/custom_profile_fields_ui.ts", - "web/src/dark_theme.ts", "web/src/debug.ts", "web/src/demo_organizations_ui.js", "web/src/deprecated_feature_notice.ts", @@ -248,6 +247,7 @@ EXEMPT_FILES = make_set( "web/src/stream_ui_updates.js", "web/src/submessage.ts", "web/src/subscriber_api.ts", + "web/src/theme.ts", "web/src/timerender.ts", "web/src/tippyjs.ts", "web/src/todo_widget.js", diff --git a/web/src/gear_menu.js b/web/src/gear_menu.js index 8e98727bd9..1ef1428c3c 100644 --- a/web/src/gear_menu.js +++ b/web/src/gear_menu.js @@ -5,11 +5,11 @@ import render_navbar_gear_menu_popover from "../templates/popovers/navbar/navbar import * as blueslip from "./blueslip"; import * as channel from "./channel"; -import * as dark_theme from "./dark_theme"; import * as popover_menus from "./popover_menus"; import * as popover_menus_data from "./popover_menus_data"; import * as popovers from "./popovers"; import * as settings_preferences from "./settings_preferences"; +import * as theme from "./theme"; import {parse_html} from "./ui_util"; /* @@ -159,7 +159,7 @@ export function initialize() { $popper.on("change", "input[name='theme-select']", (e) => { const theme_code = Number.parseInt($(e.currentTarget).attr("data-theme-code"), 10); requestAnimationFrame(() => { - dark_theme.set_theme_for_spectator(theme_code); + theme.set_theme_for_spectator(theme_code); }); }); }, diff --git a/web/src/server_events_dispatch.js b/web/src/server_events_dispatch.js index 65f4063109..f3215b3627 100644 --- a/web/src/server_events_dispatch.js +++ b/web/src/server_events_dispatch.js @@ -15,7 +15,6 @@ import * as compose_call_ui from "./compose_call_ui"; import * as compose_pm_pill from "./compose_pm_pill"; import * as compose_recipient from "./compose_recipient"; import * as compose_state from "./compose_state"; -import * as dark_theme from "./dark_theme"; import * as emoji from "./emoji"; import * as emoji_picker from "./emoji_picker"; import * as gear_menu from "./gear_menu"; @@ -77,6 +76,7 @@ import * as stream_topic_history from "./stream_topic_history"; import * as stream_ui_updates from "./stream_ui_updates"; import * as sub_store from "./sub_store"; import * as submessage from "./submessage"; +import * as theme from "./theme"; import * as typing_events from "./typing_events"; import * as unread_ops from "./unread_ops"; import * as unread_ui from "./unread_ui"; @@ -791,7 +791,7 @@ export function dispatch_normal_event(event) { } if (event.property === "color_scheme") { requestAnimationFrame(() => { - dark_theme.set_theme_and_update(event.value); + theme.set_theme_and_update(event.value); }); } if (event.property === "starred_message_counts") { diff --git a/web/src/dark_theme.ts b/web/src/theme.ts similarity index 100% rename from web/src/dark_theme.ts rename to web/src/theme.ts diff --git a/web/src/ui_init.js b/web/src/ui_init.js index c551962010..91499e0f3e 100644 --- a/web/src/ui_init.js +++ b/web/src/ui_init.js @@ -35,7 +35,6 @@ import * as compose_tooltips from "./compose_tooltips"; import * as composebox_typeahead from "./composebox_typeahead"; import * as condense from "./condense"; import * as copy_and_paste from "./copy_and_paste"; -import * as dark_theme from "./dark_theme"; import * as desktop_integration from "./desktop_integration"; import * as desktop_notifications from "./desktop_notifications"; import * as drafts from "./drafts"; @@ -126,6 +125,7 @@ import * as stream_settings_ui from "./stream_settings_ui"; import * as stream_topic_history from "./stream_topic_history"; import * as stream_topic_history_util from "./stream_topic_history_util"; import * as sub_store from "./sub_store"; +import * as theme from "./theme"; import * as timerender from "./timerender"; import * as tippyjs from "./tippyjs"; import * as topic_list from "./topic_list"; @@ -422,7 +422,7 @@ export function initialize_everything(state_data) { sidebar_ui.restore_sidebar_toggle_status(); information_density.initialize(); if (page_params.is_spectator) { - dark_theme.initialize_theme_for_spectator(); + theme.initialize_theme_for_spectator(); } i18n.initialize({language_list: page_params.language_list}); diff --git a/web/src/zcommand.ts b/web/src/zcommand.ts index f0b5d02b90..05116e8493 100644 --- a/web/src/zcommand.ts +++ b/web/src/zcommand.ts @@ -3,11 +3,11 @@ import {z} from "zod"; import * as channel from "./channel"; import * as compose_banner from "./compose_banner"; -import * as dark_theme from "./dark_theme"; import * as feedback_widget from "./feedback_widget"; import {$t} from "./i18n"; import * as markdown from "./markdown"; import * as settings_config from "./settings_config"; +import * as theme from "./theme"; /* @@ -68,7 +68,7 @@ export function switch_to_light_theme(): void { on_success(raw_data) { const data = data_schema.parse(raw_data); requestAnimationFrame(() => { - dark_theme.set_theme_and_update(settings_config.color_scheme_values.day.code); + theme.set_theme_and_update(settings_config.color_scheme_values.day.code); }); feedback_widget.show({ populate($container) { @@ -93,7 +93,7 @@ export function switch_to_dark_theme(): void { on_success(raw_data) { const data = data_schema.parse(raw_data); requestAnimationFrame(() => { - dark_theme.set_theme_and_update(settings_config.color_scheme_values.night.code); + theme.set_theme_and_update(settings_config.color_scheme_values.night.code); }); feedback_widget.show({ populate($container) { diff --git a/web/tests/dispatch.test.js b/web/tests/dispatch.test.js index 8ef590a8ee..92b263b669 100644 --- a/web/tests/dispatch.test.js +++ b/web/tests/dispatch.test.js @@ -29,7 +29,7 @@ const attachments_ui = mock_esm("../src/attachments_ui"); const audible_notifications = mock_esm("../src/audible_notifications"); const bot_data = mock_esm("../src/bot_data"); const compose_pm_pill = mock_esm("../src/compose_pm_pill"); -const dark_theme = mock_esm("../src/dark_theme"); +const theme = mock_esm("../src/theme"); const emoji_picker = mock_esm("../src/emoji_picker"); const gear_menu = mock_esm("../src/gear_menu"); const information_density = mock_esm("../src/information_density"); @@ -969,7 +969,7 @@ run_test("user_settings", ({override}) => { const stub = make_stub(); event = event_fixtures.user_settings__color_scheme_automatic; user_settings.color_scheme = 2; - override(dark_theme, "set_theme_and_update", stub.f); // automatically checks if called + override(theme, "set_theme_and_update", stub.f); // automatically checks if called dispatch(event); const args = stub.get_args("color_scheme_code"); assert.equal(stub.num_calls, 1); @@ -980,7 +980,7 @@ run_test("user_settings", ({override}) => { const stub = make_stub(); event = event_fixtures.user_settings__color_scheme_dark; user_settings.color_scheme = 1; - override(dark_theme, "set_theme_and_update", stub.f); // automatically checks if called + override(theme, "set_theme_and_update", stub.f); // automatically checks if called dispatch(event); const args = stub.get_args("color_scheme_code"); assert.equal(stub.num_calls, 1); @@ -991,7 +991,7 @@ run_test("user_settings", ({override}) => { const stub = make_stub(); event = event_fixtures.user_settings__color_scheme_light; user_settings.color_scheme = 1; - override(dark_theme, "set_theme_and_update", stub.f); // automatically checks if called + override(theme, "set_theme_and_update", stub.f); // automatically checks if called dispatch(event); const args = stub.get_args("color_scheme_code"); assert.equal(stub.num_calls, 1);