   (:require-macros [frontend.utils :refer [html]])
   (:import [goog.ui IdGenerator]))
 
+(def day-of-week
+  {1 "Monday"
+   2 "Tuesday"
+   3 "Wednesday"
+   4 "Thursday"
+   5 "Friday"
+   6 "Saturday"
+   7 "Sunday"})
+
+(defn date->bucket [date]
+  (let [time (goog.date.DateTime. date)
+        start-of-day (doto (goog.date.DateTime.)
+                       (.setHours 0)
+                       (.setMinutes 0)
+                       (.setSeconds 0)
+                       (.setMilliseconds 0))]
+    (cond
+     (time/after? time start-of-day) "today"
+     (time/after? time (time/minus start-of-day (time/days 1))) "yesterday"
+     (time/after? time (time/minus start-of-day (time/days 6))) (day-of-week (time/day-of-week time))
+     (time/after? time (time/minus start-of-day (time/days 14))) "last week"
+     :else "a while ago")))
+
+
 (defn doc-viewer [app owner]
   (reify
     om/IRender

           [:a {:on-click #(cast! :touched-fetched)
                :role "button"}
            "Fetch docs"]
           (for [doc (take 100 (reverse (sort-by :last-updated-instant touched-docs)))
                 :when (:last-updated-instant doc)]
             [:a {:href (str "/document/" (:db/id doc))}
              [:img {:src (str "/document/" (:db/id doc) ".svg")
                     :style {:border "1px solid black"}
                     :width 300
                     :height 300}]])]])))))

      (let [cast! (om/get-shared owner :cast!)
            touched-docs (get-in app [:cust :touched-docs])
            ;; Not showing created for now, since we haven't been storing that until recently
            created-docs (get-in app [:cust :created-docs])
            docs (take 100 (reverse (sort-by :last-updated-instant (filter :last-updated-instant touched-docs))))]
        (html
         [:div.menu-prompt {:class (str "menu-prompt-" "doc-viewer")}
          [:div.menu-header
