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

Tasks enter & backspace handling #2368

Merged
merged 2 commits into from
Sep 12, 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
4 changes: 2 additions & 2 deletions src/cljs/athens/types/tasks/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
[athens.router :as router]
[athens.types.core :as types]
[athens.types.dispatcher :as dispatcher]
[athens.types.tasks.generic-textarea :as generic-textarea]
[athens.types.tasks.handlers :as handlers]
[athens.types.tasks.inline-task-title :as inline-task-title]
[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]
[re-frame.core :as rf]
[reagent.core :as r]
[tick.core :as t]))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,33 @@
(ns athens.types.tasks.generic-textarea
(ns athens.types.tasks.view.generic-textarea
(:require
["/components/Block/BlockFormInput" :refer [BlockFormInput]]
["/components/Block/Taskbox" :refer []]
["/components/Icons/Icons" :refer []]
["/components/ModalInput/ModalInput" :refer []]
["/components/ModalInput/ModalInputPopover" :refer []]
["/components/ModalInput/ModalInputTrigger" :refer []]
["@chakra-ui/react" :refer [FormControl
FormLabel
Box
FormErrorMessage]]
[athens.common-events.graph.ops :as graph-ops]
[athens.common.logging :as log]
[athens.common.utils :as common.utils]
[athens.reactive :as reactive]
[athens.self-hosted.presence.views :as presence]
[athens.views.blocks.editor :as editor]
[clojure.string :as str]
[goog.functions :as gfns]
[re-frame.core :as rf]
[reagent.core :as r]))
["/components/Block/BlockFormInput" :refer [BlockFormInput]]
["@chakra-ui/react" :refer [Box
FormControl
FormErrorMessage
FormLabel]]
[athens.common-events.graph.ops :as graph-ops]
[athens.common.logging :as log]
[athens.common.utils :as common.utils]
[athens.reactive :as reactive]
[athens.self-hosted.presence.views :as presence]
[athens.views.blocks.editor :as editor]
[clojure.string :as str]
[goog.functions :as gfns]
[re-frame.core :as rf]
[reagent.core :as r]))


