Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor for zoomed in view: normal blocks and tasks #2369

Merged
merged 19 commits into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
358 changes: 203 additions & 155 deletions src/cljs/athens/types/default/view.cljs

Large diffs are not rendered by default.

55 changes: 54 additions & 1 deletion src/cljs/athens/types/tasks/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
Text]]
[athens.common-db :as common-db]
[athens.common-events.graph.ops :as graph-ops]
[athens.common.utils :as common.utils]
[athens.dates :as dates]
[athens.parse-renderer :as parser]
[athens.reactive :as reactive]
Expand All @@ -30,6 +31,9 @@
[athens.types.tasks.shared :as shared]
[athens.types.tasks.view.generic-textarea :as generic-textarea]
[athens.types.tasks.view.inline-task-title :as inline-task-title]
[athens.views.blocks.editor :as editor]
[clojure.string :as str]
[goog.functions :as gfns]
[re-frame.core :as rf]
[reagent.core :as r]
[tick.core :as t]))
Expand Down Expand Up @@ -265,6 +269,54 @@
[parser/parse-and-render title]]]))


(defn zoomed-in-view-el
[_this block-data _callbacks]
(let [parent-block-uid (:block/uid block-data)
props (:block/properties (reactive/get-reactive-block-document [:block/uid parent-block-uid]))
title-uid (-> props (get ":task/title") :block/uid)
title-block (reactive/get-reactive-block-document [:block/uid title-uid])
title-str (or (:block/string title-block) "")
local-value (r/atom title-str)
_invalid-prop-str? (and (str/blank? title-str)
(not (nil? title-str)))
save-fn (fn
([]
(rf/dispatch [:graph/update-in [:block/uid parent-block-uid] [":task/title"]
(fn [db uid] [(graph-ops/build-block-save-op db uid @local-value)])]))
([e]
(let [new-value (-> e .-target .-value)]
(reset! local-value new-value)
(rf/dispatch [:graph/update-in [:block/uid parent-block-uid] [":task/title"]
(fn [db uid] [(graph-ops/build-block-save-op db uid new-value)])]))))
update-fn #(reset! local-value %)
idle-fn (gfns/debounce #(do
(save-fn))
2000)
read-value local-value
show-edit? (r/atom true)
custom-key-handlers {:enter-handler (fn [_uid _d-key-down]
;; TODO dispatch save and jump to next input
(println "TODO dispatch save and jump to next input")
(update-fn @local-value))}
state-hooks (merge {:save-fn save-fn
:idle-fn idle-fn
:update-fn update-fn
:read-value read-value
:show-edit? show-edit?
:default-verbatim-paste? true
:keyboard-navigation? true
:navigation-uid parent-block-uid
;; TODO here we add styles
:style {}}
custom-key-handlers)]
[editor/block-editor {:block/uid (or title-uid
;; NOTE: temporary magic, stripping `:task/` 🤷‍♂️
(str "tmp-" (subs (or ":task/title" "")
(inc (.indexOf (or ":task/title" "") "/")))
"-uid-" (common.utils/gen-block-uid)))}
state-hooks]))


(defrecord TaskView
[]

Expand Down Expand Up @@ -303,7 +355,8 @@


(zoomed-in-view
[_this _block-data _callbacks])
[_this block-data _callbacks]
[zoomed-in-view-el _this block-data _callbacks])


(supported-breadcrumb-styles
Expand Down
148 changes: 147 additions & 1 deletion src/cljs/athens/views/blocks/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
ChatBubbleIcon
ExpandIcon
TextIcon]]
["/components/References/InlineReferences" :refer [ReferenceBlock
["/components/Page/Page" :refer [PageHeader
PageBody
PageFooter
TitleContainer]]
["/components/References/References" :refer [PageReferences
ReferenceBlock
ReferenceGroup]]
["@chakra-ui/react" :refer [Box
Breadcrumb
Expand Down Expand Up @@ -592,3 +597,144 @@

(when (= @drag-target :first) [drop-area-indicator/drop-area-indicator {:placement "below" :child? true}])
(when (= @drag-target :after) [drop-area-indicator/drop-area-indicator {:placement "below"}])])))))


;; Block page


