Skip to content

Commit d789f36

Browse files
committed
cut down saved info
1 parent aca028e commit d789f36

File tree

4 files changed

+34
-23
lines changed

4 files changed

+34
-23
lines changed

src/renderer/dialog/views.cljs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
[:button.button.px-2.bg-primary.rounded.flex-1
6868
{:auto-focus true
6969
:on-click #(do (rf/dispatch [::dialog.e/close])
70-
(rf/dispatch [::document.e/save-and-close]))}
70+
(rf/dispatch [::document.e/save-and-close k]))}
7171
"Save"]]
7272
[close-button]]))
7373

src/renderer/document/events.cljs

+6-6
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,13 @@
182182

183183
(rf/reg-event-fx
184184
::save-and-close
185-
(fn [{:keys [db]} [_]]
186-
(let [document (h/save-format db)]
185+
(fn [{:keys [db]} [_ k]]
186+
(let [document (h/save-format db k)]
187187
(if platform/electron?
188188
{:ipc-invoke ["save-document"
189189
(pr-str document)
190190
#(do (rf/dispatch [::saved (edn/read-string %)])
191-
(rf/dispatch [::close (:key document) false]))]}
191+
(rf/dispatch [::close k false]))]}
192192
{::fx/save-as document}))))
193193

194194
(rf/reg-event-fx
@@ -203,12 +203,12 @@
203203

204204
(rf/reg-event-db
205205
::saved
206-
(fn [db [_ document-info]]
206+
(fn [db [_ {:keys [path] :as document-info}]]
207207
;; Update the path, the title and the saved position of the document.
208208
;; Any other changes that could happen while saving should be preserved.
209209
(-> db
210-
(update-in [:documents (:key document-info)] merge document-info)
211-
(h/add-recent (:path document-info)))))
210+
(update-in [:documents (h/search-by-path db path)] merge document-info)
211+
(h/add-recent path))))
212212

213213
(rf/reg-event-db
214214
::clear-recent

src/renderer/document/handlers.cljs

+22-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
(ns renderer.document.handlers
22
(:require
3+
[config :as config]
34
[malli.core :as m]
45
[malli.transform :as mt]
56
[renderer.document.db :as db]
@@ -9,12 +10,18 @@
910
[renderer.utils.vec :as vec]))
1011

1112
(defn save-format
12-
[db]
13-
(-> db
14-
element.h/deselect
15-
(get-in [:documents (:active-document db)])
16-
(assoc :save (history.h/current-position db))
17-
(dissoc :history)))
13+
([db]
14+
(save-format db (:active-document db)))
15+
([db k]
16+
(let [document (-> db
17+
(get-in [:documents k])
18+
(select-keys [:elements :path])
19+
(assoc :save (history.h/current-position db)
20+
:version config/version))]
21+
22+
(reduce #(update-in %1 [:elements %2] dissoc :selected?)
23+
document
24+
(keys (:elements document))))))
1825

1926
(defn close
2027
[{:keys [active-document document-tabs] :as db} k]
@@ -41,7 +48,7 @@
4148
[db k]
4249
(assoc db :active-document k))
4350

44-
(defn- search-by-path
51+
(defn search-by-path
4552
[{:keys [documents]} file-path]
4653
(some #(when (and file-path (= (:path %) file-path)) (:key %)) (vals documents)))
4754

@@ -65,14 +72,15 @@
6572
(assoc :active-document k)
6673
(update :document-tabs #(vec/add % (inc active-index) k)))))
6774

75+
(def default (m/decode db/document {} mt/default-value-transformer))
76+
6877
(defn new
6978
[db]
70-
(let [document (m/decode db/document {} mt/default-value-transformer)]
71-
(-> db
72-
(create-tab document)
73-
(element.h/create {:tag :canvas :attrs {:fill "#eeeeee"}})
74-
(element.h/create {:tag :svg :attrs {:width "800" :height "600"}})
75-
(history.h/finalize "Create document"))))
79+
(-> db
80+
(create-tab default)
81+
(element.h/create {:tag :canvas :attrs {:fill "#eeeeee"}})
82+
(element.h/create {:tag :svg :attrs {:width "800" :height "600"}})
83+
(history.h/finalize "Create document")))
7684

7785
(defn set-global-attr
7886
[{active-document :active-document :as db} k v]
@@ -83,7 +91,7 @@
8391
(defn load
8492
[db document]
8593
(let [open-key (search-by-path db (:path document))
86-
document (-> document
94+
document (-> (merge default document)
8795
(assoc :key (or open-key (uuid/generate))))]
8896
(cond-> db
8997
(not open-key)

src/renderer/document/subs.cljs

+5-2
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,12 @@
7474
::title-bar
7575
:<- [::title]
7676
:<- [::path]
77-
(fn [[title path] _]
77+
:<- [::active-saved?]
78+
(fn [[title path saved?] _]
7879
(let [title (or path title)]
79-
(str (when title (str title " - ")) "Repath Studio"))))
80+
(str (when (not saved?) "")
81+
(when title (str title " - "))
82+
"Repath Studio"))))
8083

8184
(rf/reg-sub
8285
::elements

0 commit comments

Comments
 (0)