Merge pull request #6605 from penpot/niwinz-develop-fixes-1

🐛 Fix default theme setup
This commit is contained in:
Alejandro Alonso 2025-06-02 07:02:59 +02:00 committed by GitHub
commit 04f0f77cd8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 44 additions and 46 deletions

View file

@ -107,11 +107,19 @@ jobs:
keys: keys:
- v1-dependencies-{{ checksum "frontend/deps.edn"}}-{{ checksum "frontend/yarn.lock" }} - v1-dependencies-{{ checksum "frontend/deps.edn"}}-{{ checksum "frontend/yarn.lock" }}
- run:
name: "install dependencies"
working_directory: "./frontend"
# We install playwright here because the dependent tasks
# uses the same cache as this task so we prepopulate it
command: |
yarn install
yarn run playwright install chromium
- run: - run:
name: "lint scss on frontend" name: "lint scss on frontend"
working_directory: "./frontend" working_directory: "./frontend"
command: | command: |
yarn install
yarn run lint:scss yarn run lint:scss
- run: - run:
@ -125,6 +133,7 @@ jobs:
- ~/.m2 - ~/.m2
- ~/.yarn - ~/.yarn
- ~/.gitlibs - ~/.gitlibs
- ~/.cache/ms-playwright
key: v1-dependencies-{{ checksum "frontend/deps.edn"}}-{{ checksum "frontend/yarn.lock" }} key: v1-dependencies-{{ checksum "frontend/deps.edn"}}-{{ checksum "frontend/yarn.lock" }}
test-components: test-components:

View file