(defn breadcrumb-handle-click
"If block is in main, navigate to page. If in right sidebar, replace right sidebar item."
[e uid breadcrumb-uid breadcrumb-node-title]
(let [right-sidebar? (.. e -target (closest ".right-sidebar"))]
(rf/dispatch [:reporting/navigation {:source :block-page-breadcrumb
:target :block
:pane (if right-sidebar?
:right-pane
:main-pane)}])
(if right-sidebar?
(let [eid (if breadcrumb-node-title
[:node/title breadcrumb-node-title]
[:block/uid breadcrumb-uid])]
(rf/dispatch [:right-sidebar/navigate-item uid eid]))
(router/navigate-uid breadcrumb-uid e))))


(defn linked-refs-el
[id]
(let [linked-refs (reactive/get-reactive-linked-references id)]
(when (seq linked-refs)
[:> PageReferences {:title "Linked References"
:count (count linked-refs)}
(doall
(for [[group-title group] linked-refs]
[:> ReferenceGroup {:key (str "group-" group-title)
:title group-title
:onClickTitle (fn [e]
(let [shift? (.-shiftKey e)
parsed-title (parse-renderer/parse-title group-title)]
(rf/dispatch [:reporting/navigation {:source :block-page-linked-refs
:target :page
:pane (if shift?
:right-pane
:main-pane)}])
(router/navigate-page parsed-title)))}
(doall
(for [block group]
[:> ReferenceBlock {:key (str "ref-" (:block/uid block))}
[ref-comp block]]))]))])))


(defn parents-el
[uid id]
(let [parents (reactive/get-reactive-parents-recursively id)]
[:> Breadcrumb {:gridArea "breadcrumb" :opacity 0.75}
(doall
(for [{breadcrumb-uid :block/uid breadcrumb-node-title :node/title} parents]
^{:key breadcrumb-uid}
[:> BreadcrumbItem {:key (str "breadcrumb-" breadcrumb-uid)}
[:> BreadcrumbLink {:onClick #(breadcrumb-handle-click % uid breadcrumb-uid breadcrumb-node-title)}
[:span {:style {:pointer-events "none"}}
[parse-renderer/parse-and-render (common-db/breadcrumb-string @db/dsdb breadcrumb-uid)]]]]))]))


(defn block-page-el
[block]
(let [state (r/atom {:string/local nil
:string/previous nil})
uid (:block/uid block)
show-comments? (rf/subscribe [:comment/show-comments?])
show-textarea? (rf/subscribe [:comment/show-editor? uid])
is-editing? (rf/subscribe [:editing/is-editing uid])
right-sidebar-contains-items? (rf/subscribe [:right-sidebar/contains-item? [:block/uid uid]])
properties-enabled? (rf/subscribe [:feature-flags/enabled? :properties])]

(fn [block]
(let [{:block/keys [string
children
uid
properties]
:db/keys [id]} block
thread-uid (comments/get-comment-thread-uid @db/dsdb uid)
comments-data (comments/get-comments-in-thread @db/dsdb thread-uid)
block-type (reactive/reactive-get-entity-type [:block/uid uid])
ff @(rf/subscribe [:feature-flags])
renderer-k (block-type-dispatcher/block-type->protocol-k block-type ff)
renderer (block-type-dispatcher/block-type->protocol renderer-k {})]

(when (not= string (:string/previous @state))
(swap! state assoc :string/previous string :string/local string))

[:> Box

;; Header
[:> PageHeader {:onClickOpenInSidebar (when-not @right-sidebar-contains-items?
#(rf/dispatch [:right-sidebar/open-item [:block/uid uid]]))}

;; Parent Context
[parents-el uid id]
[:> TitleContainer {:isEditing @is-editing?
:onClick (fn [e]
(.. e preventDefault)
(if (.. e -shiftKey)
(do
(rf/dispatch [:reporting/navigation {:source :block-page
:target :block
:pane :right-pane}])
(router/navigate-uid uid e))

(rf/dispatch [:editing/uid uid])))}
^{:key (str renderer-k uid)}
[types/zoomed-in-view renderer block {}]]]

;; Show comments when the toggle is on
[:> PageBody
(when (or @show-textarea?
(and @show-comments?
thread-uid))
^{:key uid}
[inline-comments/inline-comments renderer comments-data uid false])]

;; Properties
(when (and @properties-enabled?
(seq properties))
[:> PageBody
(for [prop (common-db/sort-block-properties properties)]
^{:key (:db/id prop)}
[:f> block-el prop])])


;; Children
[:> PageBody
(for [child children]
(let [{:keys [db/id]} child]
^{:key id} [:f> block-el child]))]

;; Refs
[:> PageFooter
[linked-refs-el id]]]))))


(defn page
[ident]
(let [block (reactive/get-reactive-block-document ident)]
[block-page-el block]))
Loading