diff --git a/src/looped_in/macros.clj b/src/looped_in/macros.clj deleted file mode 100644 index 2a3bb16..0000000 --- a/src/looped_in/macros.clj +++ /dev/null @@ -1,6 +0,0 @@ -(ns looped-in.macros) - -(defmacro get-in-item [m ks] - `(if (seq ~ks) - (get-in ~m (cons :children (interpose :children ~ks))) - (get-in ~m ~ks))) diff --git a/src/looped_in/sidebar.cljs b/src/looped_in/sidebar.cljs index 8690002..628ab61 100644 --- a/src/looped_in/sidebar.cljs +++ b/src/looped_in/sidebar.cljs @@ -1,14 +1,11 @@ (ns looped-in.sidebar (:require [goog.dom :as dom] [goog.events :as events] - [goog.html.sanitizer.HtmlSanitizer :as Sanitizer] [cljs.core.async :refer [go channel]] - [looped-in.logging :as log]) - (:require-macros [looped-in.macros :refer [get-in-item]]) - (:import (goog.ui Zippy))) + [looped-in.logging :as log])) (enable-console-print!) @@ -27,6 +24,10 @@ (->> (:children item) (filter #(contains? % :text)) (sort-by #(count (:children % [])) #(compare %2 %1)) + (map (fn [child] + (if (> (count (:children child)) 0) + (sort-and-filter-item child) + child))) (vec)))) (defn fetch-item @@ -38,7 +39,15 @@ :id id})) (promise->channel) (clj)))) + (obj->clj) + (sort-and-filter-item)))) + +(defn get-in-item + "Retrieves the child from item represented by `depth`" + [item [fdepth & rdepth]] + (if (nil? fdepth) + item + (get-in-item (nth (:children item) fdepth) rdepth))) (defn model "Returns initial sidebar state" @@ -69,7 +78,7 @@ (cond (:loading state) (components/loader) (:item state) (let [current-item (get-in-item - (sort-and-filter-item (:item state)) + (:item state) (:depth state))] (cons (case (:type current-item)