Skip to content

Commit 41c0178

Browse files
committed
fix load document
1 parent 77fb8dd commit 41c0178

File tree

3 files changed

+24
-29
lines changed

3 files changed

+24
-29
lines changed

src/renderer/document/events.cljs

+20-14
Original file line numberDiff line numberDiff line change
@@ -185,17 +185,16 @@
185185
::load
186186
[(rf/inject-cofx ::app.fx/guid)]
187187
(fn [{:keys [db guid]} [_ document]]
188-
{:db (if (and document (map? document) (:elements document))
189-
(let [migrated-document (compatibility/migrate-document document)
190-
migrated (not= document migrated-document)
191-
document (assoc migrated-document :id guid)]
192-
(-> (h/load db document)
193-
(cond->
194-
(not migrated)
195-
(h/saved document))
196-
(history.h/finalize "Load document")))
197-
(notification.h/add db (notification.v/generic-error {:title (str "Error while loading " (:title document))
198-
:message "File appears to be unsupported or corrupted."})))}))
188+
(if (and document (map? document) (:elements document))
189+
(let [migrated-document (compatibility/migrate-document document)
190+
migrated (not= document migrated-document)
191+
document (assoc migrated-document :id guid)]
192+
(cond-> {:db (-> (h/load db document)
193+
(history.h/finalize "Load document"))}
194+
(not migrated)
195+
(assoc :dispatch [::saved document])))
196+
{:db (notification.h/add db (notification.v/generic-error {:title (str "Error while loading " (:title document))
197+
:message "File appears to be unsupported or corrupted."}))})))
199198

200199
(rf/reg-event-fx
201200
::load-multiple
@@ -258,9 +257,16 @@
258257
::saved
259258
[persist]
260259
(fn [db [_ document-info]]
261-
(cond-> db
262-
document-info
263-
(h/saved document-info))))
260+
(if document-info
261+
(let [{:keys [id]} document-info
262+
position (get-in db [:documents id :history :position])]
263+
(cond-> db
264+
:always
265+
(update-in [:documents id] merge (assoc document-info :save position))
266+
267+
(:path document-info)
268+
(h/add-recent (:path document-info))))
269+
db)))
264270

265271
(rf/reg-event-fx
266272
::close-saved

src/renderer/document/handlers.cljs

-11
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,6 @@
158158
(let [explanation (-> document db/explain me/humanize str)]
159159
(notification.h/add db (notification.v/spec-failed "Load document" explanation))))))
160160

161-
(defn saved
162-
[db document-info]
163-
(let [{:keys [id]} document-info
164-
position (get-in db [:documents id :history :position])]
165-
(cond-> db
166-
:always
167-
(update-in [:documents id] merge (assoc document-info :save position))
168-
169-
(:path document-info)
170-
(add-recent (:path document-info)))))
171-
172161
(m/=> saved? [:-> App uuid? boolean?])
173162
(defn saved?
174163
[db id]

src/renderer/history/effects.cljs

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
(rf/->interceptor
1010
:id ::auto-persist
1111
:before (fn [context]
12-
(let [db (rf/get-coeffect context :db)]
12+
(when-let [db (rf/get-coeffect context :db)]
1313
(rf/assoc-coeffect context :history-position (history.h/position db))))
1414
:after (fn [context]
15-
(let [db (rf/get-effect context :db)]
15+
(when-let [db (rf/get-effect context :db)]
1616
(when (not= (history.h/position db)
1717
(rf/get-coeffect context :history-position))
18-
(app.fx/persist! db))
19-
context))))
18+
(app.fx/persist! db)))
19+
context)))
2020

2121
(rf/reg-global-interceptor auto-persist)

0 commit comments

Comments
 (0)