From 6bf1aecb6dbb844e118263c8a6431a950050c450 Mon Sep 17 00:00:00 2001 From: Parvesh Monu Date: Thu, 22 Aug 2024 10:55:05 +0530 Subject: [PATCH] Improve app theme naming and doc strings (#21107) --- src/legacy/status_im/events.cljs | 4 +- src/status_im/common/theme/events.cljs | 37 ++++++++++++++----- src/status_im/common/theme/utils.cljs | 17 --------- src/status_im/constants.cljs | 6 +-- .../contexts/profile/settings/events.cljs | 2 +- 5 files changed, 34 insertions(+), 32 deletions(-) delete mode 100644 src/status_im/common/theme/utils.cljs diff --git a/src/legacy/status_im/events.cljs b/src/legacy/status_im/events.cljs index 22a904c86c..9e5ccd7d37 100644 --- a/src/legacy/status_im/events.cljs +++ b/src/legacy/status_im/events.cljs @@ -99,9 +99,9 @@ (rf/defn system-theme-mode-changed {:events [:system-theme-mode-changed]} [{:keys [db] :as cofx} _] - (let [current-theme-type (get-in cofx [:db :profile/profile :appearance])] + (let [appearance-type (get-in cofx [:db :profile/profile :appearance])] (when (and (multiaccounts.model/logged-in? db) - (= current-theme-type status-im.constants/theme-type-system)) + (= appearance-type status-im.constants/appearance-type-system)) {:dispatch [:theme/switch]}))) (defn- on-biometric-auth-fail diff --git a/src/status_im/common/theme/events.cljs b/src/status_im/common/theme/events.cljs index 4fc45945fa..5cfbb0e6da 100644 --- a/src/status_im/common/theme/events.cljs +++ b/src/status_im/common/theme/events.cljs @@ -2,23 +2,42 @@ (:require [re-frame.core :as re-frame] [status-im.common.theme.core :as theme] - [status-im.common.theme.utils :as utils])) + [status-im.constants :as constants])) (re-frame/reg-fx :theme/init-theme (fn [] (theme/add-device-theme-change-listener))) +(defn- appearance-type->theme + "Converts appearance type identifier to a theme keyword. + Returns `:light` or `:dark` based on `appearance-type`: + - `appearance-type-light` (1): Light theme. + - `appearance-type-dark` (2): Dark theme. + - `appearance-type-system` (0): Uses system preference." + [appearance-type] + (condp = appearance-type + constants/appearance-type-dark :dark + constants/appearance-type-light :light + constants/appearance-type-system (if (theme/device-theme-dark?) :dark :light) + :dark)) + +;; Switches the theme and triggers related effects. +;; +;; Parameters: +;; - `theme`: Optional theme keyword to apply. If not provided, defaults to the theme determined by +;; `appearance-type`. +;; - `appearance-type`: Optional appearance type to determine the theme. If not provided, defaults to +;; the appearance type from the user's profile. +;; - `view-id`: Optional view ID for updating status and navigation color. If not provided, uses the +;; current view ID from the database. `view-id` is required because status and navigation bar colors +;; depends on the screen. For example, on the home screen, the navigation color should always be dark, +;; regardless of the theme, due to the bottom tabs. (re-frame/reg-event-fx :theme/switch - (fn [{db :db} [{:keys [theme view-id theme-type]}]] - "Switches the theme and triggers related effects. - Parameters: - - theme: Optional theme keyword to apply. If not provided, defaults to the theme determined by theme-type. - - theme-type: Optional theme type to determine the theme. If not provided, defaults to the theme type from the user's profile. - - view-id: Optional view ID for updating status color. If not provided, uses the current view ID from the database." - (let [theme-type (or theme-type (get-in db [:profile/profile :appearance])) - theme (or theme (utils/theme-type->theme-value theme-type))] + (fn [{db :db} [{:keys [theme view-id appearance-type]}]] + (let [appearance-type (or appearance-type (get-in db [:profile/profile :appearance])) + theme (or theme (appearance-type->theme appearance-type))] {:db (assoc db :theme theme) :fx [[:theme/legacy-theme-fx theme] [:dispatch diff --git a/src/status_im/common/theme/utils.cljs b/src/status_im/common/theme/utils.cljs deleted file mode 100644 index 574c23ddd0..0000000000 --- a/src/status_im/common/theme/utils.cljs +++ /dev/null @@ -1,17 +0,0 @@ -(ns status-im.common.theme.utils - (:require - [status-im.common.theme.core :as theme] - [status-im.constants :as constants])) - -(defn theme-type->theme-value - "Converts theme type identifier to a theme keyword. - Returns `:light` or `:dark` based on `theme-type`: - - `theme-type-light` (1): Light theme. - - `theme-type-dark` (2): Dark theme. - - `theme-type-system` (0): Uses system preference." - [theme-type] - (condp = theme-type - constants/theme-type-dark :dark - constants/theme-type-light :light - constants/theme-type-system (if (theme/device-theme-dark?) :dark :light) - :dark)) diff --git a/src/status_im/constants.cljs b/src/status_im/constants.cljs index ba72366292..b72bed8392 100644 --- a/src/status_im/constants.cljs +++ b/src/status_im/constants.cljs @@ -425,9 +425,9 @@ "We prefix our keys with 0xe701 prior to serialisation them" "0xe701") -(def ^:const theme-type-system 0) -(def ^:const theme-type-light 1) -(def ^:const theme-type-dark 2) +(def ^:const appearance-type-system 0) +(def ^:const appearance-type-light 1) +(def ^:const appearance-type-dark 2) (def ^:const bottom-sheet-animation-delay 450) (def ^:const local-pair-event-process-success "process-success") diff --git a/src/status_im/contexts/profile/settings/events.cljs b/src/status_im/contexts/profile/settings/events.cljs index 6a7cfb529d..3675195403 100644 --- a/src/status_im/contexts/profile/settings/events.cljs +++ b/src/status_im/contexts/profile/settings/events.cljs @@ -95,7 +95,7 @@ (rf/reg-event-fx :profile.settings/change-appearance (fn [_ [theme]] {:fx [[:dispatch [:profile.settings/profile-update :appearance theme]] - [:dispatch [:theme/switch {:theme-type theme}]]]})) + [:dispatch [:theme/switch {:appearance-type theme}]]]})) (rf/reg-fx :profile.settings/get-profile-picture (fn [key-uid]