File tree Expand file tree Collapse file tree 7 files changed +16
-13
lines changed Expand file tree Collapse file tree 7 files changed +16
-13
lines changed Original file line number Diff line number Diff line change 20
20
to-str)]
21
21
(dispatch [:block/save {:uid uid
22
22
:string new-block-content
23
- :callback #()
24
23
:add-time? true }])))
25
24
26
25
Original file line number Diff line number Diff line change 653
653
" uid -> Current block
654
654
state -> Look at state atom in block-el"
655
655
[uid state]
656
- (let [{:string/keys [local]} @state
657
- callback #(swap! state assoc :string/previous local)]
656
+ (let [{:string/keys [local]} @state]
658
657
(dispatch [:block/save {:uid uid
659
- :string local
660
- :callback callback}])))
658
+ :string local}])))
Original file line number Diff line number Diff line change 820
820
821
821
(reg-event-fx
822
822
:block/save
823
- (fn [{:keys [db]} [_ {:keys [uid string callback ] :as args}]]
823
+ (fn [{:keys [db]} [_ {:keys [uid string] :as args}]]
824
824
(log/debug " :block/save args" (pr-str args))
825
825
(let [local? (not (db-picker/remote-db? db))
826
826
block-eid (common-db/e-by-av @db/dsdb :block/uid uid)
831
831
(log/debug " :block/save local?" local?
832
832
" , do-nothing?" do-nothing?)
833
833
(when-not do-nothing?
834
- {:fx [[:dispatch [:resolve-transact-forward event]]
835
- [:invoke-callback callback]]}))))
834
+ {:fx [[:dispatch [:resolve-transact-forward event]]]}))))
836
835
837
836
838
837
(reg-event-fx
Original file line number Diff line number Diff line change 333
333
334
334
(defn textarea-change
335
335
[e _uid state]
336
- (swap! state assoc :string/local (.. e -target -value)))
336
+ (swap! state assoc :string/local (.. e -target -value))
337
+ ((:string/idle-fn @state)))
337
338
338
339
339
340
(defn textarea-click
410
411
:on-change (fn [e] (textarea-change e uid state))
411
412
:on-paste (fn [e] (textarea-paste e uid state))
412
413
:on-key-down (fn [e] (textarea-keydown/textarea-key-down e uid state))
413
- :on-blur (fn [_] ( db/transact-state-for-uid ( or original-uid uid) state) )
414
+ :on-blur (:string/save-fn @ state)
414
415
:on-click (fn [e] (textarea-click e uid state))
415
416
:on-mouse-enter (fn [e] (textarea-mouse-enter e uid state))
416
417
:on-mouse-down (fn [e] (textarea-mouse-down e uid state))}])
Original file line number Diff line number Diff line change 19
19
[athens.views.blocks.context-menu :as context-menu]
20
20
[athens.views.blocks.drop-area-indicator :as drop-area-indicator]
21
21
[com.rpl.specter :as s]
22
+ [goog.functions :as gfns]
22
23
[re-frame.core :as rf]
23
24
[reagent.core :as r]
24
25
[stylefy.core :as stylefy]))
258
259
[block-el block linked-ref-data {}])
259
260
([block linked-ref-data _opts]
260
261
(let [{:keys [linked-ref initial-open linked-ref-uid parent-uids]} linked-ref-data
262
+ {:block/keys [uid original-uid]} block
261
263
state (r/atom {:string/local nil
262
264
:string/previous nil
263
265
; ; one of #{:page :block :slash :hashtag :template}
274
276
:caret-position nil
275
277
:show-editable-dom false
276
278
:linked-ref/open (or (false ? linked-ref) initial-open)
277
- :block/uid (:block/uid block)})]
279
+ :block/uid uid})
280
+ save-fn #(db/transact-state-for-uid (or original-uid uid) state)
281
+ idle-fn (gfns/debounce save-fn 2000 )]
282
+ (swap! state assoc
283
+ :string/save-fn save-fn
284
+ :string/idle-fn idle-fn)
278
285
279
286
(fn [block linked-ref-data opts]
280
287
(let [{:block/keys [uid
Original file line number Diff line number Diff line change 582
582
(replace-first tail #"(?s)\)\) (.*)" " " ))]
583
583
584
584
; ; save block before navigating away
585
- (db/transact-state-for-uid uid state)
585
+ (( :string/save-fn @ state) )
586
586
587
587
(cond
588
588
(and (re-find #"(?s)\[\[ " head)
Original file line number Diff line number Diff line change 65
65
[state block-uid]
66
66
(dispatch [:block/save {:uid block-uid
67
67
:string (:string/local state)
68
- :callback #()
69
68
:add-time? true }]))
70
69
71
70
You can’t perform that action at this time.
0 commit comments