diff --git a/ext/css/sidebar.css b/ext/css/sidebar.css index 806c8d8..7f63a21 100644 --- a/ext/css/sidebar.css +++ b/ext/css/sidebar.css @@ -285,6 +285,19 @@ html, body { justify-content: center; } +.commentsIndicator span { + padding: 4px; + padding-bottom: 0; + display: flex; + flex-direction: column; + align-items: center; +} + +.commentsIndicator.clickable:hover span { + background-color: #d7d7db; + cursor: default; +} + .commentHeader { display: flex; align-items: center; diff --git a/ext/icons/arrowhead-down-16.svg b/ext/icons/arrowhead-down-16.svg index d17491b..4d92375 100644 --- a/ext/icons/arrowhead-down-16.svg +++ b/ext/icons/arrowhead-down-16.svg @@ -2,5 +2,5 @@ - License, v. 2.0. If a copy of the MPL was not distributed with this - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> - + diff --git a/src/looped_in/components.cljs b/src/looped_in/components.cljs index 5682d29..577e612 100644 --- a/src/looped_in/components.cljs +++ b/src/looped_in/components.cljs @@ -20,15 +20,41 @@ (defn caption30 [text] (dom/createDom "span" "caption30" text)) +(defn with-append [el child] + (dom/appendChild el child) + el) + (defn comments-indicator [num-comments] - (dom/createDom "div" - "commentsIndicator" - (caption30 (str num-comments " comment" (when (not= num-comments 1) "s"))))) + (let [text (caption30 (str num-comments " comment" (when (not= num-comments 1) "s")))] + (dom/createDom "div" + "commentsIndicator" + (if (> num-comments 0) + (with-append + text + (dom/createDom + "img" + (clj->js + {:src "icons/arrowhead-down-16.svg" + :height "16px" + :width "16px" + :class "clickableArrowIcon"}))) + text)))) (defn replies-indicator [num-replies] - (dom/createDom "div" - "commentsIndicator" - (caption30 (str num-replies " " (if (not= num-replies 1) "replies" "reply"))))) + (let [text (caption30 (str num-replies " " (if (not= num-replies 1) "replies" "reply")))] + (dom/createDom "div" + "commentsIndicator" + (if (> num-replies 0) + (with-append + text + (dom/createDom + "img" + (clj->js + {:src "icons/arrowhead-down-16.svg" + :height "16px" + :width "16px" + :class "clickableArrowIcon"}))) + text)))) (defn with-listener [el type listener] (events/listen el type listener) diff --git a/src/looped_in/sidebar.cljs b/src/looped_in/sidebar.cljs index a96dbda..b62d7fd 100644 --- a/src/looped_in/sidebar.cljs +++ b/src/looped_in/sidebar.cljs @@ -100,18 +100,22 @@ (* (:created_at_i child) 1000)) (components/item-link (:id child))) (components/comment-text (:text child)) - (components/replies-indicator (count (:children child)))) + (-> (components/replies-indicator (count (:children child))) + ((fn [indicator] + (if (> (count (:children child)) 0) + (-> indicator + (components/with-classes "clickable") + (components/with-listener + "click" + (fn [e] + (dispatch-message + {:type :enq-depth + :index index})))) + indicator))))) (components/with-classes "child") ((fn [card] (if (> (count (:children child)) 0) - (-> card - (components/with-classes "clickable") - (components/with-listener - "click" - (fn [e] - (dispatch-message - {:type :enq-depth - :index index})))) + (components/with-classes card "clickable") card))))) (->> (:children current-item) (filter #(contains? % :text)) @@ -126,21 +130,25 @@ (components/story-caption (:points hit) (:author hit) (* (:created_at_i hit) 1000)) - (components/comments-indicator (:num_comments hit))) + (-> (components/comments-indicator (:num_comments hit)) + ((fn [indicator] + (if (> (:num_comments hit) 0) + (-> indicator + (components/with-classes "clickable") + (components/with-listener + "click" + (fn [e] + (dispatch-message {:type :loading :loading true}) + (go + (-> (fetch-item (:objectID hit)) + ( (:num_comments hit) 0) - (-> card - (components/with-classes "clickable") - (components/with-listener - "click" - (fn [e] - (dispatch-message {:type :loading :loading true}) - (go - (-> (fetch-item (:objectID hit)) - (