|
| 1 | +(ns status-im.contexts.settings.language-and-currency.currency.view |
| 2 | + (:require [quo.core :as quo] |
| 3 | + [react-native.core :as rn] |
| 4 | + [status-im.common.resources :as resources] |
| 5 | + [status-im.constants :as constants] |
| 6 | + [status-im.contexts.settings.language-and-currency.currency.style :as style] |
| 7 | + [status-im.contexts.settings.language-and-currency.currency.utils :as utils] |
| 8 | + [status-im.contexts.settings.language-and-currency.data-store :as data-store] |
| 9 | + [utils.debounce :as debounce] |
| 10 | + [utils.i18n :as i18n] |
| 11 | + [utils.re-frame :as rf])) |
| 12 | + |
| 13 | +(defn- navigate-back |
| 14 | + [] |
| 15 | + (rf/dispatch [:navigate-back])) |
| 16 | + |
| 17 | +(defn- get-item-layout |
| 18 | + [_ index] |
| 19 | + #js {:length constants/currency-item-height |
| 20 | + :offset (* constants/currency-item-height index) |
| 21 | + :index index}) |
| 22 | + |
| 23 | +(defn- settings-category-view |
| 24 | + [{:keys [title data]} _ _ {:keys [selected-currency on-currency-press]}] |
| 25 | + [rn/delay-render |
| 26 | + [quo/category |
| 27 | + {:label title |
| 28 | + :data (map (fn [currency] |
| 29 | + (utils/make-currency-item |
| 30 | + {:currency currency |
| 31 | + :selected-currency selected-currency |
| 32 | + :on-change on-currency-press})) |
| 33 | + data) |
| 34 | + :blur? true |
| 35 | + :list-type :settings}]]) |
| 36 | + |
| 37 | +(defn view |
| 38 | + [] |
| 39 | + (let [[search-text set-search-text] (rn/use-state "") |
| 40 | + on-currency-press (rn/use-callback #(rf/dispatch [:profile.settings/update-currency |
| 41 | + %])) |
| 42 | + selected-currency (rf/sub [:profile/currency]) |
| 43 | + currencies (rf/sub [:currencies/categorized search-text]) |
| 44 | + on-change-text (rn/use-callback |
| 45 | + (debounce/debounce |
| 46 | + #(set-search-text %) |
| 47 | + 300)) |
| 48 | + formatted-data (rn/use-memo |
| 49 | + #(data-store/get-formatted-currency-data currencies) |
| 50 | + [search-text currencies])] |
| 51 | + [quo/overlay |
| 52 | + {:type :shell |
| 53 | + :top-inset? true} |
| 54 | + [quo/page-nav |
| 55 | + {:background :blur |
| 56 | + :icon-name :i/arrow-left |
| 57 | + :on-press navigate-back}] |
| 58 | + [quo/page-top |
| 59 | + {:title (i18n/label :t/currency)}] |
| 60 | + [quo/input |
| 61 | + {:small? true |
| 62 | + :blur? true |
| 63 | + :container-style style/input-container |
| 64 | + :placeholder (i18n/label :t/search-currencies) |
| 65 | + :icon-name :i/search |
| 66 | + :on-change-text on-change-text}] |
| 67 | + (when (zero? (:total currencies)) |
| 68 | + [quo/empty-state |
| 69 | + {:title (i18n/label :t/no-result) |
| 70 | + :image (resources/get-themed-image :no-assets :dark) |
| 71 | + :container-style style/empty-results |
| 72 | + :description (i18n/label :t/try-with-different-currency)}]) |
| 73 | + [rn/flat-list |
| 74 | + {:data formatted-data |
| 75 | + :render-data {:selected-currency selected-currency |
| 76 | + :on-currency-press on-currency-press} |
| 77 | + :render-fn settings-category-view |
| 78 | + :get-item-layout get-item-layout |
| 79 | + :initial-num-to-render 14 |
| 80 | + :max-to-render-per-batch 20 |
| 81 | + :scroll-event-throttle 16 |
| 82 | + :shows-vertical-scroll-indicator false |
| 83 | + :bounces false |
| 84 | + :over-scroll-mode :never}]])) |
0 commit comments