Make recent colors to be stored locally instead of on file

This commit is contained in:
Andrey Antukh 2024-09-03 15:47:24 +02:00
parent 52d099c80e
commit e9c55e9eb4
6 changed files with 42 additions and 38 deletions

View file

@ -190,10 +190,9 @@
[:type [:= :del-color]] [:type [:= :del-color]]
[:id ::sm/uuid]]] [:id ::sm/uuid]]]
;; DEPRECATED: remove before 2.3
[:add-recent-color [:add-recent-color
[:map {:title "AddRecentColorChange"} [:map {:title "AddRecentColorChange"}]]
[:type [:= :add-recent-color]]
[:color ::ctc/recent-color]]]
[:add-media [:add-media
[:map {:title "AddMediaChange"} [:map {:title "AddMediaChange"}
@ -656,18 +655,10 @@
[data {:keys [id]}] [data {:keys [id]}]
(ctcl/delete-color data id)) (ctcl/delete-color data id))
;; DEPRECATED: remove before 2.3
(defmethod process-change :add-recent-color (defmethod process-change :add-recent-color
[data {:keys [color]}] [data _]
;; Moves the color to the top of the list and then truncates up to 15 data)
(update
data
:recent-colors
(fn [rc]
(let [rc (->> rc (d/removev (partial ctc/eq-recent-color? color)))
rc (-> rc (conj color))]
(cond-> rc
(> (count rc) 15)
(subvec 1))))))
;; -- Media ;; -- Media

View file

@ -607,13 +607,6 @@
(reduce resize-parent changes all-parents))) (reduce resize-parent changes all-parents)))
;; Library changes ;; Library changes
(defn add-recent-color
[changes color]
(-> changes
(update :redo-changes conj {:type :add-recent-color :color color})
(apply-changes-local)))
(defn add-color (defn add-color
[changes color] [changes color]
(-> changes (-> changes

View file

@ -107,17 +107,16 @@
[::sm/contains-any {:strict true} [:color :gradient :image]]]) [::sm/contains-any {:strict true} [:color :gradient :image]]])
(sm/register! ::rgb-color type:rgb-color) (sm/register! ::rgb-color type:rgb-color)
(sm/register! ::color schema:color) (sm/register! ::color schema:color)
(sm/register! ::gradient schema:gradient) (sm/register! ::gradient schema:gradient)
(sm/register! ::image-color schema:image-color) (sm/register! ::image-color schema:image-color)
(sm/register! ::recent-color schema:recent-color) (sm/register! ::recent-color schema:recent-color)
(def check-color! (def valid-color?
(sm/check-fn schema:color)) (sm/lazy-validator schema:color))
(def check-recent-color! (def valid-recent-color?
(sm/check-fn schema:recent-color)) (sm/lazy-validator schema:recent-color))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; HELPERS ;; HELPERS
@ -392,13 +391,22 @@
(process-shape-colors shape sync-color))) (process-shape-colors shape sync-color)))
(defn eq-recent-color? (defn- eq-recent-color?
[c1 c2] [c1 c2]
(or (= c1 c2) (or (= c1 c2)
(and (some? (:color c1)) (and (some? (:color c1))
(some? (:color c2)) (some? (:color c2))
(= (:color c1) (:color c2))))) (= (:color c1) (:color c2)))))
(defn add-recent-color
"Moves the color to the top of the list and then truncates up to 15"
[state file-id color]
(update state file-id (fn [colors]
(let [colors (d/removev (partial eq-recent-color? color) colors)
colors (conj colors color)]
(cond-> colors
(> (count colors) 15)
(subvec 1))))))
(defn stroke->color-att (defn stroke->color-att
[stroke file-id shared-libs] [stroke file-id shared-libs]

View file

@ -79,6 +79,7 @@
[app.util.http :as http] [app.util.http :as http]
[app.util.i18n :as i18n :refer [tr]] [app.util.i18n :as i18n :refer [tr]]
[app.util.router :as rt] [app.util.router :as rt]
[app.util.storage :refer [storage]]
[app.util.timers :as tm] [app.util.timers :as tm]
[app.util.webapi :as wapi] [app.util.webapi :as wapi]
[beicon.v2.core :as rx] [beicon.v2.core :as rx]
@ -335,6 +336,7 @@
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(assoc state (assoc state
:recent-colors (:recent-colors @storage)
:workspace-ready? false :workspace-ready? false
:current-file-id file-id :current-file-id file-id
:current-project-id project-id :current-project-id project-id

View file

@ -48,6 +48,7 @@
[app.util.color :as uc] [app.util.color :as uc]
[app.util.i18n :refer [tr]] [app.util.i18n :refer [tr]]
[app.util.router :as rt] [app.util.router :as rt]
[app.util.storage :as s]
[app.util.time :as dt] [app.util.time :as dt]
[beicon.v2.core :as rx] [beicon.v2.core :as rx]
[cuerdas.core :as str] [cuerdas.core :as str]
@ -132,16 +133,21 @@
(defn add-recent-color (defn add-recent-color
[color] [color]
(dm/assert! (dm/assert!
"expected valid recent color map" "expected valid recent color map"
(ctc/check-recent-color! color)) (ctc/valid-recent-color? color))
(ptk/reify ::add-recent-color (ptk/reify ::add-recent-color
ptk/WatchEvent ptk/UpdateEvent
(watch [it _ _] (update [_ state]
(let [changes (-> (pcb/empty-changes it) (let [file-id (:current-file-id state)]
(pcb/add-recent-color color))] (update state :recent-colors ctc/add-recent-color file-id color)))
(rx/of (dch/commit-changes changes))))))
ptk/EffectEvent
(effect [_ state _]
(let [recent-colors (:recent-colors state)]
(swap! s/storage assoc :recent-colors recent-colors)))))
(def clear-color-for-rename (def clear-color-for-rename
(ptk/reify ::clear-color-for-rename (ptk/reify ::clear-color-for-rename
@ -168,8 +174,11 @@
(dm/assert! (dm/assert!
"expected valid parameters" "expected valid parameters"
(and (ctc/check-color! color) (ctc/valid-color? color))
(uuid? file-id)))
(dm/assert!
"expected file-id"
(uuid? file-id))
(ptk/reify ::update-color (ptk/reify ::update-color
ptk/WatchEvent ptk/WatchEvent

View file

@ -236,9 +236,10 @@
=)) =))
(def workspace-recent-colors (def workspace-recent-colors
(l/derived (fn [data] (l/derived (fn [state]
(get data :recent-colors [])) (when-let [file-id (:current-file-id state)]
workspace-data)) (dm/get-in state [:recent-colors file-id])))
st/state))
(def workspace-recent-fonts (def workspace-recent-fonts
(l/derived (fn [data] (l/derived (fn [data]