more detailed information about syncing in toolbar

This commit is contained in:
Roman Volosovskyi 2016-12-14 19:27:20 +02:00
parent 6ab45b692f
commit cd1ad1afc4
2 changed files with 20 additions and 4 deletions

View File

@ -1,4 +1,5 @@
(ns status-im.chat.views.toolbar-content (ns status-im.chat.views.toolbar-content
(:require-macros [status-im.utils.views :refer [defview]])
(:require [re-frame.core :refer [subscribe dispatch]] (:require [re-frame.core :refer [subscribe dispatch]]
[clojure.string :as str] [clojure.string :as str]
[cljs-time.core :as t] [cljs-time.core :as t]
@ -25,12 +26,24 @@
(label :t/active-unknown))) (label :t/active-unknown)))
:else (label :t/active-unknown))) :else (label :t/active-unknown)))
(defn last-activity [{:keys [online-text sync-state]}] (defn in-progress-text [{:keys [highestBlock currentBlock startBlock]}]
(let [total (- highestBlock startBlock)
ready (- currentBlock startBlock)
percentage (if (zero? ready)
0
(->> (/ ready total)
(* 100)
(.round js/Math)))]
(str (label :t/sync-in-progress) " " percentage "% " currentBlock)))
(defview last-activity [{:keys [online-text sync-state]}]
[state [:get :sync-data]]
[refreshable-text {:style st/last-activity [refreshable-text {:style st/last-activity
:text-style (get-in platform-specific [:component-styles :toolbar-last-activity]) :text-style (get-in platform-specific [:component-styles :toolbar-last-activity])
:font :default :font :default
:value (case sync-state :value (case sync-state
:in-progress (label :t/sync-in-progress) :in-progress (in-progress-text state)
:synced (label :t/sync-synced) :synced (label :t/sync-synced)
online-text)}]) online-text)}])

View File

@ -51,8 +51,9 @@
(register-handler :update-sync-state (register-handler :update-sync-state
(u/side-effect! (u/side-effect!
(fn [{:keys [sync-state]} [_ error sync]] (fn [{:keys [sync-state sync-data]} [_ error sync]]
(let [{:keys [highestBlock currentBlock]} (js->clj sync :keywordize-keys true) (let [{:keys [highestBlock currentBlock] :as state}
(js->clj sync :keywordize-keys true)
syncing? (> (- highestBlock currentBlock) blocks-per-hour) syncing? (> (- highestBlock currentBlock) blocks-per-hour)
new-state (cond new-state (cond
error :offline error :offline
@ -63,6 +64,8 @@
(= sync-state :pending)) (= sync-state :pending))
:done :done
:synced))] :synced))]
(when (and (not= sync-data state) (= :in-progress new-state))
(dispatch [:set :sync-data state]))
(when (not= sync-state new-state) (when (not= sync-state new-state)
(dispatch [:set :sync-state new-state])))))) (dispatch [:set :sync-state new-state]))))))