Skip to content

Commit

Permalink
fix(blocks): prevent unindent when already a top-level child in curre…
Browse files Browse the repository at this point in the history
…nt context (athensresearch#209)

If the node being unindented is the top-level node in the current context, prevent unindent by checking if parent node id is equal to id present in :current-route object.

Co-authored-by: Adrien Lacquemant <github@alaq.io>
Co-authored-by: nthd3gr33 <codinginenglish@gmail.com>
  • Loading branch information
3 people committed Jul 8, 2020
1 parent 3462cc7 commit 744219a
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/cljs/athens/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -499,21 +499,25 @@

;; TODO: no-op when user tries to unindent to a child out of current context
(defn unindent
[uid]
[uid context-root]
(let [parent (db/get-parent [:block/uid uid])
grandpa (db/get-parent (:db/id parent))
new-block {:block/uid uid :block/order (inc (:block/order parent))}
reindex-grandpa (->> (inc-after (:db/id grandpa) (:block/order parent))
(concat [new-block]))]
(when (and parent grandpa)
{:transact! [[:db/retract (:db/id parent) :block/children [:block/uid uid]]
{:db/id (:db/id grandpa) :block/children reindex-grandpa}]})))
(if (= (:block/uid parent) context-root) ; if the parent node is the context-root, prevent unindent
{}
(when (and parent grandpa)
{:transact! [[:db/retract (:db/id parent) :block/children [:block/uid uid]]
{:db/id (:db/id grandpa) :block/children reindex-grandpa}]}))))


(reg-event-fx
:unindent
(fn [_ [_ uid]]
(unindent uid)))
; Pass in the reframe db as a cofx to the :unindent event handler
(fn [{rfdb :db} [_ uid]]
(let [context-root (get-in rfdb [:current-route :path-params :id])]
(unindent uid context-root))))


(defn target-child
Expand Down

0 comments on commit 744219a

Please sign in to comment.