Skip to content

Commit

Permalink
fix(blocks): prevent indent when already a leaf block, prevent `ind…
Browse files Browse the repository at this point in the history
…ent` and `unindent` when already a top-level child (athensresearch#228)

* fix(blocks): prevent unindent when already a top-level child in current 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>

* fix(blocks): prevent indent when already a leaf block (athensresearch#209)

A leaf block is a block with block order 0. If the block order is 0, do not indent and return a no-op in the indent event handler

Co-authored-by: Adrien Lacquemant <github@alaq.io>
Co-authored-by: nthd3gr33 <codinginenglish@gmail.com>

* fix: prevent default browser behavior for tab and shift+tab when there is no indent or unindent happening (athensresearch#209)

Co-authored-by: Adrien Lacquemant <github@alaq.io>
Co-authored-by: nthd3gr33 <codinginenglish@gmail.com>

* fix(blocks) - Refactor indent and unindent event handlers

* Move the block zero check in indent event handler to the on-key-down handler since it doesn't require any re-frame or datascript subscriptions
* Rename context-root to context-root-uid and remove unnecessary comment in unindent event handler
* Use the stricter parent ID to context-root uid check instead of (and parent grandpa) in unindent event handler

Co-authored-by: Adrien Lacquemant <github@alaq.io>
Co-authored-by: nthd3gr33 <codinginenglish@gmail.com>

* Add missing devtool devcard deps (athensresearch#229)

* feat(blocks): Drag n drop v2. use local listeners instead of global. decompose monolith block-el (athensresearch#232)

* line 524 of blocks. if I use a dispatch, on-drag-end doesn't get called

* feat(blocks): drag and drop PoC for local event handlers. refactor block-el

Co-authored-by: Adrien Lacquemant <github@alaq.io>
Co-authored-by: nthd3gr33 <codinginenglish@gmail.com>
Co-authored-by: Tom H <git@tomisme.com>
Co-authored-by: jeff <tangj1122@gmail.com>
  • Loading branch information
5 people authored and korlaism committed Jul 19, 2021
1 parent 13b0924 commit a11e9a9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/cljs/athens/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -497,23 +497,23 @@
(indent uid)))


;; TODO: no-op when user tries to unindent to a child out of current context
(defn unindent
[uid]
[uid context-root-uid]
(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)
(when-not (= (:block/uid parent) context-root-uid) ; if the parent node is the context-root, prevent unindent
{: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)))
(fn [{rfdb :db} [_ uid]]
(let [context-root-uid (get-in rfdb [:current-route :path-params :id])]
(unindent uid context-root-uid))))


(defn target-child
Expand Down
8 changes: 6 additions & 2 deletions src/cljs/athens/views/blocks.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@
query (:search/query @state)
block-start? (zero? start)
block-end? (= start (count string))
block-zero? (zero? (:block/order (db/get-block [:block/uid uid])))
top-row? true ;; TODO
bottom-row? true ;; TODO
head (subs string 0 start)
Expand All @@ -267,8 +268,11 @@
(and (= key-code KeyCodes.RIGHT) block-end?) (dispatch [:right uid])

;; -- Tab ----------------------------------------------------------------
(and shift (= key-code KeyCodes.TAB)) (dispatch [:unindent uid])
(= key-code KeyCodes.TAB) (dispatch [:indent uid])
(and shift (= key-code KeyCodes.TAB)) (do (.. e preventDefault)
(dispatch [:unindent uid]))
(= key-code KeyCodes.TAB) (do (.. e preventDefault)
(when-not block-zero?
(dispatch [:indent uid])))

;; -- Enter --------------------------------------------------------------

Expand Down

0 comments on commit a11e9a9

Please sign in to comment.