Merge pull request #328 from status-im/bug/contacts-list

Fixes bugs related to contacts list screen (#316, #292)
This commit is contained in:
Roman Volosovskyi 2016-10-07 14:21:05 +03:00 committed by GitHub
commit 49e6738626
4 changed files with 63 additions and 31 deletions

View File

@ -1,7 +1,14 @@
(ns status-im.chat.handlers.wallet-chat
(:require [re-frame.core :refer [after enrich path dispatch]]
[status-im.utils.handlers :refer [register-handler] :as u]
[status-im.constants :refer [wallet-chat-id]]))
[status-im.constants :refer [wallet-chat-id]]
[clojure.string :as s]))
(def dapp-contact
{:whisper-identity wallet-chat-id
:name (s/capitalize wallet-chat-id)
:dapp? true})
(register-handler :init-wallet-chat
(u/side-effect!
@ -10,5 +17,6 @@
(dispatch [:add-chat
wallet-chat-id
{:name "Wallet"
:dapp-url "http://127.0.0.1:3450"}])))))
:dapp-url "http://127.0.0.1:3450"}])
(dispatch [:add-contacts [dapp-contact]])))))

View File

@ -32,8 +32,7 @@
:style icon-back}]]]))]
(or custom-content
[view {:style st/toolbar-title-container}
[text {:style st/toolbar-title-text
:font :medium}
[text {:style st/toolbar-title-text}
title]])
[view st/toolbar-actions-container
(if actions

View File

@ -29,13 +29,13 @@
(defn contact-list-toolbar []
(let [new-contact? (get-in platform-specific [:contacts :new-contact-in-toolbar?])
actions (cond->> [{:image {:source {:uri :icon_search}
:style icon-search}
:handler (fn [])}]
new-contact?
(into [{:image {:source {:uri :icon_add}
:style icon-search}
:handler #(dispatch [:navigate-to :new-contact])}]))]
actions (cond->> [{:image {:source {:uri :icon_search}
:style icon-search}
:handler (fn [])}]
new-contact?
(into [{:image {:source {:uri :icon_add}
:style icon-search}
:handler #(dispatch [:navigate-to :new-contact])}]))]
[toolbar {:nav-action {:image {:source {:uri :icon_hamburger}
:style hamburger-icon}
:handler open-drawer}
@ -87,8 +87,10 @@
:style create-icon}]]]])
(defn contact-list []
(let [contacts (subscribe [:get-added-contacts-with-limit contacts-limit])
contacts-count (subscribe [:added-contacts-count])
(let [peoples (subscribe [:get-added-people-with-limit contacts-limit])
dapps (subscribe [:get-added-dapps-with-limit contacts-limit])
people-count (subscribe [:added-people-count])
dapps-count (subscribe [:added-dapps-count])
click-handler (subscribe [:get :contacts-click-handler])
show-toolbar-shadow? (r/atom false)]
(fn []
@ -98,23 +100,25 @@
(when @show-toolbar-shadow?
[linear-gradient {:style st/contact-group-header-gradient-bottom
:colors st/contact-group-header-gradient-bottom-colors}])]
(if (pos? @contacts-count)
(if (pos? (+ @dapps-count @people-count))
[scroll-view {:style st/contact-groups
:onScroll (fn [e]
(let [offset (.. e -nativeEvent -contentOffset -y)]
(reset! show-toolbar-shadow? (<= st/contact-group-header-height offset))))}
[contact-group
@contacts
@contacts-count
(label :t/contacts-group-dapps)
:dapps true
@click-handler]
[contact-group
@contacts
@contacts-count
(label :t/contacts-group-people)
:people false
@click-handler]]
(when (pos? @dapps-count)
[contact-group
@dapps
@dapps-count
(label :t/contacts-group-dapps)
:dapps true
@click-handler])
(when (pos? @people-count)
[contact-group
@peoples
@people-count
(label :t/contacts-group-people)
:people false
@click-handler])]
[view st/empty-contact-groups
[react/icon :group_big st/empty-contacts-icon]
[text {:style st/empty-contacts-text} (label :t/no-contacts)]])

View File

@ -19,18 +19,39 @@
(register-sub :all-added-contacts
(fn [db _]
(let [contacts (reaction (:contacts @db))]
(->> (remove #(:pending %) @contacts)
(->> (remove :pending @contacts)
(sort-contacts)
(reaction)))))
(register-sub :get-added-contacts-with-limit
(fn [_ [_ limit]]
(register-sub :all-added-people
(fn []
(let [contacts (subscribe [:all-added-contacts])]
(reaction (remove :dapp? @contacts)))))
(register-sub :all-added-dapps
(fn []
(let [contacts (subscribe [:all-added-contacts])]
(reaction (filter :dapp? @contacts)))))
(register-sub :get-added-people-with-limit
(fn [_ [_ limit]]
(let [contacts (subscribe [:all-added-people])]
(reaction (take limit @contacts)))))
(register-sub :added-contacts-count
(register-sub :get-added-dapps-with-limit
(fn [_ [_ limit]]
(let [contacts (subscribe [:all-added-dapps])]
(reaction (take limit @contacts)))))
(register-sub :added-people-count
(fn [_ _]
(let [contacts (subscribe [:all-added-contacts])]
(let [contacts (subscribe [:all-added-people])]
(reaction (count @contacts)))))
(register-sub :added-dapps-count
(fn [_ _]
(let [contacts (subscribe [:all-added-dapps])]
(reaction (count @contacts)))))
(defn get-contact-letter [contact]