(defn generic-textarea-view-for-task-props
[_parent-block-uid _prop-block-uid _prop-name _prop-title _required? _multiline?]
(let [prop-id (str (random-uuid))]
(let [prop-id (str (random-uuid))
local-value (r/atom "")]
(fn [parent-block-uid prop-block-uid prop-name prop-title required? multiline?]
(let [prop-block (reactive/get-reactive-block-document [:block/uid prop-block-uid])
prop-str (or (:block/string prop-block) "")
local-value (r/atom prop-str)
invalid-prop-str? (and required?
(str/blank? prop-str)
(not (nil? prop-str)))
save-fn (fn
save-fn (fn generic-textarea-view-for-task-props-save-fn
([]
(log/debug prop-name "save-fn" (pr-str @local-value))
(when (#{":task/title" ":task/description" ":task/due-date"} prop-name)
Expand All @@ -49,9 +44,8 @@
(rf/dispatch [:graph/update-in [:block/uid parent-block-uid] [prop-name]
(fn [db uid] [(graph-ops/build-block-save-op db uid new-value)])])))))
update-fn #(do
(when-not (= prop-str %)
(log/debug prop-name "update-fn:" (pr-str %))
(reset! local-value %)))
(log/debug prop-name "update-fn:" (pr-str %))
(reset! local-value %))
idle-fn (gfns/debounce #(do
(log/debug prop-name "idle-fn" (pr-str @local-value))
(save-fn))
Expand All @@ -62,7 +56,6 @@
editor/enter-handler-new-line
(fn [_uid _d-key-down]
;; TODO dispatch save and jump to next input
(println "TODO dispatch save and jump to next input")
(when (= ":task/assignee"
prop-name)
(rf/dispatch [:notification-for-assigned-task parent-block-uid @local-value]))
Expand All @@ -78,14 +71,15 @@
:default-verbatim-paste? true
:keyboard-navigation? false}
custom-key-handlers)]
(reset! local-value prop-str)
[:> FormControl {:is-required required?
:display "contents"
:display "contents"
:is-invalid invalid-prop-str?}
[:> FormLabel {:html-for prop-id}
prop-title]
[:> Box [:> BlockFormInput
{:isMultiline multiline?
:size "sm"}
:size "sm"}
;; NOTE: we generate temporary uid for prop if it doesn't exist, so editor can work
[editor/block-editor {:block/uid (or prop-block-uid
;; NOTE: temporary magic, stripping `:task/` 🤷‍♂️
Expand Down
Original file line number Diff line number Diff line change
@@ -1,60 +1,59 @@
(ns athens.types.tasks.inline-task-title
(ns athens.types.tasks.view.inline-task-title
(:require
[athens.common-events.graph.ops :as graph-ops]
[athens.common.logging :as log]
[athens.common.utils :as common.utils]
[athens.reactive :as reactive]
[athens.views.blocks.editor :as editor]
[clojure.string :as str]
[goog.functions :as gfns]
[re-frame.core :as rf]
[reagent.core :as r]))
[athens.common-events.graph.ops :as graph-ops]
[athens.common.logging :as log]
[athens.common.utils :as common.utils]
[athens.reactive :as reactive]
[athens.views.blocks.editor :as editor]
[clojure.string :as str]
[goog.functions :as gfns]
[re-frame.core :as rf]
[reagent.core :as r]))


(defn inline-task-title-2
[_state-hooks _parent-block-uid _prop-block-uid _prop-name _prop-title _required? _multiline?]
(let [_prop-id (str (random-uuid))]
(let [_prop-id (str (random-uuid))
local-value (r/atom "")]
(fn [state-hooks parent-block-uid prop-block-uid prop-name _prop-title _required? _multiline?]
(let [prop-block (reactive/get-reactive-block-document [:block/uid prop-block-uid])
prop-str (or (:block/string prop-block) "")
local-value (r/atom prop-str)
_invalid-prop-str? (and (str/blank? prop-str)
(not (nil? prop-str)))
save-fn (fn
([]
(log/debug prop-name "save-fn" (pr-str @local-value))
(when (#{":task/title" ":task/description" ":task/due-date"} prop-name)
(rf/dispatch [:graph/update-in [:block/uid parent-block-uid] [prop-name]
(fn [db uid] [(graph-ops/build-block-save-op db uid @local-value)])])))
([e]
(let [new-value (-> e .-target .-value)]
(log/debug prop-name "save-fn" (pr-str new-value))
(reset! local-value new-value)
(when (#{":task/title"
":task/assignee"
":task/description"
":task/due-date"} prop-name)
(rf/dispatch [:graph/update-in [:block/uid parent-block-uid] [prop-name]
(fn [db uid] [(graph-ops/build-block-save-op db uid new-value)])])))))
update-fn #(do
(when-not (= prop-str %)
(log/debug prop-name "update-fn:" (pr-str %))
(reset! local-value %)))
idle-fn (gfns/debounce #(do
(log/debug prop-name "idle-fn" (pr-str @local-value))
(save-fn))
2000)
read-value local-value
show-edit? (r/atom false)
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}
state-hooks)]
(let [prop-block (reactive/get-reactive-block-document [:block/uid prop-block-uid])
prop-str (:block/string prop-block "")
_invalid-prop-str? (and (str/blank? prop-str)
(not (nil? prop-str)))
save-fn (fn
([]
(log/debug prop-name "save-fn" (pr-str @local-value))
(when (#{":task/title" ":task/description" ":task/due-date"} prop-name)
(rf/dispatch [:graph/update-in [:block/uid parent-block-uid] [prop-name]
(fn [db uid] [(graph-ops/build-block-save-op db uid @local-value)])])))
([e]
(let [new-value (-> e .-target .-value)]
(log/debug prop-name "save-fn" (pr-str new-value))
(reset! local-value new-value)
(when (#{":task/title"
":task/assignee"
":task/description"
":task/due-date"} prop-name)
(rf/dispatch [:graph/update-in [:block/uid parent-block-uid] [prop-name]
(fn [db uid] [(graph-ops/build-block-save-op db uid new-value)])])))))
update-fn #(do
(log/debug prop-name "update-fn:" (pr-str %))
(reset! local-value %))
idle-fn (gfns/debounce #(do
(log/debug prop-name "idle-fn" (pr-str @local-value))
(save-fn))
2000)
show-edit? (r/atom false)
state-hooks (merge {:save-fn save-fn
:idle-fn idle-fn
:update-fn update-fn
:read-value local-value
:show-edit? show-edit?
:default-verbatim-paste? true
:keyboard-navigation? true
:navigation-uid parent-block-uid}
state-hooks)]
(reset! local-value prop-str)
[editor/block-editor {:block/uid (or prop-block-uid
;; NOTE: temporary magic, stripping `:task/` 🤷‍♂️
(str "tmp-" (subs (or prop-name "")
Expand Down