Fix contacts sorting

This commit is contained in:
virvar 2016-06-20 12:50:20 +03:00
parent 383602200e
commit c6205fdd65
4 changed files with 12 additions and 9 deletions

View File

@ -63,8 +63,7 @@
:default-chat-icon (st/default-chat-icon-menu-item color) :default-chat-icon (st/default-chat-icon-menu-item color)
:default-chat-icon-text st/default-chat-icon-text}]) :default-chat-icon-text st/default-chat-icon-text}])
(defview contact-icon-view [identity styles] (defn contact-icon-view [contact styles]
[contact [:contact-by-identity identity]]
(let [photo-path (:photo-path contact) (let [photo-path (:photo-path contact)
;; TODO stub data ;; TODO stub data
online true] online true]
@ -74,8 +73,8 @@
[default-chat-icon (:name contact) styles]) [default-chat-icon (:name contact) styles])
[contact-online online styles]])) [contact-online online styles]]))
(defn contact-icon-contacts-tab [identity] (defn contact-icon-contacts-tab [contact]
[contact-icon-view identity [contact-icon-view contact
{:container st/container-chat-list {:container st/container-chat-list
:online-view st/online-view :online-view st/online-view
:online-dot-left st/online-dot-left :online-dot-left st/online-dot-left

View File

@ -60,7 +60,7 @@
[text {:style st/show-all-text} (label :show-all)]]]]) [text {:style st/show-all-text} (label :show-all)]]]])
(defn contact-list [] (defn contact-list []
(let [contacts (subscribe [:get-contacts]) (let [contacts (subscribe [:all-contacts])
show-toolbar-shadow? (r/atom false)] show-toolbar-shadow? (r/atom false)]
(fn [] (fn []
[drawer-view [drawer-view

View File

@ -7,10 +7,14 @@
(let [contacts (reaction (:contacts @db))] (let [contacts (reaction (:contacts @db))]
(reaction (vals @contacts))))) (reaction (vals @contacts)))))
(defn sort-contacts [contacts]
(sort-by :name #(compare (clojure.string/lower-case %1)
(clojure.string/lower-case %2)) (vals contacts)))
(register-sub :all-contacts (register-sub :all-contacts
(fn [db _] (fn [db _]
(let [contacts (reaction (:contacts @db))] (let [contacts (reaction (:contacts @db))]
(reaction (sort-by :name (vals @contacts)))))) (reaction (sort-contacts @contacts)))))
(defn get-contact-letter [contact] (defn get-contact-letter [contact]
(when-let [letter (first (:name contact))] (when-let [letter (first (:name contact))]
@ -20,7 +24,7 @@
(fn [db _] (fn [db _]
(let [contacts (reaction (:contacts @db))] (let [contacts (reaction (:contacts @db))]
(reaction (reaction
(let [ordered (sort-by :name (vals @contacts))] (let [ordered (sort-contacts @contacts)]
(map (fn [prev cur] (map (fn [prev cur]
(let [prev-letter (get-contact-letter prev) (let [prev-letter (get-contact-letter prev)
cur-letter (get-contact-letter cur)] cur-letter (get-contact-letter cur)]

View File

@ -11,9 +11,9 @@
[text {:style st/letter-text} [text {:style st/letter-text}
letter])]) letter])])
(defn contact-photo [{:keys [whisper-identity]}] (defn contact-photo [contact]
[view st/contact-photo-container [view st/contact-photo-container
[contact-icon-contacts-tab whisper-identity]]) [contact-icon-contacts-tab contact]])
(defn contact-inner-view [{:keys [name letter] :as contact}] (defn contact-inner-view [{:keys [name letter] :as contact}]
[view st/contact-container [view st/contact-container