@ -27,7 +27,6 @@
[app.plugins :as plugins] [app.plugins :as plugins]
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.i18n :as i18n] [app.util.i18n :as i18n]
[app.util.theme :as theme]
[beicon.v2.core :as rx] [beicon.v2.core :as rx]
[debug] [debug]
[features] [features]
@ -96,8 +95,7 @@
(cur/init-styles) (cur/init-styles)
(thr/init!) (thr/init!)
(init-ui) (init-ui)
(st/emit! (theme/initialize) (st/emit! (plugins/initialize)
(plugins/initialize)
(initialize))) (initialize)))
(defn ^:export reinit (defn ^:export reinit

View file

@ -28,7 +28,6 @@
[app.main.ui.onboarding.team-choice :refer [onboarding-team-modal]] [app.main.ui.onboarding.team-choice :refer [onboarding-team-modal]]
[app.main.ui.releases :refer [release-notes-modal]] [app.main.ui.releases :refer [release-notes-modal]]
[app.main.ui.static :as static] [app.main.ui.static :as static]
[app.util.dom :as dom]
[app.util.i18n :refer [tr]] [app.util.i18n :refer [tr]]
[app.util.theme :as theme] [app.util.theme :as theme]
[beicon.v2.core :as rx] [beicon.v2.core :as rx]
@ -358,13 +357,10 @@
[] []
(let [route (mf/deref refs/route) (let [route (mf/deref refs/route)
edata (mf/deref refs/exception) edata (mf/deref refs/exception)
profile (mf/deref refs/profile) profile (mf/deref refs/profile)]
profile-theme (:theme profile)
system-theme (mf/deref theme/preferred-color-scheme)]
(mf/with-effect [profile-theme system-theme] ;; initialize themes
(dom/set-html-theme-color (theme/use-initialize profile)
(if (= profile-theme "system") system-theme profile-theme)))
[:& (mf/provider ctx/current-route) {:value route} [:& (mf/provider ctx/current-route) {:value route}
[:& (mf/provider ctx/current-profile) {:value profile} [:& (mf/provider ctx/current-profile) {:value profile}

View file

@ -14,6 +14,7 @@
[app.main.ui.components.forms :as fm] [app.main.ui.components.forms :as fm]
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.i18n :as i18n :refer [tr]] [app.util.i18n :as i18n :refer [tr]]
[app.util.theme :as theme]
[rumext.v2 :as mf])) [rumext.v2 :as mf]))
(def ^:private schema:options-form (def ^:private schema:options-form
@ -37,6 +38,7 @@
(let [profile (mf/deref refs/profile) (let [profile (mf/deref refs/profile)
initial (mf/with-memo [profile] initial (mf/with-memo [profile]
(update profile :lang #(or % ""))) (update profile :lang #(or % "")))
form (fm/use-form :schema schema:options-form form (fm/use-form :schema schema:options-form
:initial initial)] :initial initial)]
@ -58,7 +60,7 @@
[:div {:class (stl/css :fields-row)} [:div {:class (stl/css :fields-row)}
[:& fm/select {:label (tr "dashboard.select-ui-theme") [:& fm/select {:label (tr "dashboard.select-ui-theme")
:name :theme :name :theme
:default "default" :default theme/default
:options [{:label (tr "dashboard.select-ui-theme.dark") :value "dark"} :options [{:label (tr "dashboard.select-ui-theme.dark") :value "dark"}
{:label (tr "dashboard.select-ui-theme.light") :value "light"} {:label (tr "dashboard.select-ui-theme.light") :value "light"}
{:label (tr "dashboard.select-ui-theme.system") :value "system"}] {:label (tr "dashboard.select-ui-theme.system") :value "system"}]

View file

@ -70,17 +70,6 @@
[^string title] [^string title]
(set! (.-title globals/document) title)) (set! (.-title globals/document) title))
(defn set-html-lang!
[^string lang]
(.setAttribute (.querySelector js/document "html") "lang" lang))
(defn set-html-theme-color
[^string color]
(let [node (.querySelector js/document "body")
class (if (= color "dark") "default" "light")]
(.removeAttribute node "class")
(.add ^js (.-classList ^js node) class)))
(defn set-page-style! (defn set-page-style!
[styles] [styles]
(let [node (first (get-elements-by-tag globals/document "head")) (let [node (first (get-elements-by-tag globals/document "head"))

View file

@ -6,33 +6,37 @@
(ns app.util.theme (ns app.util.theme
(:require (:require
[app.common.data :as d]
[app.util.globals :as globals] [app.util.globals :as globals]
[beicon.v2.core :as rx] [beicon.v2.core :as rx]
[potok.v2.core :as ptk])) [rumext.v2 :as mf]))
(defonce ^:private color-scheme-media-query
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Set the preferred color scheme based on the user's system settings.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defonce ^:private color-scheme-mq
(.matchMedia globals/window "(prefers-color-scheme: dark)")) (.matchMedia globals/window "(prefers-color-scheme: dark)"))
;; This atom is referenced in app.main.ui.app (def ^:const default "dark")
(defonce preferred-color-scheme
(atom (if (.-matches color-scheme-mq) "dark" "light")))
(defonce prefers-color-scheme-sub (defn- set-color-scheme
(let [sub (rx/behavior-subject "dark") [^string color]
ob (->> (rx/from-event color-scheme-mq "change")
(rx/map #(if (.-matches %) "dark" "light")))]
(rx/sub! ob sub)
sub))
(defn initialize (let [node (.querySelector js/document "body")
[] class (if (= color "dark") "default" "light")]
(ptk/reify ::initialize (.removeAttribute node "class")
ptk/WatchEvent (.add ^js (.-classList ^js node) class)))
(watch [_ _ _]
(->> prefers-color-scheme-sub (defn use-initialize
(rx/map #(reset! preferred-color-scheme %)))))) [{profile-theme :theme}]
(let [system-theme* (mf/use-state #(if (.-matches color-scheme-media-query) "dark" "light"))
system-theme (deref system-theme*)]
(mf/with-effect []
(let [s (->> (rx/from-event color-scheme-media-query "change")
(rx/map #(if (.-matches %) "dark" "light"))
(rx/subs! #(reset! system-theme* %)))]
(fn []
(rx/dispose! s))))
(mf/with-effect [system-theme profile-theme]
(set-color-scheme
(if (= profile-theme "system") system-theme
(d/nilv profile-theme "dark"))))))