|
185 | 185 | ::load
|
186 | 186 | [(rf/inject-cofx ::app.fx/guid)]
|
187 | 187 | (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."}))}))) |
199 | 198 |
|
200 | 199 | (rf/reg-event-fx
|
201 | 200 | ::load-multiple
|
|
258 | 257 | ::saved
|
259 | 258 | [persist]
|
260 | 259 | (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))) |
264 | 270 |
|
265 | 271 | (rf/reg-event-fx
|
266 | 272 | ::close-saved
|
|
0 commit comments