 (defn now [] (new js/Date))
 (def custom-formatter (time-format/formatter "dd/MM/yyyy"))
 (def app-title (str "Notes " (time-format/unparse custom-formatter (time-core/date-time (.getFullYear (now)) (+ 1 (.getMonth (now))) (.getDate (now))))))
-(def app-state (atom {:notes [] :tab 0 }))
+(def app-state (atom {:entered [] :current { :tab 0 :title "" }}))
 
 (defn note-view  [note owner]
   (reify

    (if (and key (not (empty? key)) (not (some #{key} mod-keys)))
      (string/join "+" (conj mods key)))))

(defn handle-new-note-keydown [e app owner]
  (let [code (event->key e)]
  (case code
    "enter"
    (do

        (let [new-note {:id (guid)
                        :title (.-value new-field)
                        :status "pending"
                        :tab (get-in @app [:current :tab])}]
          (om/transact! app :entered
            #(conj % new-note)
            [:create new-note])
          (om/transact! app [:current :title]
            (fn [_] "")
            [:clean-current]))
        ))
        false)
    "tab" (do
      (om/transact! app [:current :tab]
        #(+ % 1)
        [:tab nil])
      false)
    "shift+tab" (do
      (om/transact! app [:current :tab]
        #(- % 1)
        [:tab nil])
      false)
    nil
    )))))

(defn focus-on-input [] (-> js/document (.querySelector "input") (.focus)))

