From 7d47ab2d627436d9a0353e8386024983592fafa3 Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Wed, 25 May 2016 04:27:03 +0300 Subject: [PATCH 01/19] added i18n translations Former-commit-id: b15c156a40957c27f0c4feea3ea7ceedf0407090 --- src/status_im/chat/screen.cljs | 44 ++++---- src/status_im/chat/sign_up.cljs | 105 ++++++++---------- src/status_im/chats_list/screen.cljs | 7 +- src/status_im/components/drawer/view.cljs | 17 +-- src/status_im/components/main_tabs.cljs | 8 +- src/status_im/components/toolbar.cljs | 16 +-- src/status_im/contacts/screen.cljs | 5 +- .../contacts/views/contact_inner.cljs | 5 +- src/status_im/discovery/screen.cljs | 11 +- src/status_im/discovery/tag.cljs | 3 - src/status_im/discovery/views/popular.cljs | 5 +- src/status_im/group_settings/screen.cljs | 37 +++--- .../group_settings/views/member.cljs | 5 +- src/status_im/i18n.cljs | 22 ++++ src/status_im/models/commands.cljs | 39 +++---- src/status_im/new_group/screen.cljs | 13 ++- src/status_im/participants/views/add.cljs | 5 +- src/status_im/participants/views/remove.cljs | 2 +- src/status_im/profile/screen.cljs | 23 ++-- src/status_im/protocol/handlers.cljs | 15 +-- src/status_im/translations/en.cljs | 99 +++++++++++++++++ 21 files changed, 302 insertions(+), 184 deletions(-) create mode 100644 src/status_im/i18n.cljs create mode 100644 src/status_im/translations/en.cljs diff --git a/src/status_im/chat/screen.cljs b/src/status_im/chat/screen.cljs index 19723aba22..55096319e4 100644 --- a/src/status_im/chat/screen.cljs +++ b/src/status_im/chat/screen.cljs @@ -17,7 +17,8 @@ [status-im.components.invertible-scroll-view :refer [invertible-scroll-view]] [status-im.components.toolbar :refer [toolbar]] [status-im.chat.views.message :refer [chat-message]] - [status-im.chat.views.new-message :refer [chat-message-new]])) + [status-im.chat.views.new-message :refer [chat-message-new]] + [status-im.i18n :refer [t]])) (defn contacts-by-identity [contacts] @@ -46,7 +47,7 @@ [view st/typing-view [view st/typing-background [text {:style st/typing-text} - (str member " is typing")]]]) + (str member " " (t :chat.is-typing))]]]) (defn typing-all [] [view st/typing-all @@ -100,63 +101,63 @@ [chat-icon-view-menu-item chat-id group-chat name color true]) (defn members-text [members] - (truncate-str (str (s/join ", " (map #(:name %) members)) " and you") 35)) + (truncate-str (str (s/join ", " (map #(:name %) members)) " " (t :chat.and-you)) 35)) (defn actions-list-view [] (let [{:keys [group-chat chat-id]} (subscribe [:chat-properties [:group-chat :chat-id]]) members (subscribe [:current-chat-contacts])] (when-let [actions (if @group-chat - [{:title "Members" + [{:title (t :members-title) :subtitle (members-text @members) :icon :menu_group :icon-style {:width 25 :height 19} ;; TODO not implemented: action Members :handler nil} - {:title "Search chat" - :subtitle "!not implemented" + {:title (t :chat.search-chat) + :subtitle (t :not-implemented) :icon :search_gray_copy :icon-style {:width 17 :height 17} ;; TODO not implemented: action Search chat :handler nil} - {:title "Notifications and sounds" - :subtitle "!not implemented" + {:title (t :notifications.title) + :subtitle (t :not-implemented) ;;:subtitle "Chat muted" :icon :muted :icon-style {:width 18 :height 21} ;; TODO not implemented: action Notifications :handler nil} - {:title "Settings" + {:title (t :settings.title) :icon :settings :icon-style {:width 20 :height 13} :handler #(dispatch [:show-group-settings])}] - [{:title "Profile" + [{:title (t :profile.title) :custom-icon [menu-item-icon-profile] :icon :menu_group :icon-style {:width 25 :height 19} :handler #(dispatch [:show-profile @chat-id])} - {:title "Search chat" - :subtitle "!not implemented" + {:title (t :chat.search-chat) + :subtitle (t :not-implemented) :icon :search_gray_copy :icon-style {:width 17 :height 17} ;; TODO not implemented: action Search chat :handler nil} - {:title "Notifications and sounds" - :subtitle "!not implemented" + {:title (t :notifications.title) + :subtitle (t :not-implemented) ;;:subtitle "Notifications on" :icon :muted :icon-style {:width 18 :height 21} ;; TODO not implemented: action Notifications :handler nil} - {:title "Settings" - :subtitle "!not implemented" + {:title (t :settings.title) + :subtitle (t :not-implemented) :icon :settings :icon-style {:width 20 :height 13} @@ -179,20 +180,15 @@ (fn [] [view (st/chat-name-view @show-actions) [text {:style st/chat-name-text} - (truncate-str (or @name "Chat name") 30)] + (truncate-str (or @name (t :chat-name)) 30)] (if @group-chat [view {:flexDirection :row} [icon :group st/group-icon] [text {:style st/members} (let [cnt (inc (count @contacts))] - (str cnt - (if (< 1 cnt) - " members" - " member") - ;; TODO stub data: active members - ", " cnt " active"))]] + (t :chat.members {:count cnt}))]] ;; TODO stub data: last activity - [text {:style st/last-activity} "Active a minute ago"])]))) + [text {:style st/last-activity} (t :chat.last-active)])]))) (defn toolbar-action [] (let [show-actions (subscribe [:show-actions])] diff --git a/src/status_im/chat/sign_up.cljs b/src/status_im/chat/sign_up.cljs index ef855d0021..5026b4914f 100644 --- a/src/status_im/chat/sign_up.cljs +++ b/src/status_im/chat/sign_up.cljs @@ -13,12 +13,13 @@ [status-im.constants :refer [text-content-type content-type-command content-type-command-request - content-type-status]])) + content-type-status]] + [status-im.i18n :refer [t]])) (defn send-console-msg [text] {:msg-id (random/id) - :from "me" - :to "console" + :from (t :me) + :to (t :console) :content text :content-type text-content-type :outgoing true}) @@ -32,11 +33,11 @@ (defn on-sync-contacts [] (dispatch [:received-msg {:msg-id (random/id) - :content (str "Your contacts have been synchronized") + :content (t :sign-up.contacts-syncronized) :content-type text-content-type :outgoing false - :from "console" - :to "me"}]) + :from (t :console) + :to (t :me)}]) (dispatch [:set-signed-up true])) (defn sync-contacts [] @@ -49,8 +50,8 @@ :content (:message body) :content-type text-content-type :outgoing false - :from "console" - :to "me"}]) + :from (t :console) + :to (t :me)}]) (when (:confirmed body) (dispatch [:stop-listening-confirmation-code-sms]) (sync-contacts) @@ -70,12 +71,11 @@ {:msg-id msg-id :content (command-content :confirmation-code - (str "Thanks! We've sent you a text message with a confirmation " - "code. Please provide that code to confirm your phone number")) + (t :sign-up.confirmation-code)) :content-type content-type-command-request :outgoing false - :from "console" - :to "me"}]))) + :from (t :console) + :to (t :me)}]))) (defn handle-sms [{body :body}] (when-let [matches (re-matches #"(\d{4})" body)] @@ -95,28 +95,25 @@ ;; TODO validate and save password (dispatch [:received-msg {:msg-id (random/id) - :content (str "OK great! Your password has been saved. Just to let you " - "know you can always change it in the Console by the way " - "it's me the Console nice to meet you!") + :content (t :sign-up.password-saved) :content-type text-content-type :outgoing false - :from "console" - :to "me"}]) + :from (t :console) + :to (t :me)}]) (dispatch [:received-msg {:msg-id (random/id) - :content (str "I'll generate a passphrase for you so you can restore your " - "access or log in from another device") + :content (t :sign-up.generate-passphrase) :content-type text-content-type :outgoing false - :from "console" - :to "me"}]) + :from (t :console) + :to (t :me)}]) (dispatch [:received-msg {:msg-id (random/id) - :content "Here's your passphrase:" + :content (t :sign-up.passphrase) :content-type text-content-type :outgoing false - :from "console" - :to "me"}]) + :from (t :console) + :to (t :me)}]) ;; TODO generate passphrase (let [passphrase (str "The brash businessman's braggadocio and public squabbing with " "candidates in the US presidential election")] @@ -125,79 +122,73 @@ :content passphrase :content-type text-content-type :outgoing false - :from "console" - :to "me"}])) + :from (t :console) + :to (t :me)}])) (dispatch [:received-msg {:msg-id "8" - :content "Make sure you had securely written it down" + :content (t :sign-up.written-down) :content-type text-content-type :outgoing false - :from "console" - :to "me"}]) + :from (t :console) + :to (t :me)}]) ;; TODO highlight '!phone' (let [msg-id (random/id)] (dispatch [:received-msg {:msg-id msg-id :content (command-content :phone - (str "Your phone number is also required to use the app. Type the " - "exclamation mark or hit the icon to open the command list " - "and choose the !phone command")) + (t :sign-up.phone-number-required)) :content-type content-type-command-request :outgoing false - :from "console" - :to "me"}]))) + :from (t :console) + :to (t :me)}]))) (def intro-status {:msg-id "intro-status" - :content (str "The brash businessman’s braggadocio " - "and public exchange with candidates " - "in the US presidential election") + :content (t :sign-up.intro-status) :delivery-status "seen" - :from "console" - :chat-id "console" + :from (t :console) + :chat-id (t :console) :content-type content-type-status :outgoing false - :to "me"}) + :to (t :me)}) (defn intro [db] (dispatch [:received-msg intro-status]) (dispatch [:received-msg {:msg-id "intro-message1" - :content "Hello there! It's Status a Dapp browser in your phone." + :content (t :sign-up.intro-message1) :content-type text-content-type :outgoing false - :from "console" - :to "me"}]) + :from (t :console) + :to (t :me)}]) (dispatch [:received-msg {:msg-id "intro-message2" - :content (str "Status uses a highly secure key-pair authentication type " - "to provide you a reliable way to access your account") + :content (t :sign-up.intro-message2) :content-type text-content-type :outgoing false - :from "console" - :to "me"}]) + :from (t :console) + :to (t :me)}]) (let [msg-id "into-message3"] (dispatch [:received-msg {:msg-id msg-id :content (command-content :keypair-password - (str "A key pair has been generated and saved to your device. " - "Create a password to secure your key")) + (t :sign-up.keypair-generated)) :content-type content-type-command-request :outgoing false - :from "console" - :to "me"}])) + :from (t :console) + :to (t :me)}])) db) (def console-chat - {:chat-id "console" - :name "console" + {:chat-id (t :console) + :name (t :console) :color default-chat-color :group-chat false :is-active true :timestamp (.getTime (js/Date.)) - :contacts [{:identity "console" + :contacts [{:identity (t :console) :text-color "#FFFFFF" :background-color "#AB7967"}]}) @@ -211,10 +202,10 @@ (def init (create-chat (fn [{:keys [chats] :as db}] - (if (chats "console") + (if (chats (t :console)) db (-> db - (assoc-in [:chats "console"] console-chat) + (assoc-in [:chats (t :console)] console-chat) (assoc :new-chat console-chat) - (assoc :current-chat-id "console") + (assoc :current-chat-id (t :console)) (intro)))))) diff --git a/src/status_im/chats_list/screen.cljs b/src/status_im/chats_list/screen.cljs index 980c21146e..cf4cadde59 100644 --- a/src/status_im/chats_list/screen.cljs +++ b/src/status_im/chats_list/screen.cljs @@ -16,13 +16,14 @@ toolbar-background2]] [status-im.components.toolbar :refer [toolbar]] [status-im.components.icons.ionicons :refer [icon]] + [status-im.i18n :refer [t]] [status-im.chats-list.styles :as st])) (defn chats-list-toolbar [] [toolbar {:nav-action {:image {:source {:uri :icon_hamburger} :style st/hamburger-icon} :handler open-drawer} - :title "Chats" + :title (t :chats.title) :background-color toolbar-background2 ;; TODO implement search :action {:image {:source {:uri :icon_search} @@ -43,13 +44,13 @@ :offsetY 16 :offsetX 16} [action-button-item - {:title "New Chat" + {:title (t :chats.new-chat) :buttonColor :#9b59b6 :onPress #(dispatch [:navigate-to :contact-list])} [icon {:name :android-create :style st/create-icon}]] [action-button-item - {:title "New Group Chat" + {:title (t :chats.new-group-chat) :buttonColor :#1abc9c :onPress #(dispatch [:show-group-new])} [icon {:name :person-stalker diff --git a/src/status_im/components/drawer/view.cljs b/src/status_im/components/drawer/view.cljs index 5101c6eaaa..29ffa414b4 100644 --- a/src/status_im/components/drawer/view.cljs +++ b/src/status_im/components/drawer/view.cljs @@ -11,7 +11,8 @@ drawer-layout-android touchable-opacity]] [status-im.resources :as res] - [status-im.components.drawer.styles :as st])) + [status-im.components.drawer.styles :as st] + [status-im.i18n :refer [t]])) (defonce drawer-atom (atom)) @@ -45,21 +46,21 @@ [text {:style st/name-text} @username]] [view st/menu-items-container - [menu-item {:name "Profile" + [menu-item {:name (t :profile.title) :handler #(dispatch [:navigate-to :my-profile])}] - [menu-item {:name "Settings" + [menu-item {:name (t :settings.title) :handler (fn [] ;; TODO not implemented )}] - [menu-item {:name "Discovery" + [menu-item {:name (t :discovery.title) :handler #(dispatch [:navigate-to :discovery])}] - [menu-item {:name "Contacts" + [menu-item {:name (t :contacts.title) :handler #(dispatch [:show-contacts navigator])}] - [menu-item {:name "Invite friends" + [menu-item {:name (t :invite-friends.title) :handler (fn [] ;; TODO not implemented )}] - [menu-item {:name "FAQ" + [menu-item {:name (t :faq.title) :handler (fn [])}]] [view st/switch-users-container [touchable-opacity {:onPress (fn [] @@ -67,7 +68,7 @@ ;; TODO not implemented )} [text {:style st/switch-users-text} - "Switch users"]]]]))) + (t :drawer.switch-users)]]]]))) (defn drawer-view [items] [drawer-layout-android {:drawerWidth 260 diff --git a/src/status_im/components/main_tabs.cljs b/src/status_im/components/main_tabs.cljs index b25ade7f4b..20a8ee5103 100644 --- a/src/status_im/components/main_tabs.cljs +++ b/src/status_im/components/main_tabs.cljs @@ -12,19 +12,19 @@ [status-im.components.tabs.tabs :refer [tabs]] [status-im.components.tabs.styles :as st] [status-im.components.styles :as common-st] - [status-im.utils.logging :as log])) + [status-im.i18n :refer [t]])) (def tab-list [{:view-id :chat-list - :title "Chats" + :title (t :chats.title) :screen chats-list :icon :icon_tab_chats} {:view-id :discovery - :title "Discover" + :title (t :discovery.title) :screen discovery :icon :icon_tab_discovery} {:view-id :contact-list - :title "Contacts" + :title (t :contacts.title) :screen contact-list :icon :icon_tab_contacts}]) diff --git a/src/status_im/components/toolbar.cljs b/src/status_im/components/toolbar.cljs index d7a164a624..3f21fc8a35 100644 --- a/src/status_im/components/toolbar.cljs +++ b/src/status_im/components/toolbar.cljs @@ -18,7 +18,7 @@ (defn toolbar [{:keys [title nav-action hide-nav? action custom-action background-color custom-content style]}] - (let [style (merge {:flexDirection "row" + (let [style (merge {:flexDirection :row :backgroundColor (or background-color toolbar-background1) :height 56 :elevation 2} style)] @@ -28,21 +28,21 @@ [touchable-highlight {:on-press (:handler nav-action)} [view {:width 56 :height 56 - :alignItems "center" - :justifyContent "center"} + :alignItems :center + :justifyContent :center} [image (:image nav-action)]]] [touchable-highlight {:on-press #(dispatch [:navigate-back])} [view {:width 56 :height 56} - [image {:source {:uri "icon_back"} + [image {:source {:uri :icon_back} :style {:marginTop 21 :marginLeft 23 :width 8 :height 14}}]]])) (or custom-content [view {:style {:flex 1 - :alignItems "center" - :justifyContent "center"}} + :alignItems :center + :justifyContent :center}} [text {:style {:marginTop -2.5 :color text1-color :fontSize 16 @@ -54,7 +54,7 @@ [view {:width 56 :height 56 - :alignItems "center" - :justifyContent "center"} + :alignItems :center + :justifyContent :center} [image (:image action)]]])])) diff --git a/src/status_im/contacts/screen.cljs b/src/status_im/contacts/screen.cljs index 3ed6af93bf..ab5944796a 100644 --- a/src/status_im/contacts/screen.cljs +++ b/src/status_im/contacts/screen.cljs @@ -10,13 +10,14 @@ [status-im.components.styles :refer [toolbar-background2]] [status-im.components.toolbar :refer [toolbar]] [status-im.contacts.styles :as st] - [status-im.utils.listview :as lw])) + [status-im.utils.listview :as lw] + [status-im.i18n :refer [t]])) (defn render-row [row _ _] (list-item [contact-view row])) (defn contact-list-toolbar [] - [toolbar {:title "Contacts" + [toolbar {:title (t :contacts.title) :background-color toolbar-background2 :action {:image {:source {:uri :icon_search} :style st/search-icon} diff --git a/src/status_im/contacts/views/contact_inner.cljs b/src/status_im/contacts/views/contact_inner.cljs index 0c62dbd650..222c34ffe9 100644 --- a/src/status_im/contacts/views/contact_inner.cljs +++ b/src/status_im/contacts/views/contact_inner.cljs @@ -2,7 +2,8 @@ (:require [clojure.string :as s] [status-im.components.react :refer [view image text]] [status-im.resources :as res] - [status-im.contacts.styles :as st])) + [status-im.contacts.styles :as st] + [status-im.i18n :refer [t]])) (defn contact-photo [{:keys [photo-path]}] [view st/contact-photo-container @@ -27,4 +28,4 @@ (if (pos? (count name)) name ;; todo is this correct behaviour? - "Noname")]]]) + (t :contacts.no-name))]]]) diff --git a/src/status_im/discovery/screen.cljs b/src/status_im/discovery/screen.cljs index fc06443fa7..07995499c8 100644 --- a/src/status_im/discovery/screen.cljs +++ b/src/status_im/discovery/screen.cljs @@ -9,7 +9,8 @@ [status-im.components.toolbar :refer [toolbar]] [status-im.discovery.views.popular :refer [popular]] [status-im.discovery.views.recent :refer [discovery-recent]] - [status-im.discovery.styles :as st])) + [status-im.discovery.styles :as st] + [status-im.i18n :refer [t]])) (defn get-hashtags [status] (let [hashtags (map #(subs % 1) (re-seq #"#[^ !?,;:.]+" status))] @@ -20,13 +21,13 @@ (if show-search [text-input {:style st/discovery-search-input :autoFocus true - :placeholder "Type your search tags here" + :placeholder (t :discovery.search-tags) :onSubmitEditing (fn [e] (let [search (aget e "nativeEvent" "text") hashtags (get-hashtags search)] (dispatch [:broadcast-status search hashtags])))}] [view - [text {:style st/discovery-title} "Discover"]])]) + [text {:style st/discovery-title} (t :discovery.title)]])]) (defn toogle-search [current-value] (dispatch [:set ::show-search (not current-value)])) @@ -45,8 +46,8 @@ :handler #(toogle-search show-search)}}] [scroll-view st/scroll-view-container [view st/section-spacing - [text {:style st/discovery-subtitle} "Popular tags"]] + [text {:style st/discovery-subtitle} (t :discovery.popular-tags)]] [popular] [view st/section-spacing - [text {:style st/discovery-subtitle} "Recent"]] + [text {:style st/discovery-subtitle} (t :discovery.recent)]] [discovery-recent]]]) diff --git a/src/status_im/discovery/tag.cljs b/src/status_im/discovery/tag.cljs index a872b48000..aeda1f4d3c 100644 --- a/src/status_im/discovery/tag.cljs +++ b/src/status_im/discovery/tag.cljs @@ -1,7 +1,6 @@ (ns status-im.discovery.tag (:require [re-frame.core :refer [subscribe dispatch]] - [status-im.utils.logging :as log] [status-im.utils.listview :refer [to-datasource]] [status-im.components.react :refer [view text list-view list-item]] [status-im.components.toolbar :refer [toolbar]] @@ -23,7 +22,6 @@ (defn discovery-tag [] (let [tag (subscribe [:get :current-tag]) discoveries (subscribe [:get-discoveries-by-tag])] - (log/debug "Got discoveries: " @discoveries) (fn [] (let [items @discoveries datasource (to-datasource items)] @@ -31,7 +29,6 @@ [toolbar {:nav-action {:image {:source {:uri :icon_back} :style st/icon-back} :handler #(dispatch [:navigate-back])} - :title "Add Participants" :custom-content (title-content @tag) :action {:image {:source {:uri :icon_search} :style st/icon-search} diff --git a/src/status_im/discovery/views/popular.cljs b/src/status_im/discovery/views/popular.cljs index 65b47fdf05..2b997d6829 100644 --- a/src/status_im/discovery/views/popular.cljs +++ b/src/status_im/discovery/views/popular.cljs @@ -7,7 +7,8 @@ text]] [status-im.components.carousel.carousel :refer [carousel]] [status-im.discovery.styles :as st] - [status-im.discovery.views.popular-list :refer [discovery-popular-list]])) + [status-im.discovery.views.popular-list :refer [discovery-popular-list]] + [status-im.i18n :refer [t]])) (defn page-width [] (.-width (.get (.. js/React -Dimensions) "window"))) @@ -19,4 +20,4 @@ :sneak 20} (for [{:keys [name count]} popular-tags] [discovery-popular-list name count])] - [text "None"])) + [text (t :discovery.none)])) diff --git a/src/status_im/group_settings/screen.cljs b/src/status_im/group_settings/screen.cljs index 1c49c4f094..8544b85728 100644 --- a/src/status_im/group_settings/screen.cljs +++ b/src/status_im/group_settings/screen.cljs @@ -14,7 +14,8 @@ [status-im.components.toolbar :refer [toolbar]] [status-im.components.chat-icon.screen :refer [chat-icon-view-action]] [status-im.group-settings.styles.group-settings :as st] - [status-im.group-settings.views.member :refer [member-view]])) + [status-im.group-settings.views.member :refer [member-view]] + [status-im.i18n :refer [t]])) (defn remove-member [] (dispatch [:remove-participants])) @@ -35,7 +36,7 @@ [text {:style st/modal-member-name} name] [touchable-highlight {:on-press remove-member} [text {:style st/modal-remove-text} - "Remove"]]]]])) + (t :group-settings.remove)]]]]])) (defview chat-members [] [members [:current-chat-contacts]] @@ -75,13 +76,13 @@ [view st/modal-color-picker-inner-container [picker {:selectedValue new-color :onValueChange #(dispatch [:set :new-chat-color %])} - [picker-item {:label "Blue" :value "#7099e6"}] - [picker-item {:label "Purple" :value "#a187d5"}] - [picker-item {:label "Green" :value "green"}] - [picker-item {:label "Red" :value "red"}]] + [picker-item {:label (t :colors.blue) :value "#7099e6"}] + [picker-item {:label (t :colors.purple) :value "#a187d5"}] + [picker-item {:label (t :colors.green) :value "green"}] + [picker-item {:label (t :colors.red) :value "red"}]] [touchable-highlight {:on-press set-chat-color} [text {:style st/modal-color-picker-save-btn-text} - "Save"]]]]]) + (t :group-settings.save)]]]]]) (defview chat-color-icon [] [chat-color [:chat :color]] @@ -92,11 +93,11 @@ (defn settings-view [] (let [settings [{:custom-icon [chat-color-icon] - :title "Change color" + :title (t :group-settings.change-color) :handler show-chat-color-picker} ;; TODO not implemented: Notifications - (merge {:title "Notifications and sounds" - :subtitle "!not implemented" + (merge {:title (t :notifications.title) + :subtitle (t :not-implemented) :handler nil} (if true {:icon :notifications-on @@ -108,13 +109,13 @@ {:icon :close-gray :icon-style {:width 12 :height 12} - :title "Clear history" + :title (t :group-settings.clear-history) ;; TODO show confirmation dialog? :handler #(dispatch [:clear-history])} {:icon :bin :icon-style {:width 12 :height 18} - :title "Delete and leave" + :title (t :group-settings.delete-and-leave) ;; TODO show confirmation dialog? :handler #(dispatch [:leave-group-chat])}]] [view st/settings-container @@ -130,7 +131,7 @@ [chat-icon-view-action chat-id group-chat name color false]]) (defn new-group-toolbar [] - [toolbar {:title "Chat settings" + [toolbar {:title (t :group-settings.chat-settings) :custom-action [chat-icon]}]) (defn focus [] @@ -147,7 +148,7 @@ new-name [:get :new-chat-name] focused? [:get ::name-input-focused]] [view - [text {:style st/chat-name-text} "Chat name"] + [text {:style st/chat-name-text} (t :chat-name)] [view (st/chat-name-value-container focused?) [text-input {:style st/chat-name-value :ref #(when (and % focused?) (.focus %)) @@ -161,7 +162,7 @@ [view [icon :ok-purple st/add-members-icon]]] [touchable-highlight {:style st/chat-name-btn-edit-container :on-press focus} - [text {:style st/chat-name-btn-edit-text} "Edit"]])]]) + [text {:style st/chat-name-btn-edit-text} (t :group-settings.edit)]])]]) (defview group-settings [] [show-color-picker [:group-settings :show-color-picker]] @@ -169,16 +170,16 @@ [new-group-toolbar] [scroll-view st/body [chat-name] - [text {:style st/members-text} "Members"] + [text {:style st/members-text} (t :members-title)] [touchable-highlight {:on-press #(dispatch [:navigate-to :add-participants])} ;; TODO add participants view is not in design [view st/add-members-container [icon :add-gray st/add-members-icon] [text {:style st/add-members-text} - "Add members"]]] + (t :group-settings.add-members)]]] [chat-members] [text {:style st/settings-text} - "Settings"] + (t :settings.title)] [settings-view]] (when show-color-picker [chat-color-picker]) diff --git a/src/status_im/group_settings/views/member.cljs b/src/status_im/group_settings/views/member.cljs index 240d6a09c8..302b516fe3 100644 --- a/src/status_im/group_settings/views/member.cljs +++ b/src/status_im/group_settings/views/member.cljs @@ -7,7 +7,8 @@ icon touchable-highlight]] [status-im.resources :as res] - [status-im.group-settings.styles.member :as st])) + [status-im.group-settings.styles.member :as st] + [status-im.i18n :refer [t]])) (defn contact-photo [{:keys [photo-path]}] [view st/contact-photo-container @@ -32,7 +33,7 @@ (if (pos? (count name)) name ;; todo is this correct behaviour? - "Noname")] + (t :group-settings.no-name))] ;; TODO implement :role property for group chat contact (when role [text {:style st/role-text} diff --git a/src/status_im/i18n.cljs b/src/status_im/i18n.cljs new file mode 100644 index 0000000000..22410ace37 --- /dev/null +++ b/src/status_im/i18n.cljs @@ -0,0 +1,22 @@ +(ns status-im.i18n + (:require + [status-im.translations.en :as en])) + +(set! js/window.I18n (js/require "react-native-i18n")) +(set! (.-fallbacks js/I18n) true) + +(set! (.-translations js.I18n) (clj->js {:en en/translations})) + +(defn t [path & options] + (.t js/I18n (name path) options)) + +(comment + (defn deep-merge [& maps] + (if (every? map? maps) + (apply merge-with deep-merge maps) + (last maps))) + + (defn add-translations [new-translations] + (let [translations (.-translations js/I18n)] + (set! (.-translations js/I18n) (clj->js (deep-merge (js->clj translations) new-translations))))) + ) \ No newline at end of file diff --git a/src/status_im/models/commands.cljs b/src/status_im/models/commands.cljs index 4ade2ed196..5b8a3ec915 100644 --- a/src/status_im/models/commands.cljs +++ b/src/status_im/models/commands.cljs @@ -3,58 +3,59 @@ [clojure.walk :refer [stringify-keys keywordize-keys]] [re-frame.core :refer [subscribe dispatch]] [status-im.db :as db] - [status-im.components.styles :refer [color-blue color-dark-mint]])) + [status-im.components.styles :refer [color-blue color-dark-mint]] + [status-im.i18n :refer [t]])) ;; todo delete (def commands [{:command :money - :text "!money" - :description "Send money" + :text (t :commands.money.text) + :description (t :commands.money.description) :color color-dark-mint :request-icon {:uri "icon_lock_white"} :icon {:uri "icon_lock_gray"} :suggestion true} {:command :location - :text "!location" - :description "Send location" + :text (t :commands.location.text) + :description (t :commands.location.description) :color "#9a5dcf" :suggestion true} {:command :phone - :text "!phone" - :description "Send phone number" + :text (t :commands.phone.text) + :description (t :commands.phone.description) :color color-dark-mint - :request-text "Phone number request" + :request-text (t :commands.phone.request-text) :suggestion true :handler #(dispatch [:sign-up %])} {:command :confirmation-code - :text "!confirmationCode" - :description "Send confirmation code" - :request-text "Confirmation code request" + :text (t :commands.confirmation-code.text) + :description (t :commands.confirmation-code.description) + :request-text (t :commands.confirmation-code.request-text) :color color-blue :request-icon {:uri "icon_lock_white"} :icon {:uri "icon_lock_gray"} :suggestion true :handler #(dispatch [:sign-up-confirm %])} {:command :send - :text "!send" - :description "Send location" + :text (t :commands.send.text) + :description (t :commands.send.description) :color "#9a5dcf" :suggestion true} {:command :request - :text "!request" - :description "Send request" + :text (t :commands.request.text) + :description (t :commands.request.description) :color "#48ba30" :suggestion true} {:command :keypair-password - :text "!keypairPassword" - :description "" + :text (t :commands.keypair-password.text) + :description (t :commands.keypair-password.description) :color color-blue :request-icon {:uri "icon_lock_white"} :icon {:uri "icon_lock_gray"} :suggestion false :handler #(dispatch [:save-password %])} {:command :help - :text "!help" - :description "Help" + :text (t :commands.help.text) + :description (t :commands.help.description) :color "#9a5dcf" :suggestion true}]) diff --git a/src/status_im/new_group/screen.cljs b/src/status_im/new_group/screen.cljs index a620959d50..0639d55dc3 100644 --- a/src/status_im/new_group/screen.cljs +++ b/src/status_im/new_group/screen.cljs @@ -14,14 +14,15 @@ [status-im.components.toolbar :refer [toolbar]] [status-im.utils.listview :refer [to-datasource]] [status-im.new-group.views.contact :refer [new-group-contact]] - [status-im.new-group.styles :as st])) + [status-im.new-group.styles :as st] + [status-im.i18n :refer [t]])) (defview new-group-toolbar [] [group-name [:get ::group-name] creation-disabled? [:get :disable-group-creation]] [toolbar - {:title "New group chat" + {:title (t :new-group.title) :action {:image {:source res/v ;; {:uri "icon_search"} :style st/toolbar-icon} :handler (when-not creation-disabled? @@ -33,7 +34,7 @@ {:underlineColorAndroid color-purple :style st/group-name-input :autoFocus true - :placeholder "Group Name" + :placeholder (t :new-group.group-name) :onChangeText #(dispatch [:set ::group-name %])} group-name]) @@ -42,13 +43,13 @@ [view st/new-group-container [new-group-toolbar] [view st/chat-name-container - [text {:style st/chat-name-text} "Chat name"] + [text {:style st/chat-name-text} (t :chat-name)] [group-name-input] - [text {:style st/members-text} "Members"] + [text {:style st/members-text} (t :members-title)] [touchable-highlight {:on-press (fn [])} [view st/add-container [icon :add_gray st/add-icon] - [text {:style st/add-text} "Add members"]]] + [text {:style st/add-text} (t :group-settings.add-members)]]] [list-view {:dataSource (to-datasource contacts) :renderRow (fn [row _ _] diff --git a/src/status_im/participants/views/add.cljs b/src/status_im/participants/views/add.cljs index 5bab93ea1c..56f3a2a597 100644 --- a/src/status_im/participants/views/add.cljs +++ b/src/status_im/participants/views/add.cljs @@ -7,11 +7,12 @@ [status-im.utils.listview :refer [to-datasource]] [status-im.participants.views.contact :refer [participant-contact]] [reagent.core :as r] - [status-im.participants.styles :as st])) + [status-im.participants.styles :as st] + [status-im.i18n :refer [t]])) (defn new-participants-toolbar [] [toolbar - {:title "Add Participants" + {:title (t :participants.add) :action {:image {:source res/v ;; {:uri "icon_search"} :style st/new-participant-image} :handler #(do (dispatch [:add-new-participants]) diff --git a/src/status_im/participants/views/remove.cljs b/src/status_im/participants/views/remove.cljs index e7b8103ffe..b7fee9f419 100644 --- a/src/status_im/participants/views/remove.cljs +++ b/src/status_im/participants/views/remove.cljs @@ -14,7 +14,7 @@ (defn remove-participants-toolbar [] [toolbar - {:title "Remove Participants" + {:title (t :participants.remove) :action {:handler #(do (dispatch [:remove-participants]) (dispatch [:navigate-back])) :image {:source res/trash-icon ;; {:uri "icon_search"} diff --git a/src/status_im/profile/screen.cljs b/src/status_im/profile/screen.cljs index 83470681dc..3665619229 100644 --- a/src/status_im/profile/screen.cljs +++ b/src/status_im/profile/screen.cljs @@ -10,7 +10,8 @@ touchable-opacity]] [status-im.components.chat-icon.screen :refer [profile-icon my-profile-icon]] - [status-im.profile.styles :as st])) + [status-im.profile.styles :as st] + [status-im.i18n :refer [t]])) (defn profile-property-view [{:keys [name value]}] [view st/profile-property-view-container @@ -34,29 +35,29 @@ [profile-icon]] [text {:style st/user-name} name] ;; TODO stub data - [text {:style st/status} "!not implemented"] + [text {:style st/status} (t :not-implemented)] [view st/btns-container [touchable-highlight {:onPress #(message-user whisper-identity)} [view st/message-btn - [text {:style st/message-btn-text} "Message"]]] + [text {:style st/message-btn-text} (t :profile.message)]]] [touchable-highlight {:onPress (fn [] ;; TODO not implemented )} [view st/more-btn [icon :more_vertical_blue st/more-btn-image]]]]] [view st/profile-properties-container - [profile-property-view {:name "Username" + [profile-property-view {:name (t :profile.username) :value name}] - [profile-property-view {:name "Phone number" + [profile-property-view {:name (t :profile.phone-number) :value phone-number}] ;; TODO stub data - [profile-property-view {:name "Email" - :value "!not implemented"}] + [profile-property-view {:name (t :profile.email) + :value (t :not-implemented)}] [view st/report-user-container [touchable-highlight {:on-press (fn [] ;; TODO not implemented )} - [text {:style st/report-user-text} "REPORT USER"]]]]]) + [text {:style st/report-user-text} (t :profile.report-user)]]]]]) (defview my-profile [] [username [:get :username] @@ -81,9 +82,9 @@ [text {:style st/user-name} username] [text {:style st/status} status]] [view st/profile-properties-container - [profile-property-view {:name "Username" + [profile-property-view {:name (t :profile.username) :value username}] - [profile-property-view {:name "Phone number" + [profile-property-view {:name (t :profile.phone-number) :value phone-number}] - [profile-property-view {:name "Email" + [profile-property-view {:name (t :profile.email) :value email}]]]) diff --git a/src/status_im/protocol/handlers.cljs b/src/status_im/protocol/handlers.cljs index 4b51c9ec65..2ba283f6f8 100644 --- a/src/status_im/protocol/handlers.cljs +++ b/src/status_im/protocol/handlers.cljs @@ -12,7 +12,8 @@ set-initialized]] [status-im.constants :refer [text-content-type]] [status-im.models.messages :as messages] - [status-im.models.chats :as chats])) + [status-im.models.chats :as chats] + [status-im.i18n :refer [t]])) (register-handler :initialize-protocol (u/side-effect! @@ -35,35 +36,35 @@ (let [contact-name (:name (contacts/contact-by-identity from))] (messages/save-message chat-id {:from "system" :msg-id (str msg-id "_" from) - :content (str (or contact-name from) " received chat invitation") + :content (str (or contact-name from) " " (t :protocol.received-invitation)) :content-type text-content-type}))) (defn participant-invited-to-group-msg [chat-id identity from msg-id] (let [inviter-name (:name (contacts/contact-by-identity from)) invitee-name (if (= identity (api/my-identity)) - "You" + (t :You) (:name (contacts/contact-by-identity identity)))] (messages/save-message chat-id {:from "system" :msg-id msg-id - :content (str (or inviter-name from) " invited " (or invitee-name identity)) + :content (str (or inviter-name from) " " (t :invited) " " (or invitee-name identity)) :content-type text-content-type}))) (defn participant-removed-from-group-msg [chat-id identity from msg-id] (let [remover-name (:name (contacts/contact-by-identity from)) removed-name (:name (contacts/contact-by-identity identity))] - (->> (str (or remover-name from) " removed " (or removed-name identity)) + (->> (str (or remover-name from) " " (t :removed) " " (or removed-name identity)) (system-message msg-id) (messages/save-message chat-id)))) (defn you-removed-from-group-msg [chat-id from msg-id] (let [remover-name (:name (contacts/contact-by-identity from))] - (->> (str (or remover-name from) " removed you from group chat") + (->> (str (or remover-name from) " " (t :protocol.removed-from-chat)) (system-message msg-id) (messages/save-message chat-id)))) (defn participant-left-group-msg [chat-id from msg-id] (let [left-name (:name (contacts/contact-by-identity from))] - (->> (str (or left-name from) " left") + (->> (str (or left-name from) " " (t :left)) (system-message msg-id) (messages/save-message chat-id)))) diff --git a/src/status_im/translations/en.cljs b/src/status_im/translations/en.cljs new file mode 100644 index 0000000000..66dbe07ae4 --- /dev/null +++ b/src/status_im/translations/en.cljs @@ -0,0 +1,99 @@ +(ns status-im.translations.en) + +(def translations + {:chat {:is-typing "is typing" + :and-you "and you" + + :search-chat "Search chat" + + :members {:one "1 member, 1 active" + :other "{{count}} members, {{count}} active"} + :last-active "Active a minute ago"} + :sign-up {:contacts-syncronized "Your contacts have been synchronized" + :confirmation-code (str "Thanks! We've sent you a text message with a confirmation " + "code. Please provide that code to confirm your phone number") + :password-saved (str "OK great! Your password has been saved. Just to let you " + "know you can always change it in the Console by the way " + "it's me the Console nice to meet you!") + :generate-passphrase (str "I'll generate a passphrase for you so you can restore your " + "access or log in from another device") + :passphrase "Here's your passphrase:" + :written-down "Make sure you had securely written it down" + :phone-number-required (str "Your phone number is also required to use the app. Type the " + "exclamation mark or hit the icon to open the command list " + "and choose the !phone command") + :intro-status (str "The brash businessman’s braggadocio " + "and public exchange with candidates " + "in the US presidential election") + :intro-message1 "Hello there! It's Status a Dapp browser in your phone." + :intro-message2 (str "Status1 uses a highly secure key-pair authentication type " + "to provide you a reliable way to access your account") + :keypair-generated (str "A key pair has been generated and saved to your device. " + "Create a password to secure your key")} + :chats {:title "Chats" + :new-chat "New Chat" + :new-group-chat "New Group Chat"} + :profile {:title "Profile" + :message "Message" + :username "Username" + :phone-number "Phone number" + :email "Email" + :report-user "REPORT USER"} + :settings {:title "Settings"} + :discovery {:title "Discovery" + :none "None" + :search-tags "Type your search tags here" + :popular-tags "Popular tags" + :recent "Recent"} + :contacts {:title "Contacts" + :no-name "Noname"} + :invite-friends {:title "Invite friends"} + :faq {:title "FAQ"} + :drawer {:switch-users "Switch users"} + :group-settings {:no-name "Noname" + :remove "Remove" + :save "Save" + :change-color "Change color" + :clear-history "Clear history" + :delete-and-leave "Delete and leave" + :chat-settings "Chat settings" + :edit "Edit" + :add-members "Add Members"} + :new-group {:title "New Group Chat" + :group-name "Group Name"} + :participants {:add "Add Participants" + :remove "Remove Participants"} + :commands {:money {:text "!money" + :description "Send money"} + :location {:text "!location" + :description "Send location"} + :phone {:text "!phone" + :description "Send phone number" + :request-text "Phone number request"} + :confirmation-code {:text "!confirmationCode" + :description "Send confirmation code" + :request-text "Confirmation code request"} + :send {:text "!send" + :description "Send location"} + :request {:text "!request" + :description "Send request"} + :keypair-password {:text "!keypair-password" + :description ""} + :help {:text "!help" + :description "Help"}} + :protocol {:received-invitation "received chat invitation" + :removed-from-chat "removed you from group chat"} + :colors {:blue "Blue" + :purple "Purple" + :green "Green" + :red "Red"} + :notifications {:title "Notifications and sounds"} + :not-implemented "!not implemented" + :chat-name "Chat name" + :members-title "Members" + :left "left" + :invited "invited" + :removed "removed" + :You "You" + :me "me" + :console "console"}) \ No newline at end of file From 67c8a63e2601beb82bd0444e3a439bc1ebf8d829 Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Wed, 25 May 2016 04:55:44 +0300 Subject: [PATCH 02/19] fix interop Former-commit-id: e2b8bcc42436f584060a874b67e06adf6dc7957c --- src/status_im/i18n.cljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/status_im/i18n.cljs b/src/status_im/i18n.cljs index 22410ace37..93b0840b74 100644 --- a/src/status_im/i18n.cljs +++ b/src/status_im/i18n.cljs @@ -8,7 +8,7 @@ (set! (.-translations js.I18n) (clj->js {:en en/translations})) (defn t [path & options] - (.t js/I18n (name path) options)) + (.t js/I18n (name path) (clj->js options))) (comment (defn deep-merge [& maps] From c64b15766624fe1c33fcdbcc8ae624f51c825fdf Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Wed, 25 May 2016 14:59:19 +0300 Subject: [PATCH 03/19] removed unneeded translations Former-commit-id: 930d201764c042aced8178499102dc937ad5b249 --- src/status_im/chat/sign_up.cljs | 70 +++++++++++++++--------------- src/status_im/models/commands.cljs | 16 +++---- src/status_im/translations/en.cljs | 28 ++++-------- 3 files changed, 52 insertions(+), 62 deletions(-) diff --git a/src/status_im/chat/sign_up.cljs b/src/status_im/chat/sign_up.cljs index 5026b4914f..066216a3eb 100644 --- a/src/status_im/chat/sign_up.cljs +++ b/src/status_im/chat/sign_up.cljs @@ -18,8 +18,8 @@ (defn send-console-msg [text] {:msg-id (random/id) - :from (t :me) - :to (t :console) + :from "me" + :to "console" :content text :content-type text-content-type :outgoing true}) @@ -36,8 +36,8 @@ :content (t :sign-up.contacts-syncronized) :content-type text-content-type :outgoing false - :from (t :console) - :to (t :me)}]) + :from "console" + :to "me"}]) (dispatch [:set-signed-up true])) (defn sync-contacts [] @@ -50,8 +50,8 @@ :content (:message body) :content-type text-content-type :outgoing false - :from (t :console) - :to (t :me)}]) + :from "console" + :to "me"}]) (when (:confirmed body) (dispatch [:stop-listening-confirmation-code-sms]) (sync-contacts) @@ -74,8 +74,8 @@ (t :sign-up.confirmation-code)) :content-type content-type-command-request :outgoing false - :from (t :console) - :to (t :me)}]))) + :from "console" + :to "me"}]))) (defn handle-sms [{body :body}] (when-let [matches (re-matches #"(\d{4})" body)] @@ -98,22 +98,22 @@ :content (t :sign-up.password-saved) :content-type text-content-type :outgoing false - :from (t :console) - :to (t :me)}]) + :from "console" + :to "me"}]) (dispatch [:received-msg {:msg-id (random/id) :content (t :sign-up.generate-passphrase) :content-type text-content-type :outgoing false - :from (t :console) - :to (t :me)}]) + :from "console" + :to "me"}]) (dispatch [:received-msg {:msg-id (random/id) :content (t :sign-up.passphrase) :content-type text-content-type :outgoing false - :from (t :console) - :to (t :me)}]) + :from "console" + :to "me"}]) ;; TODO generate passphrase (let [passphrase (str "The brash businessman's braggadocio and public squabbing with " "candidates in the US presidential election")] @@ -122,15 +122,15 @@ :content passphrase :content-type text-content-type :outgoing false - :from (t :console) - :to (t :me)}])) + :from "console" + :to "me"}])) (dispatch [:received-msg {:msg-id "8" :content (t :sign-up.written-down) :content-type text-content-type :outgoing false - :from (t :console) - :to (t :me)}]) + :from "console" + :to "me"}]) ;; TODO highlight '!phone' (let [msg-id (random/id)] (dispatch [:received-msg @@ -140,18 +140,18 @@ (t :sign-up.phone-number-required)) :content-type content-type-command-request :outgoing false - :from (t :console) - :to (t :me)}]))) + :from "console" + :to "me"}]))) (def intro-status {:msg-id "intro-status" :content (t :sign-up.intro-status) :delivery-status "seen" - :from (t :console) - :chat-id (t :console) + :from "console" + :chat-id "console" :content-type content-type-status :outgoing false - :to (t :me)}) + :to "me"}) (defn intro [db] (dispatch [:received-msg intro-status]) @@ -160,15 +160,15 @@ :content (t :sign-up.intro-message1) :content-type text-content-type :outgoing false - :from (t :console) - :to (t :me)}]) + :from "console" + :to "me"}]) (dispatch [:received-msg {:msg-id "intro-message2" :content (t :sign-up.intro-message2) :content-type text-content-type :outgoing false - :from (t :console) - :to (t :me)}]) + :from "console" + :to "me"}]) (let [msg-id "into-message3"] (dispatch [:received-msg {:msg-id msg-id @@ -177,18 +177,18 @@ (t :sign-up.keypair-generated)) :content-type content-type-command-request :outgoing false - :from (t :console) - :to (t :me)}])) + :from "console" + :to "me"}])) db) (def console-chat - {:chat-id (t :console) - :name (t :console) + {:chat-id "console" + :name "console" :color default-chat-color :group-chat false :is-active true :timestamp (.getTime (js/Date.)) - :contacts [{:identity (t :console) + :contacts [{:identity "console" :text-color "#FFFFFF" :background-color "#AB7967"}]}) @@ -202,10 +202,10 @@ (def init (create-chat (fn [{:keys [chats] :as db}] - (if (chats (t :console)) + (if (chats "console") db (-> db - (assoc-in [:chats (t :console)] console-chat) + (assoc-in [:chats "console"] console-chat) (assoc :new-chat console-chat) - (assoc :current-chat-id (t :console)) + (assoc :current-chat-id "console") (intro)))))) diff --git a/src/status_im/models/commands.cljs b/src/status_im/models/commands.cljs index 5b8a3ec915..71018acb06 100644 --- a/src/status_im/models/commands.cljs +++ b/src/status_im/models/commands.cljs @@ -8,26 +8,26 @@ ;; todo delete (def commands [{:command :money - :text (t :commands.money.text) + :text "!money" :description (t :commands.money.description) :color color-dark-mint :request-icon {:uri "icon_lock_white"} :icon {:uri "icon_lock_gray"} :suggestion true} {:command :location - :text (t :commands.location.text) + :text "!location" :description (t :commands.location.description) :color "#9a5dcf" :suggestion true} {:command :phone - :text (t :commands.phone.text) + :text "!phone" :description (t :commands.phone.description) :color color-dark-mint :request-text (t :commands.phone.request-text) :suggestion true :handler #(dispatch [:sign-up %])} {:command :confirmation-code - :text (t :commands.confirmation-code.text) + :text "!confirmationCode" :description (t :commands.confirmation-code.description) :request-text (t :commands.confirmation-code.request-text) :color color-blue @@ -36,17 +36,17 @@ :suggestion true :handler #(dispatch [:sign-up-confirm %])} {:command :send - :text (t :commands.send.text) + :text "!send" :description (t :commands.send.description) :color "#9a5dcf" :suggestion true} {:command :request - :text (t :commands.request.text) + :text "!request" :description (t :commands.request.description) :color "#48ba30" :suggestion true} {:command :keypair-password - :text (t :commands.keypair-password.text) + :text "!keypair-password" :description (t :commands.keypair-password.description) :color color-blue :request-icon {:uri "icon_lock_white"} @@ -54,7 +54,7 @@ :suggestion false :handler #(dispatch [:save-password %])} {:command :help - :text (t :commands.help.text) + :text "!help" :description (t :commands.help.description) :color "#9a5dcf" :suggestion true}]) diff --git a/src/status_im/translations/en.cljs b/src/status_im/translations/en.cljs index 66dbe07ae4..b3077b6b9f 100644 --- a/src/status_im/translations/en.cljs +++ b/src/status_im/translations/en.cljs @@ -63,24 +63,16 @@ :group-name "Group Name"} :participants {:add "Add Participants" :remove "Remove Participants"} - :commands {:money {:text "!money" - :description "Send money"} - :location {:text "!location" - :description "Send location"} - :phone {:text "!phone" - :description "Send phone number" + :commands {:money {:description "Send money"} + :location {:description "Send location"} + :phone {:description "Send phone number" :request-text "Phone number request"} - :confirmation-code {:text "!confirmationCode" - :description "Send confirmation code" + :confirmation-code {:description "Send confirmation code" :request-text "Confirmation code request"} - :send {:text "!send" - :description "Send location"} - :request {:text "!request" - :description "Send request"} - :keypair-password {:text "!keypair-password" - :description ""} - :help {:text "!help" - :description "Help"}} + :send {:description "Send location"} + :request {:description "Send request"} + :keypair-password {:text:description ""} + :help {:description "Help"}} :protocol {:received-invitation "received chat invitation" :removed-from-chat "removed you from group chat"} :colors {:blue "Blue" @@ -94,6 +86,4 @@ :left "left" :invited "invited" :removed "removed" - :You "You" - :me "me" - :console "console"}) \ No newline at end of file + :You "You"}) \ No newline at end of file From 67e784598ad9b041c3900cb3afa63f08cf4b9648 Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Wed, 25 May 2016 18:57:06 +0300 Subject: [PATCH 04/19] changed translation style Former-commit-id: 182600b2d7089b36f9b7451ba49a74ac80dab515 --- src/status_im/chat/screen.cljs | 38 ++-- src/status_im/chat/sign_up.cljs | 24 +-- src/status_im/chats_list/screen.cljs | 8 +- src/status_im/components/drawer/view.cljs | 16 +- src/status_im/components/main_tabs.cljs | 8 +- src/status_im/contacts/screen.cljs | 4 +- .../contacts/views/contact_inner.cljs | 4 +- src/status_im/discovery/screen.cljs | 10 +- src/status_im/discovery/views/popular.cljs | 4 +- src/status_im/group_settings/screen.cljs | 36 ++-- .../group_settings/views/member.cljs | 4 +- src/status_im/i18n.cljs | 3 +- src/status_im/models/commands.cljs | 22 +- src/status_im/new_group/screen.cljs | 12 +- src/status_im/participants/views/add.cljs | 4 +- src/status_im/participants/views/remove.cljs | 5 +- src/status_im/profile/screen.cljs | 22 +- src/status_im/protocol/handlers.cljs | 14 +- src/status_im/translations/en.cljs | 194 ++++++++++-------- 19 files changed, 230 insertions(+), 202 deletions(-) diff --git a/src/status_im/chat/screen.cljs b/src/status_im/chat/screen.cljs index 55096319e4..8c20bb1136 100644 --- a/src/status_im/chat/screen.cljs +++ b/src/status_im/chat/screen.cljs @@ -18,7 +18,7 @@ [status-im.components.toolbar :refer [toolbar]] [status-im.chat.views.message :refer [chat-message]] [status-im.chat.views.new-message :refer [chat-message-new]] - [status-im.i18n :refer [t]])) + [status-im.i18n :refer [label]])) (defn contacts-by-identity [contacts] @@ -47,7 +47,7 @@ [view st/typing-view [view st/typing-background [text {:style st/typing-text} - (str member " " (t :chat.is-typing))]]]) + (str member " " (label :t/is-typing))]]]) (defn typing-all [] [view st/typing-all @@ -101,63 +101,63 @@ [chat-icon-view-menu-item chat-id group-chat name color true]) (defn members-text [members] - (truncate-str (str (s/join ", " (map #(:name %) members)) " " (t :chat.and-you)) 35)) + (truncate-str (str (s/join ", " (map #(:name %) members)) " " (label :t/and-you)) 35)) (defn actions-list-view [] (let [{:keys [group-chat chat-id]} (subscribe [:chat-properties [:group-chat :chat-id]]) members (subscribe [:current-chat-contacts])] (when-let [actions (if @group-chat - [{:title (t :members-title) + [{:title (label :t/members-title) :subtitle (members-text @members) :icon :menu_group :icon-style {:width 25 :height 19} ;; TODO not implemented: action Members :handler nil} - {:title (t :chat.search-chat) - :subtitle (t :not-implemented) + {:title (label :t/search-chat) + :subtitle (label :t/not-implemented) :icon :search_gray_copy :icon-style {:width 17 :height 17} ;; TODO not implemented: action Search chat :handler nil} - {:title (t :notifications.title) - :subtitle (t :not-implemented) + {:title (label :t/notifications-title) + :subtitle (label :t/not-implemented) ;;:subtitle "Chat muted" :icon :muted :icon-style {:width 18 :height 21} ;; TODO not implemented: action Notifications :handler nil} - {:title (t :settings.title) + {:title (label :t/settings) :icon :settings :icon-style {:width 20 :height 13} :handler #(dispatch [:show-group-settings])}] - [{:title (t :profile.title) + [{:title (label :t/profile) :custom-icon [menu-item-icon-profile] :icon :menu_group :icon-style {:width 25 :height 19} :handler #(dispatch [:show-profile @chat-id])} - {:title (t :chat.search-chat) - :subtitle (t :not-implemented) + {:title (label :t/search-chat) + :subtitle (label :t/not-implemented) :icon :search_gray_copy :icon-style {:width 17 :height 17} ;; TODO not implemented: action Search chat :handler nil} - {:title (t :notifications.title) - :subtitle (t :not-implemented) + {:title (label :t/notifications-title) + :subtitle (label :t/not-implemented) ;;:subtitle "Notifications on" :icon :muted :icon-style {:width 18 :height 21} ;; TODO not implemented: action Notifications :handler nil} - {:title (t :settings.title) - :subtitle (t :not-implemented) + {:title (label :t/settings) + :subtitle (label :t/not-implemented) :icon :settings :icon-style {:width 20 :height 13} @@ -180,15 +180,15 @@ (fn [] [view (st/chat-name-view @show-actions) [text {:style st/chat-name-text} - (truncate-str (or @name (t :chat-name)) 30)] + (truncate-str (or @name (label :t/chat-name)) 30)] (if @group-chat [view {:flexDirection :row} [icon :group st/group-icon] [text {:style st/members} (let [cnt (inc (count @contacts))] - (t :chat.members {:count cnt}))]] + (label :t/members {:count cnt}))]] ;; TODO stub data: last activity - [text {:style st/last-activity} (t :chat.last-active)])]))) + [text {:style st/last-activity} (label :t/last-active)])]))) (defn toolbar-action [] (let [show-actions (subscribe [:show-actions])] diff --git a/src/status_im/chat/sign_up.cljs b/src/status_im/chat/sign_up.cljs index 066216a3eb..9633d94464 100644 --- a/src/status_im/chat/sign_up.cljs +++ b/src/status_im/chat/sign_up.cljs @@ -14,7 +14,7 @@ content-type-command content-type-command-request content-type-status]] - [status-im.i18n :refer [t]])) + [status-im.i18n :refer [label]])) (defn send-console-msg [text] {:msg-id (random/id) @@ -33,7 +33,7 @@ (defn on-sync-contacts [] (dispatch [:received-msg {:msg-id (random/id) - :content (t :sign-up.contacts-syncronized) + :content (label :t/contacts-syncronized) :content-type text-content-type :outgoing false :from "console" @@ -71,7 +71,7 @@ {:msg-id msg-id :content (command-content :confirmation-code - (t :sign-up.confirmation-code)) + (label :t/confirmation-code)) :content-type content-type-command-request :outgoing false :from "console" @@ -95,21 +95,21 @@ ;; TODO validate and save password (dispatch [:received-msg {:msg-id (random/id) - :content (t :sign-up.password-saved) + :content (label :t/password-saved) :content-type text-content-type :outgoing false :from "console" :to "me"}]) (dispatch [:received-msg {:msg-id (random/id) - :content (t :sign-up.generate-passphrase) + :content (label :t/generate-passphrase) :content-type text-content-type :outgoing false :from "console" :to "me"}]) (dispatch [:received-msg {:msg-id (random/id) - :content (t :sign-up.passphrase) + :content (label :t/passphrase) :content-type text-content-type :outgoing false :from "console" @@ -126,7 +126,7 @@ :to "me"}])) (dispatch [:received-msg {:msg-id "8" - :content (t :sign-up.written-down) + :content (label :t/written-down) :content-type text-content-type :outgoing false :from "console" @@ -137,7 +137,7 @@ {:msg-id msg-id :content (command-content :phone - (t :sign-up.phone-number-required)) + (label :t/phone-number-required)) :content-type content-type-command-request :outgoing false :from "console" @@ -145,7 +145,7 @@ (def intro-status {:msg-id "intro-status" - :content (t :sign-up.intro-status) + :content (label :t/intro-status) :delivery-status "seen" :from "console" :chat-id "console" @@ -157,14 +157,14 @@ (dispatch [:received-msg intro-status]) (dispatch [:received-msg {:msg-id "intro-message1" - :content (t :sign-up.intro-message1) + :content (label :t/intro-message1) :content-type text-content-type :outgoing false :from "console" :to "me"}]) (dispatch [:received-msg {:msg-id "intro-message2" - :content (t :sign-up.intro-message2) + :content (label :t/intro-message2) :content-type text-content-type :outgoing false :from "console" @@ -174,7 +174,7 @@ {:msg-id msg-id :content (command-content :keypair-password - (t :sign-up.keypair-generated)) + (label :t/keypair-generated)) :content-type content-type-command-request :outgoing false :from "console" diff --git a/src/status_im/chats_list/screen.cljs b/src/status_im/chats_list/screen.cljs index cf4cadde59..a82849d7e6 100644 --- a/src/status_im/chats_list/screen.cljs +++ b/src/status_im/chats_list/screen.cljs @@ -16,14 +16,14 @@ toolbar-background2]] [status-im.components.toolbar :refer [toolbar]] [status-im.components.icons.ionicons :refer [icon]] - [status-im.i18n :refer [t]] + [status-im.i18n :refer [label]] [status-im.chats-list.styles :as st])) (defn chats-list-toolbar [] [toolbar {:nav-action {:image {:source {:uri :icon_hamburger} :style st/hamburger-icon} :handler open-drawer} - :title (t :chats.title) + :title (label :t/chats) :background-color toolbar-background2 ;; TODO implement search :action {:image {:source {:uri :icon_search} @@ -44,13 +44,13 @@ :offsetY 16 :offsetX 16} [action-button-item - {:title (t :chats.new-chat) + {:title (label :t/new-chat) :buttonColor :#9b59b6 :onPress #(dispatch [:navigate-to :contact-list])} [icon {:name :android-create :style st/create-icon}]] [action-button-item - {:title (t :chats.new-group-chat) + {:title (label :t/new-group-chat) :buttonColor :#1abc9c :onPress #(dispatch [:show-group-new])} [icon {:name :person-stalker diff --git a/src/status_im/components/drawer/view.cljs b/src/status_im/components/drawer/view.cljs index 29ffa414b4..1cd4ae43e8 100644 --- a/src/status_im/components/drawer/view.cljs +++ b/src/status_im/components/drawer/view.cljs @@ -12,7 +12,7 @@ touchable-opacity]] [status-im.resources :as res] [status-im.components.drawer.styles :as st] - [status-im.i18n :refer [t]])) + [status-im.i18n :refer [label]])) (defonce drawer-atom (atom)) @@ -46,21 +46,21 @@ [text {:style st/name-text} @username]] [view st/menu-items-container - [menu-item {:name (t :profile.title) + [menu-item {:name (label :t/profile) :handler #(dispatch [:navigate-to :my-profile])}] - [menu-item {:name (t :settings.title) + [menu-item {:name (label :t/settings) :handler (fn [] ;; TODO not implemented )}] - [menu-item {:name (t :discovery.title) + [menu-item {:name (label :t/discovery) :handler #(dispatch [:navigate-to :discovery])}] - [menu-item {:name (t :contacts.title) + [menu-item {:name (label :t/contacts) :handler #(dispatch [:show-contacts navigator])}] - [menu-item {:name (t :invite-friends.title) + [menu-item {:name (label :t/invite-friends) :handler (fn [] ;; TODO not implemented )}] - [menu-item {:name (t :faq.title) + [menu-item {:name (label :t/faq) :handler (fn [])}]] [view st/switch-users-container [touchable-opacity {:onPress (fn [] @@ -68,7 +68,7 @@ ;; TODO not implemented )} [text {:style st/switch-users-text} - (t :drawer.switch-users)]]]]))) + (label :t/switch-users)]]]]))) (defn drawer-view [items] [drawer-layout-android {:drawerWidth 260 diff --git a/src/status_im/components/main_tabs.cljs b/src/status_im/components/main_tabs.cljs index 20a8ee5103..16fb5b074d 100644 --- a/src/status_im/components/main_tabs.cljs +++ b/src/status_im/components/main_tabs.cljs @@ -12,19 +12,19 @@ [status-im.components.tabs.tabs :refer [tabs]] [status-im.components.tabs.styles :as st] [status-im.components.styles :as common-st] - [status-im.i18n :refer [t]])) + [status-im.i18n :refer [label]])) (def tab-list [{:view-id :chat-list - :title (t :chats.title) + :title (label :t/chats) :screen chats-list :icon :icon_tab_chats} {:view-id :discovery - :title (t :discovery.title) + :title (label :t/discovery) :screen discovery :icon :icon_tab_discovery} {:view-id :contact-list - :title (t :contacts.title) + :title (label :t/contacts) :screen contact-list :icon :icon_tab_contacts}]) diff --git a/src/status_im/contacts/screen.cljs b/src/status_im/contacts/screen.cljs index ab5944796a..b8672807da 100644 --- a/src/status_im/contacts/screen.cljs +++ b/src/status_im/contacts/screen.cljs @@ -11,13 +11,13 @@ [status-im.components.toolbar :refer [toolbar]] [status-im.contacts.styles :as st] [status-im.utils.listview :as lw] - [status-im.i18n :refer [t]])) + [status-im.i18n :refer [label]])) (defn render-row [row _ _] (list-item [contact-view row])) (defn contact-list-toolbar [] - [toolbar {:title (t :contacts.title) + [toolbar {:title (label :t/contacts) :background-color toolbar-background2 :action {:image {:source {:uri :icon_search} :style st/search-icon} diff --git a/src/status_im/contacts/views/contact_inner.cljs b/src/status_im/contacts/views/contact_inner.cljs index 222c34ffe9..05502d793b 100644 --- a/src/status_im/contacts/views/contact_inner.cljs +++ b/src/status_im/contacts/views/contact_inner.cljs @@ -3,7 +3,7 @@ [status-im.components.react :refer [view image text]] [status-im.resources :as res] [status-im.contacts.styles :as st] - [status-im.i18n :refer [t]])) + [status-im.i18n :refer [label]])) (defn contact-photo [{:keys [photo-path]}] [view st/contact-photo-container @@ -28,4 +28,4 @@ (if (pos? (count name)) name ;; todo is this correct behaviour? - (t :contacts.no-name))]]]) + (label :t/no-name))]]]) diff --git a/src/status_im/discovery/screen.cljs b/src/status_im/discovery/screen.cljs index 07995499c8..b7d8e37a7b 100644 --- a/src/status_im/discovery/screen.cljs +++ b/src/status_im/discovery/screen.cljs @@ -10,7 +10,7 @@ [status-im.discovery.views.popular :refer [popular]] [status-im.discovery.views.recent :refer [discovery-recent]] [status-im.discovery.styles :as st] - [status-im.i18n :refer [t]])) + [status-im.i18n :refer [label]])) (defn get-hashtags [status] (let [hashtags (map #(subs % 1) (re-seq #"#[^ !?,;:.]+" status))] @@ -21,13 +21,13 @@ (if show-search [text-input {:style st/discovery-search-input :autoFocus true - :placeholder (t :discovery.search-tags) + :placeholder (label :t/search-tags) :onSubmitEditing (fn [e] (let [search (aget e "nativeEvent" "text") hashtags (get-hashtags search)] (dispatch [:broadcast-status search hashtags])))}] [view - [text {:style st/discovery-title} (t :discovery.title)]])]) + [text {:style st/discovery-title} (label :t/discovery)]])]) (defn toogle-search [current-value] (dispatch [:set ::show-search (not current-value)])) @@ -46,8 +46,8 @@ :handler #(toogle-search show-search)}}] [scroll-view st/scroll-view-container [view st/section-spacing - [text {:style st/discovery-subtitle} (t :discovery.popular-tags)]] + [text {:style st/discovery-subtitle} (label :t/popular-tags)]] [popular] [view st/section-spacing - [text {:style st/discovery-subtitle} (t :discovery.recent)]] + [text {:style st/discovery-subtitle} (label :t/recent)]] [discovery-recent]]]) diff --git a/src/status_im/discovery/views/popular.cljs b/src/status_im/discovery/views/popular.cljs index 2b997d6829..9fbeb4f9fb 100644 --- a/src/status_im/discovery/views/popular.cljs +++ b/src/status_im/discovery/views/popular.cljs @@ -8,7 +8,7 @@ [status-im.components.carousel.carousel :refer [carousel]] [status-im.discovery.styles :as st] [status-im.discovery.views.popular-list :refer [discovery-popular-list]] - [status-im.i18n :refer [t]])) + [status-im.i18n :refer [label]])) (defn page-width [] (.-width (.get (.. js/React -Dimensions) "window"))) @@ -20,4 +20,4 @@ :sneak 20} (for [{:keys [name count]} popular-tags] [discovery-popular-list name count])] - [text (t :discovery.none)])) + [text (label :t/none)])) diff --git a/src/status_im/group_settings/screen.cljs b/src/status_im/group_settings/screen.cljs index 8544b85728..346b783912 100644 --- a/src/status_im/group_settings/screen.cljs +++ b/src/status_im/group_settings/screen.cljs @@ -15,7 +15,7 @@ [status-im.components.chat-icon.screen :refer [chat-icon-view-action]] [status-im.group-settings.styles.group-settings :as st] [status-im.group-settings.views.member :refer [member-view]] - [status-im.i18n :refer [t]])) + [status-im.i18n :refer [label]])) (defn remove-member [] (dispatch [:remove-participants])) @@ -36,7 +36,7 @@ [text {:style st/modal-member-name} name] [touchable-highlight {:on-press remove-member} [text {:style st/modal-remove-text} - (t :group-settings.remove)]]]]])) + (label :t/remove)]]]]])) (defview chat-members [] [members [:current-chat-contacts]] @@ -76,13 +76,13 @@ [view st/modal-color-picker-inner-container [picker {:selectedValue new-color :onValueChange #(dispatch [:set :new-chat-color %])} - [picker-item {:label (t :colors.blue) :value "#7099e6"}] - [picker-item {:label (t :colors.purple) :value "#a187d5"}] - [picker-item {:label (t :colors.green) :value "green"}] - [picker-item {:label (t :colors.red) :value "red"}]] + [picker-item {:label (label :t/blue) :value "#7099e6"}] + [picker-item {:label (label :t/purple) :value "#a187d5"}] + [picker-item {:label (label :t/green) :value "green"}] + [picker-item {:label (label :t/red) :value "red"}]] [touchable-highlight {:on-press set-chat-color} [text {:style st/modal-color-picker-save-btn-text} - (t :group-settings.save)]]]]]) + (label :t/save)]]]]]) (defview chat-color-icon [] [chat-color [:chat :color]] @@ -93,11 +93,11 @@ (defn settings-view [] (let [settings [{:custom-icon [chat-color-icon] - :title (t :group-settings.change-color) + :title (label :t/change-color) :handler show-chat-color-picker} ;; TODO not implemented: Notifications - (merge {:title (t :notifications.title) - :subtitle (t :not-implemented) + (merge {:title (label :t/notifications-title) + :subtitle (label :t/not-implemented) :handler nil} (if true {:icon :notifications-on @@ -109,13 +109,13 @@ {:icon :close-gray :icon-style {:width 12 :height 12} - :title (t :group-settings.clear-history) + :title (label :t/clear-history) ;; TODO show confirmation dialog? :handler #(dispatch [:clear-history])} {:icon :bin :icon-style {:width 12 :height 18} - :title (t :group-settings.delete-and-leave) + :title (label :t/delete-and-leave) ;; TODO show confirmation dialog? :handler #(dispatch [:leave-group-chat])}]] [view st/settings-container @@ -131,7 +131,7 @@ [chat-icon-view-action chat-id group-chat name color false]]) (defn new-group-toolbar [] - [toolbar {:title (t :group-settings.chat-settings) + [toolbar {:title (label :t/chat-settings) :custom-action [chat-icon]}]) (defn focus [] @@ -148,7 +148,7 @@ new-name [:get :new-chat-name] focused? [:get ::name-input-focused]] [view - [text {:style st/chat-name-text} (t :chat-name)] + [text {:style st/chat-name-text} (label :t/chat-name)] [view (st/chat-name-value-container focused?) [text-input {:style st/chat-name-value :ref #(when (and % focused?) (.focus %)) @@ -162,7 +162,7 @@ [view [icon :ok-purple st/add-members-icon]]] [touchable-highlight {:style st/chat-name-btn-edit-container :on-press focus} - [text {:style st/chat-name-btn-edit-text} (t :group-settings.edit)]])]]) + [text {:style st/chat-name-btn-edit-text} (label :t/edit)]])]]) (defview group-settings [] [show-color-picker [:group-settings :show-color-picker]] @@ -170,16 +170,16 @@ [new-group-toolbar] [scroll-view st/body [chat-name] - [text {:style st/members-text} (t :members-title)] + [text {:style st/members-text} (label :t/members-title)] [touchable-highlight {:on-press #(dispatch [:navigate-to :add-participants])} ;; TODO add participants view is not in design [view st/add-members-container [icon :add-gray st/add-members-icon] [text {:style st/add-members-text} - (t :group-settings.add-members)]]] + (label :t/add-members)]]] [chat-members] [text {:style st/settings-text} - (t :settings.title)] + (label :t/settings)] [settings-view]] (when show-color-picker [chat-color-picker]) diff --git a/src/status_im/group_settings/views/member.cljs b/src/status_im/group_settings/views/member.cljs index 302b516fe3..c5292daa36 100644 --- a/src/status_im/group_settings/views/member.cljs +++ b/src/status_im/group_settings/views/member.cljs @@ -8,7 +8,7 @@ touchable-highlight]] [status-im.resources :as res] [status-im.group-settings.styles.member :as st] - [status-im.i18n :refer [t]])) + [status-im.i18n :refer [label]])) (defn contact-photo [{:keys [photo-path]}] [view st/contact-photo-container @@ -33,7 +33,7 @@ (if (pos? (count name)) name ;; todo is this correct behaviour? - (t :group-settings.no-name))] + (label :t/no-name))] ;; TODO implement :role property for group chat contact (when role [text {:style st/role-text} diff --git a/src/status_im/i18n.cljs b/src/status_im/i18n.cljs index 93b0840b74..9abde5c46e 100644 --- a/src/status_im/i18n.cljs +++ b/src/status_im/i18n.cljs @@ -4,10 +4,11 @@ (set! js/window.I18n (js/require "react-native-i18n")) (set! (.-fallbacks js/I18n) true) +(set! (.-defaultSeparator js/I18n) "/") (set! (.-translations js.I18n) (clj->js {:en en/translations})) -(defn t [path & options] +(defn label [path & options] (.t js/I18n (name path) (clj->js options))) (comment diff --git a/src/status_im/models/commands.cljs b/src/status_im/models/commands.cljs index 71018acb06..a9ba2ffd26 100644 --- a/src/status_im/models/commands.cljs +++ b/src/status_im/models/commands.cljs @@ -4,32 +4,32 @@ [re-frame.core :refer [subscribe dispatch]] [status-im.db :as db] [status-im.components.styles :refer [color-blue color-dark-mint]] - [status-im.i18n :refer [t]])) + [status-im.i18n :refer [label]])) ;; todo delete (def commands [{:command :money :text "!money" - :description (t :commands.money.description) + :description (label :t/money-command-description) :color color-dark-mint :request-icon {:uri "icon_lock_white"} :icon {:uri "icon_lock_gray"} :suggestion true} {:command :location :text "!location" - :description (t :commands.location.description) + :description (label :t/location-command-description) :color "#9a5dcf" :suggestion true} {:command :phone :text "!phone" - :description (t :commands.phone.description) + :description (label :t/phone-command-description) :color color-dark-mint - :request-text (t :commands.phone.request-text) + :request-text (label :t/phone-request-text) :suggestion true :handler #(dispatch [:sign-up %])} {:command :confirmation-code :text "!confirmationCode" - :description (t :commands.confirmation-code.description) - :request-text (t :commands.confirmation-code.request-text) + :description (label :t/confirmation-code-command-description) + :request-text (label :t/confirmation-code-request-text) :color color-blue :request-icon {:uri "icon_lock_white"} :icon {:uri "icon_lock_gray"} @@ -37,17 +37,17 @@ :handler #(dispatch [:sign-up-confirm %])} {:command :send :text "!send" - :description (t :commands.send.description) + :description (label :t/send-command-description) :color "#9a5dcf" :suggestion true} {:command :request :text "!request" - :description (t :commands.request.description) + :description (label :t/request-command-description) :color "#48ba30" :suggestion true} {:command :keypair-password :text "!keypair-password" - :description (t :commands.keypair-password.description) + :description (label :t/keypair-password-command-description) :color color-blue :request-icon {:uri "icon_lock_white"} :icon {:uri "icon_lock_gray"} @@ -55,7 +55,7 @@ :handler #(dispatch [:save-password %])} {:command :help :text "!help" - :description (t :commands.help.description) + :description (label :t/help-command-description) :color "#9a5dcf" :suggestion true}]) diff --git a/src/status_im/new_group/screen.cljs b/src/status_im/new_group/screen.cljs index 0639d55dc3..4b266486c6 100644 --- a/src/status_im/new_group/screen.cljs +++ b/src/status_im/new_group/screen.cljs @@ -15,14 +15,14 @@ [status-im.utils.listview :refer [to-datasource]] [status-im.new-group.views.contact :refer [new-group-contact]] [status-im.new-group.styles :as st] - [status-im.i18n :refer [t]])) + [status-im.i18n :refer [label]])) (defview new-group-toolbar [] [group-name [:get ::group-name] creation-disabled? [:get :disable-group-creation]] [toolbar - {:title (t :new-group.title) + {:title (label :t/new-group-chat) :action {:image {:source res/v ;; {:uri "icon_search"} :style st/toolbar-icon} :handler (when-not creation-disabled? @@ -34,7 +34,7 @@ {:underlineColorAndroid color-purple :style st/group-name-input :autoFocus true - :placeholder (t :new-group.group-name) + :placeholder (label :t/group-name) :onChangeText #(dispatch [:set ::group-name %])} group-name]) @@ -43,13 +43,13 @@ [view st/new-group-container [new-group-toolbar] [view st/chat-name-container - [text {:style st/chat-name-text} (t :chat-name)] + [text {:style st/chat-name-text} (label :t/chat-name)] [group-name-input] - [text {:style st/members-text} (t :members-title)] + [text {:style st/members-text} (label :t/members-title)] [touchable-highlight {:on-press (fn [])} [view st/add-container [icon :add_gray st/add-icon] - [text {:style st/add-text} (t :group-settings.add-members)]]] + [text {:style st/add-text} (label :t/add-members)]]] [list-view {:dataSource (to-datasource contacts) :renderRow (fn [row _ _] diff --git a/src/status_im/participants/views/add.cljs b/src/status_im/participants/views/add.cljs index 56f3a2a597..e708b9a7c2 100644 --- a/src/status_im/participants/views/add.cljs +++ b/src/status_im/participants/views/add.cljs @@ -8,11 +8,11 @@ [status-im.participants.views.contact :refer [participant-contact]] [reagent.core :as r] [status-im.participants.styles :as st] - [status-im.i18n :refer [t]])) + [status-im.i18n :refer [label]])) (defn new-participants-toolbar [] [toolbar - {:title (t :participants.add) + {:title (label :t/add-participants) :action {:image {:source res/v ;; {:uri "icon_search"} :style st/new-participant-image} :handler #(do (dispatch [:add-new-participants]) diff --git a/src/status_im/participants/views/remove.cljs b/src/status_im/participants/views/remove.cljs index b7fee9f419..6469371a3f 100644 --- a/src/status_im/participants/views/remove.cljs +++ b/src/status_im/participants/views/remove.cljs @@ -10,11 +10,12 @@ [status-im.participants.views.contact :refer [participant-contact]] [reagent.core :as r] - [status-im.participants.styles :as st])) + [status-im.participants.styles :as st] + [status-im.i18n :refer [label]])) (defn remove-participants-toolbar [] [toolbar - {:title (t :participants.remove) + {:title (label :t/remove-participants) :action {:handler #(do (dispatch [:remove-participants]) (dispatch [:navigate-back])) :image {:source res/trash-icon ;; {:uri "icon_search"} diff --git a/src/status_im/profile/screen.cljs b/src/status_im/profile/screen.cljs index 3665619229..f2de5dcb41 100644 --- a/src/status_im/profile/screen.cljs +++ b/src/status_im/profile/screen.cljs @@ -11,7 +11,7 @@ [status-im.components.chat-icon.screen :refer [profile-icon my-profile-icon]] [status-im.profile.styles :as st] - [status-im.i18n :refer [t]])) + [status-im.i18n :refer [label]])) (defn profile-property-view [{:keys [name value]}] [view st/profile-property-view-container @@ -35,29 +35,29 @@ [profile-icon]] [text {:style st/user-name} name] ;; TODO stub data - [text {:style st/status} (t :not-implemented)] + [text {:style st/status} (label :t/not-implemented)] [view st/btns-container [touchable-highlight {:onPress #(message-user whisper-identity)} [view st/message-btn - [text {:style st/message-btn-text} (t :profile.message)]]] + [text {:style st/message-btn-text} (label :t/message)]]] [touchable-highlight {:onPress (fn [] ;; TODO not implemented )} [view st/more-btn [icon :more_vertical_blue st/more-btn-image]]]]] [view st/profile-properties-container - [profile-property-view {:name (t :profile.username) + [profile-property-view {:name (label :t/username) :value name}] - [profile-property-view {:name (t :profile.phone-number) + [profile-property-view {:name (label :t/phone-number) :value phone-number}] ;; TODO stub data - [profile-property-view {:name (t :profile.email) - :value (t :not-implemented)}] + [profile-property-view {:name (label :t/email) + :value (label :t/not-implemented)}] [view st/report-user-container [touchable-highlight {:on-press (fn [] ;; TODO not implemented )} - [text {:style st/report-user-text} (t :profile.report-user)]]]]]) + [text {:style st/report-user-text} (label :t/report-user)]]]]]) (defview my-profile [] [username [:get :username] @@ -82,9 +82,9 @@ [text {:style st/user-name} username] [text {:style st/status} status]] [view st/profile-properties-container - [profile-property-view {:name (t :profile.username) + [profile-property-view {:name (label :t/username) :value username}] - [profile-property-view {:name (t :profile.phone-number) + [profile-property-view {:name (label :t/phone-number) :value phone-number}] - [profile-property-view {:name (t :profile.email) + [profile-property-view {:name (label :t/email) :value email}]]]) diff --git a/src/status_im/protocol/handlers.cljs b/src/status_im/protocol/handlers.cljs index 2ba283f6f8..a9b94e5541 100644 --- a/src/status_im/protocol/handlers.cljs +++ b/src/status_im/protocol/handlers.cljs @@ -13,7 +13,7 @@ [status-im.constants :refer [text-content-type]] [status-im.models.messages :as messages] [status-im.models.chats :as chats] - [status-im.i18n :refer [t]])) + [status-im.i18n :refer [label]])) (register-handler :initialize-protocol (u/side-effect! @@ -36,35 +36,35 @@ (let [contact-name (:name (contacts/contact-by-identity from))] (messages/save-message chat-id {:from "system" :msg-id (str msg-id "_" from) - :content (str (or contact-name from) " " (t :protocol.received-invitation)) + :content (str (or contact-name from) " " (label :t/received-invitation)) :content-type text-content-type}))) (defn participant-invited-to-group-msg [chat-id identity from msg-id] (let [inviter-name (:name (contacts/contact-by-identity from)) invitee-name (if (= identity (api/my-identity)) - (t :You) + (label :t/You) (:name (contacts/contact-by-identity identity)))] (messages/save-message chat-id {:from "system" :msg-id msg-id - :content (str (or inviter-name from) " " (t :invited) " " (or invitee-name identity)) + :content (str (or inviter-name from) " " (label :t/invited) " " (or invitee-name identity)) :content-type text-content-type}))) (defn participant-removed-from-group-msg [chat-id identity from msg-id] (let [remover-name (:name (contacts/contact-by-identity from)) removed-name (:name (contacts/contact-by-identity identity))] - (->> (str (or remover-name from) " " (t :removed) " " (or removed-name identity)) + (->> (str (or remover-name from) " " (label :t/removed) " " (or removed-name identity)) (system-message msg-id) (messages/save-message chat-id)))) (defn you-removed-from-group-msg [chat-id from msg-id] (let [remover-name (:name (contacts/contact-by-identity from))] - (->> (str (or remover-name from) " " (t :protocol.removed-from-chat)) + (->> (str (or remover-name from) " " (label :t/removed-from-chat)) (system-message msg-id) (messages/save-message chat-id)))) (defn participant-left-group-msg [chat-id from msg-id] (let [left-name (:name (contacts/contact-by-identity from))] - (->> (str (or left-name from) " " (t :left)) + (->> (str (or left-name from) " " (label :t/left)) (system-message msg-id) (messages/save-message chat-id)))) diff --git a/src/status_im/translations/en.cljs b/src/status_im/translations/en.cljs index b3077b6b9f..be71f9037b 100644 --- a/src/status_im/translations/en.cljs +++ b/src/status_im/translations/en.cljs @@ -1,89 +1,115 @@ (ns status-im.translations.en) (def translations - {:chat {:is-typing "is typing" - :and-you "and you" + { + ;common + :members-title "Members" + :not-implemented "!not implemented" + :chat-name "Chat name" + :notifications-title "Notifications and sounds" - :search-chat "Search chat" + ;drawer + :invite-friends "Invite friends" + :faq "FAQ" + :switch-users "Switch users" - :members {:one "1 member, 1 active" - :other "{{count}} members, {{count}} active"} - :last-active "Active a minute ago"} - :sign-up {:contacts-syncronized "Your contacts have been synchronized" - :confirmation-code (str "Thanks! We've sent you a text message with a confirmation " - "code. Please provide that code to confirm your phone number") - :password-saved (str "OK great! Your password has been saved. Just to let you " - "know you can always change it in the Console by the way " - "it's me the Console nice to meet you!") - :generate-passphrase (str "I'll generate a passphrase for you so you can restore your " - "access or log in from another device") - :passphrase "Here's your passphrase:" - :written-down "Make sure you had securely written it down" - :phone-number-required (str "Your phone number is also required to use the app. Type the " - "exclamation mark or hit the icon to open the command list " - "and choose the !phone command") - :intro-status (str "The brash businessman’s braggadocio " - "and public exchange with candidates " - "in the US presidential election") - :intro-message1 "Hello there! It's Status a Dapp browser in your phone." - :intro-message2 (str "Status1 uses a highly secure key-pair authentication type " - "to provide you a reliable way to access your account") - :keypair-generated (str "A key pair has been generated and saved to your device. " - "Create a password to secure your key")} - :chats {:title "Chats" - :new-chat "New Chat" - :new-group-chat "New Group Chat"} - :profile {:title "Profile" - :message "Message" - :username "Username" - :phone-number "Phone number" - :email "Email" - :report-user "REPORT USER"} - :settings {:title "Settings"} - :discovery {:title "Discovery" - :none "None" - :search-tags "Type your search tags here" - :popular-tags "Popular tags" - :recent "Recent"} - :contacts {:title "Contacts" - :no-name "Noname"} - :invite-friends {:title "Invite friends"} - :faq {:title "FAQ"} - :drawer {:switch-users "Switch users"} - :group-settings {:no-name "Noname" - :remove "Remove" - :save "Save" - :change-color "Change color" - :clear-history "Clear history" - :delete-and-leave "Delete and leave" - :chat-settings "Chat settings" - :edit "Edit" - :add-members "Add Members"} - :new-group {:title "New Group Chat" - :group-name "Group Name"} - :participants {:add "Add Participants" - :remove "Remove Participants"} - :commands {:money {:description "Send money"} - :location {:description "Send location"} - :phone {:description "Send phone number" - :request-text "Phone number request"} - :confirmation-code {:description "Send confirmation code" - :request-text "Confirmation code request"} - :send {:description "Send location"} - :request {:description "Send request"} - :keypair-password {:text:description ""} - :help {:description "Help"}} - :protocol {:received-invitation "received chat invitation" - :removed-from-chat "removed you from group chat"} - :colors {:blue "Blue" - :purple "Purple" - :green "Green" - :red "Red"} - :notifications {:title "Notifications and sounds"} - :not-implemented "!not implemented" - :chat-name "Chat name" - :members-title "Members" - :left "left" - :invited "invited" - :removed "removed" - :You "You"}) \ No newline at end of file + ;chat + :is-typing "is typing" + :and-you "and you" + :search-chat "Search chat" + :members {:one "1 member, 1 active" + :other "{{count}} members, {{count}} active"} + :last-active "Active a minute ago" + + ;profile + :profile "Profile" + :report-user "REPORT USER" + :message "Message" + :username "Username" + :phone-number "Phone number" + :email "Email" + + ;sign-up + :contacts-syncronized "Your contacts have been synchronized" + :confirmation-code (str "Thanks! We've sent you a text message with a confirmation " + "code. Please provide that code to confirm your phone number") + :password-saved (str "OK great! Your password has been saved. Just to let you " + "know you can always change it in the Console by the way " + "it's me the Console nice to meet you!") + :generate-passphrase (str "I'll generate a passphrase for you so you can restore your " + "access or log in from another device") + :passphrase "Here's your passphrase:" + :written-down "Make sure you had securely written it down" + :phone-number-required (str "Your phone number is also required to use the app. Type the " + "exclamation mark or hit the icon to open the command list " + "and choose the !phone command") + :intro-status (str "The brash businessman’s braggadocio " + "and public exchange with candidates " + "in the US presidential election") + :intro-message1 "Hello there! It's Status a Dapp browser in your phone." + :intro-message2 (str "Status1 uses a highly secure key-pair authentication type " + "to provide you a reliable way to access your account") + :keypair-generated (str "A key pair has been generated and saved to your device. " + "Create a password to secure your key") + + ;chats + :chats "Chats" + :new-chat "New Chat" + :new-group-chat "New Group Chat" + + ;discover + :discovery "Discovery" + :none "None" + :search-tags "Type your search tags here" + :popular-tags "Popular tags" + :recent "Recent" + + ;settings + :settings "Settings" + + ;contacts + :contacts "Contacts" + :no-name "Noname" + + ;group-settings + :remove "Remove" + :save "Save" + :change-color "Change color" + :clear-history "Clear history" + :delete-and-leave "Delete and leave" + :chat-settings "Chat settings" + :edit "Edit" + :add-members "Add Members" + :blue "Blue" + :purple "Purple" + :green "Green" + :red "Red" + + ;commands + :money-command-description "Send money" + :location-command-description "Send location" + :phone-command-description "Send phone number" + :phone-request-text "Phone number request" + :confirmation-code-coomand-description "Send confirmation code" + :confirmation-code-request-text "Confirmation code request" + :send-command-description "Send location" + :request-command-description "Send request" + :keypair-password-command-description "" + :help-command-description "Help" + + ;new-group + :group-name "Group Name" + + ;participants + :add-participants "Add Participants" + :remove-participants "Remove Participants" + + ;protocol + :received-invitation "received chat invitation" + :removed-from-chat "removed you from group chat" + :left "left" + :invited "invited" + :removed "removed" + :You "You" + + }) \ No newline at end of file From c10abb17bb012157dae8e472227b7df5d5e0e28e Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 26 May 2016 15:31:11 +0300 Subject: [PATCH 05/19] first attempt Former-commit-id: dc2839e0861cd17ae5b40d28f08c27dc6f658c8c --- .gitignore | 4 +++ project.clj | 9 +++--- test/status_im/appium.clj | 53 ++++++++++++++++++++++++++++++++++++ test/status_im/console.clj | 44 ++++++++++++++++++++++++++++++ test/status_im/core_test.clj | 7 ----- 5 files changed, 106 insertions(+), 11 deletions(-) create mode 100644 test/status_im/appium.clj create mode 100644 test/status_im/console.clj delete mode 100644 test/status_im/core_test.clj diff --git a/.gitignore b/.gitignore index 14773fe52f..ea7f8f836b 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,7 @@ target/ # figwheel_server.log .nrepl-port + +# Lein +# +.lein-failures diff --git a/project.clj b/project.clj index 647d7ad498..d68172cc05 100644 --- a/project.clj +++ b/project.clj @@ -8,7 +8,7 @@ [reagent "0.5.1" :exclusions [cljsjs/react]] [re-frame "0.6.0"] [prismatic/schema "1.0.4"] - ^{:voom {:repo "https://github.com/status-im/status-lib.git" + ^{:voom {:repo "git@github.com:status-im/status-lib.git" :branch "master"}} [status-im/protocol "0.1.1-20160525_083359-g53ab2c2"] [natal-shell "0.1.6"] @@ -22,7 +22,9 @@ ["with-profile" "prod" "cljsbuild" "once" "android"]]} :figwheel {:nrepl-port 7888} :profiles {:dev {:dependencies [[figwheel-sidecar "0.5.0-2"] - [com.cemerick/piggieback "0.2.1"]] + [com.cemerick/piggieback "0.2.1"] + [io.appium/java-client "3.4.1"] + ] :source-paths ["src" "env/dev"] :cljsbuild {:builds {:ios {:source-paths ["src" "env/dev"] :figwheel true @@ -46,5 +48,4 @@ :compiler {:output-to "index.android.js" :main "env.android.main" :output-dir "target/android" - :optimizations :simple}}}} - }}) + :optimizations :simple}}}}}}) diff --git a/test/status_im/appium.clj b/test/status_im/appium.clj new file mode 100644 index 0000000000..a879a68ba2 --- /dev/null +++ b/test/status_im/appium.clj @@ -0,0 +1,53 @@ +(ns status-im.appium + (:require [clojure.java.io :as io] + [clojure.test :refer :all]) + (:import (org.openqa.selenium.remote DesiredCapabilities) + (org.openqa.selenium By) + (io.appium.java_client.android AndroidDriver) + (java.net URL) + (java.util.concurrent TimeUnit))) + + +(defn init [] + (let [dir (io/file (str (System/getProperty "user.dir") + "/android/app/build/outputs/apk")) + app (io/file dir "app-debug.apk") + capabilities (doto (DesiredCapabilities.) + (.setCapability "deviceName" "device") + (.setCapability "platformVersion" "6.0.0") + (.setCapability "app" (.getAbsolutePath app)) + (.setCapability "appPackage" "com.statusim") + (.setCapability "appActivity" ".MainActivity")) + driver (AndroidDriver. (URL. "http://127.0.0.1:4723/wd/hub") capabilities)] + (-> driver + .manage + .timeouts + (.implicitlyWait 100 TimeUnit/MILLISECONDS)) + (Thread/sleep 9000) + driver)) + +(defn by-xpath [driver xpath] + (.findElement driver (By/xpath xpath))) + +(defn elements-by-xpath [driver xpath] + (.findElements driver (By/xpath xpath))) + +(defn click [driver xpath] + (.click (by-xpath driver xpath))) + +(defn write [driver input-xpath text] + (.sendKeys (by-xpath driver input-xpath) (into-array [text]))) + +(defn get-text [driver xpath] + (.getText (by-xpath driver xpath))) + +(defn xpath-by-text [text] + (str ".//*[@text='" text "']" )) + +(defn contains-text [driver text] + (is (= 1 (->> (xpath-by-text text) + (elements-by-xpath driver) + (.size))))) + +(defn quit [driver] + (.quit driver)) diff --git a/test/status_im/console.clj b/test/status_im/console.clj new file mode 100644 index 0000000000..a99251393d --- /dev/null +++ b/test/status_im/console.clj @@ -0,0 +1,44 @@ +(ns status-im.console + (:require [clojure.test :refer :all] + [status-im.appium :refer :all])) + +(def command-request-icon + (str + "//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]" + "/android.widget.FrameLayout[1]/android.view.ViewGroup[1]" + "/android.widget.ScrollView[1]/android.view.ViewGroup[1]" + "/android.view.ViewGroup[1]/android.view.ViewGroup[1]" + "/android.view.ViewGroup[2]/android.widget.ImageView[1]")) + +(def input + (str + "//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]" + "/android.widget.FrameLayout[1]/android.view.ViewGroup[1]" + "/android.view.ViewGroup[2]/android.view.ViewGroup[1]" + "/android.widget.EditText[1]")) + +(def send-button1 + (str "//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]" + "/android.widget.FrameLayout[1]/android.view.ViewGroup[1]" + "/android.view.ViewGroup[2]/android.view.ViewGroup[1]" + "/android.view.ViewGroup[2]/android.view.ViewGroup[1]")) + +(def send-button2 + (str "//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]" + "/android.widget.FrameLayout[1]/android.view.ViewGroup[1]" + "/android.view.ViewGroup[2]/android.view.ViewGroup[2]" + "/android.view.ViewGroup[2]/android.view.ViewGroup[1]")) + +(def message-text + (str "Your phone number is also required to use the app. Type" + " the exclamation mark or hit the icon to open the command " + "list and choose the !phone command")) + +(deftest console-test + (let [driver (init)] + (click driver command-request-icon) + (write driver input "123") + (click driver send-button1) + (click driver send-button2) + (contains-text driver message-text) + (quit driver))) diff --git a/test/status_im/core_test.clj b/test/status_im/core_test.clj deleted file mode 100644 index 1224033d1c..0000000000 --- a/test/status_im/core_test.clj +++ /dev/null @@ -1,7 +0,0 @@ -(ns status-im.core-test - (:require [clojure.test :refer :all] - [status-im.core :refer :all])) - -(deftest a-test - (testing "FIXME, I fail." - (is (= 0 1)))) From 6823acd171eeb4ff5b777a49bc30abbb8e805da8 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 26 May 2016 16:46:14 +0300 Subject: [PATCH 06/19] :accessibility-label Former-commit-id: 63dd0d4a4a63c1d71bcafe6b7e56ecc00fd3c9aa --- src/status_im/chat/views/command.cljs | 6 ++-- src/status_im/chat/views/message.cljs | 7 ++++- src/status_im/chat/views/plain_input.cljs | 19 ++++++------ test/status_im/appium.clj | 14 +++++++-- test/status_im/console.clj | 35 +++-------------------- 5 files changed, 35 insertions(+), 46 deletions(-) diff --git a/src/status_im/chat/views/command.cljs b/src/status_im/chat/views/command.cljs index ab90de0426..2b550dc7bf 100644 --- a/src/status_im/chat/views/command.cljs +++ b/src/status_im/chat/views/command.cljs @@ -38,11 +38,13 @@ :onChangeText set-input-message :onSubmitEditing (fn [] (when (valid? message validator) - (send-command)))} + (send-command))) + :accessibility-label :command-input} input-options) message] (if (valid? message validator) - [touchable-highlight {:on-press send-command} + [touchable-highlight {:on-press send-command + :accessibility-label :stage-command} [view st/send-container [icon :send st/send-icon]]] [touchable-highlight {:on-press cancel-command-input} [view st/cancel-container diff --git a/src/status_im/chat/views/message.cljs b/src/status_im/chat/views/message.cljs index d1b9750f5f..ceb430fc76 100644 --- a/src/status_im/chat/views/message.cljs +++ b/src/status_im/chat/views/message.cljs @@ -72,13 +72,18 @@ (defn set-chat-command [msg-id command] (dispatch [:set-response-chat-command msg-id (:command command)])) +(defn label [{:keys [command]}] + (->> (name command) + (str "request-"))) + (defn message-content-command-request [{:keys [msg-id content from incoming-group]}] (let [commands-atom (subscribe [:get-commands])] (fn [{:keys [msg-id content from incoming-group]}] (let [commands @commands-atom {:keys [command content]} (parse-command-request commands content)] - [touchable-highlight {:onPress #(set-chat-command msg-id command)} + [touchable-highlight {:onPress #(set-chat-command msg-id command) + :accessibility-label (label command)} [view st/comand-request-view [view st/command-request-message-view (when incoming-group diff --git a/src/status_im/chat/views/plain_input.cljs b/src/status_im/chat/views/plain_input.cljs index eaece17dfb..dcbc75780a 100644 --- a/src/status_im/chat/views/plain_input.cljs +++ b/src/status_im/chat/views/plain_input.cljs @@ -1,9 +1,9 @@ (ns status-im.chat.views.plain-input (:require [re-frame.core :refer [subscribe dispatch]] [status-im.components.react :refer [view - icon - touchable-highlight - text-input]] + icon + touchable-highlight + text-input]] [status-im.chat.views.suggestions :refer [suggestions-view]] [status-im.chat.styles.plain-input :as st])) @@ -39,15 +39,16 @@ (if @typing-command? [icon :close-gray st/close-icon] [icon :list st/list-icon])]] - [text-input {:style st/message-input - :autoFocus (pos? (count @staged-commands-atom)) - :onChangeText set-input-message - :onSubmitEditing #(try-send @chat @staged-commands-atom - input-message)} + [text-input {:style st/message-input + :autoFocus (pos? (count @staged-commands-atom)) + :onChangeText set-input-message + :onSubmitEditing #(try-send @chat @staged-commands-atom + input-message)} input-message] ;; TODO emoticons: not implemented [icon :smile st/smile-icon] (when (message-valid? @staged-commands-atom input-message) - [touchable-highlight {:on-press #(send @chat input-message)} + [touchable-highlight {:on-press #(send @chat input-message) + :accessibility-label :send-message} [view st/send-container [icon :send st/send-icon]]])]])))) diff --git a/test/status_im/appium.clj b/test/status_im/appium.clj index a879a68ba2..7a857711de 100644 --- a/test/status_im/appium.clj +++ b/test/status_im/appium.clj @@ -32,11 +32,19 @@ (defn elements-by-xpath [driver xpath] (.findElements driver (By/xpath xpath))) -(defn click [driver xpath] - (.click (by-xpath driver xpath))) +(defn by-id [driver id] + (.findElementByAccessibilityId driver (name id))) + +(defn get-element [driver id] + (if (keyword? id) + (by-id driver id) + (by-xpath driver id))) + +(defn click [driver id] + (.click (get-element driver id))) (defn write [driver input-xpath text] - (.sendKeys (by-xpath driver input-xpath) (into-array [text]))) + (.sendKeys (get-element driver input-xpath) (into-array [text]))) (defn get-text [driver xpath] (.getText (by-xpath driver xpath))) diff --git a/test/status_im/console.clj b/test/status_im/console.clj index a99251393d..4d748af7c2 100644 --- a/test/status_im/console.clj +++ b/test/status_im/console.clj @@ -2,33 +2,6 @@ (:require [clojure.test :refer :all] [status-im.appium :refer :all])) -(def command-request-icon - (str - "//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]" - "/android.widget.FrameLayout[1]/android.view.ViewGroup[1]" - "/android.widget.ScrollView[1]/android.view.ViewGroup[1]" - "/android.view.ViewGroup[1]/android.view.ViewGroup[1]" - "/android.view.ViewGroup[2]/android.widget.ImageView[1]")) - -(def input - (str - "//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]" - "/android.widget.FrameLayout[1]/android.view.ViewGroup[1]" - "/android.view.ViewGroup[2]/android.view.ViewGroup[1]" - "/android.widget.EditText[1]")) - -(def send-button1 - (str "//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]" - "/android.widget.FrameLayout[1]/android.view.ViewGroup[1]" - "/android.view.ViewGroup[2]/android.view.ViewGroup[1]" - "/android.view.ViewGroup[2]/android.view.ViewGroup[1]")) - -(def send-button2 - (str "//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]" - "/android.widget.FrameLayout[1]/android.view.ViewGroup[1]" - "/android.view.ViewGroup[2]/android.view.ViewGroup[2]" - "/android.view.ViewGroup[2]/android.view.ViewGroup[1]")) - (def message-text (str "Your phone number is also required to use the app. Type" " the exclamation mark or hit the icon to open the command " @@ -36,9 +9,9 @@ (deftest console-test (let [driver (init)] - (click driver command-request-icon) - (write driver input "123") - (click driver send-button1) - (click driver send-button2) + (click driver :request-keypair-password) + (write driver :command-input "123") + (click driver :stage-command) + (click driver :send-message) (contains-text driver message-text) (quit driver))) From 23b646c2131c681a2083bd8cc9633a81228a53b1 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 26 May 2016 17:00:42 +0300 Subject: [PATCH 07/19] appium-test macro Former-commit-id: 54ae25dc67ec9ca2d75e87f8b62637c4c8592c43 --- test/status_im/appium.clj | 10 +++++++++- test/status_im/console.clj | 14 ++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/test/status_im/appium.clj b/test/status_im/appium.clj index 7a857711de..d2ff6adb53 100644 --- a/test/status_im/appium.clj +++ b/test/status_im/appium.clj @@ -50,7 +50,7 @@ (.getText (by-xpath driver xpath))) (defn xpath-by-text [text] - (str ".//*[@text='" text "']" )) + (str ".//*[@text='" text "']")) (defn contains-text [driver text] (is (= 1 (->> (xpath-by-text text) @@ -59,3 +59,11 @@ (defn quit [driver] (.quit driver)) + +(defmacro appium-test [name & body] + (let [sym (gensym)] + `(deftest ~name + (let [~sym (init)] + ~@(for [[f & rest] body] + `(~f ~sym ~@rest)) + (quit ~sym))))) diff --git a/test/status_im/console.clj b/test/status_im/console.clj index 4d748af7c2..5cdf17ae45 100644 --- a/test/status_im/console.clj +++ b/test/status_im/console.clj @@ -7,11 +7,9 @@ " the exclamation mark or hit the icon to open the command " "list and choose the !phone command")) -(deftest console-test - (let [driver (init)] - (click driver :request-keypair-password) - (write driver :command-input "123") - (click driver :stage-command) - (click driver :send-message) - (contains-text driver message-text) - (quit driver))) +(appium-test console-test + (click :request-keypair-password) + (write :command-input "123") + (click :stage-command) + (click :send-message) + (contains-text message-text)) From e8256f34e918b353ebc69c82d89757c2b74d9dc8 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 26 May 2016 18:13:37 +0300 Subject: [PATCH 08/19] implicitly wait 25s Former-commit-id: 0e3c1d10ba0ef3205efb800ce5d98f71f4266274 --- test/status_im/appium.clj | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/status_im/appium.clj b/test/status_im/appium.clj index d2ff6adb53..061ed3f4b4 100644 --- a/test/status_im/appium.clj +++ b/test/status_im/appium.clj @@ -22,8 +22,7 @@ (-> driver .manage .timeouts - (.implicitlyWait 100 TimeUnit/MILLISECONDS)) - (Thread/sleep 9000) + (.implicitlyWait 25 TimeUnit/SECONDS)) driver)) (defn by-xpath [driver xpath] From ee2087ce7784594bb7f0c6b2286d602f7fecc2ca Mon Sep 17 00:00:00 2001 From: Jarrad Hope Date: Thu, 26 May 2016 18:05:10 +0200 Subject: [PATCH 09/19] run appium with second param Former-commit-id: a2e14e4ff09b49cce3d170341e8623cdcd4c46d9 --- .re-natal | 2 +- run-osx.sh | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.re-natal b/.re-natal index 1455b14c43..b4f25ba62a 100644 --- a/.re-natal +++ b/.re-natal @@ -1,7 +1,7 @@ { "name": "StatusIm", "interface": "reagent", - "androidHost": "localhost", + "androidHost": "10.0.3.2", "modules": [ "react-native-contacts", "react-native-invertible-scroll-view", diff --git a/run-osx.sh b/run-osx.sh index 9f89a05857..d02de2a3e1 100755 --- a/run-osx.sh +++ b/run-osx.sh @@ -59,3 +59,9 @@ sleep 10s adb reverse tcp:8081 tcp:8081 && adb reverse tcp:3449 tcp:3449 react-native run-android + +if [ ! -z $2 ] +then + tab "appium" + lein test +fi \ No newline at end of file From 17c1c7600328835f079d54012691a437a517cba6 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Fri, 27 May 2016 19:44:06 +0300 Subject: [PATCH 10/19] clean js/window first attempt Former-commit-id: 7694ad9e873d80824a07798de66b96b0f6a96dbb --- src/status_im/components/action_button.cljs | 6 +++--- src/status_im/components/icons/ionicons.cljs | 4 +--- .../components/invertible_scroll_view.cljs | 5 ++--- src/status_im/components/item_checkbox.cljs | 4 +--- src/status_im/components/realm.cljs | 9 -------- src/status_im/components/toolbar.cljs | 4 +--- src/status_im/i18n.cljs | 21 +++++-------------- src/status_im/utils/crypt.cljs | 10 ++++----- src/status_im/utils/listview.cljs | 3 +-- 9 files changed, 19 insertions(+), 47 deletions(-) delete mode 100644 src/status_im/components/realm.cljs diff --git a/src/status_im/components/action_button.cljs b/src/status_im/components/action_button.cljs index db303f5f6d..6ee896d1ed 100644 --- a/src/status_im/components/action_button.cljs +++ b/src/status_im/components/action_button.cljs @@ -1,7 +1,7 @@ (ns status-im.components.action-button (:require [reagent.core :as r])) -(set! js/window.ActionButton (js/require "react-native-action-button")) +(def class (js/require "react-native-action-button")) -(def action-button (r/adapt-react-class (.-default js/ActionButton))) -(def action-button-item (r/adapt-react-class (.. js/ActionButton -default -Item))) \ No newline at end of file +(def action-button (r/adapt-react-class (.-default class))) +(def action-button-item (r/adapt-react-class (.. class -default -Item))) diff --git a/src/status_im/components/icons/ionicons.cljs b/src/status_im/components/icons/ionicons.cljs index 885af057d5..5bc4a06ddc 100644 --- a/src/status_im/components/icons/ionicons.cljs +++ b/src/status_im/components/icons/ionicons.cljs @@ -1,6 +1,4 @@ (ns status-im.components.icons.ionicons (:require [reagent.core :as r])) -(set! js/window.Ionicons (js/require "react-native-vector-icons/Ionicons")) - -(def icon (r/adapt-react-class js/Ionicons)) +(def icon (r/adapt-react-class (js/require "react-native-vector-icons/Ionicons"))) diff --git a/src/status_im/components/invertible_scroll_view.cljs b/src/status_im/components/invertible_scroll_view.cljs index daf873a773..ba4a1d546a 100644 --- a/src/status_im/components/invertible_scroll_view.cljs +++ b/src/status_im/components/invertible_scroll_view.cljs @@ -1,8 +1,7 @@ (ns status-im.components.invertible-scroll-view) -(set! js/window.InvertibleScrollView (js/require "react-native-invertible-scroll-view")) +(def class (js/require "react-native-invertible-scroll-view")) (defn invertible-scroll-view [props] - (js/React.createElement js/InvertibleScrollView - (clj->js (merge {:inverted true} props)))) + (js/React.createElement class (clj->js (merge {:inverted true} props)))) diff --git a/src/status_im/components/item_checkbox.cljs b/src/status_im/components/item_checkbox.cljs index 97d43ecd37..45c667141d 100644 --- a/src/status_im/components/item_checkbox.cljs +++ b/src/status_im/components/item_checkbox.cljs @@ -1,7 +1,5 @@ (ns status-im.components.item-checkbox (:require [reagent.core :as r])) -(set! js/window.ItemCheckbox (js/require "react-native-circle-checkbox")) - -(def item-checkbox (r/adapt-react-class js/ItemCheckbox)) +(def item-checkbox (r/adapt-react-class (js/require "react-native-circle-checkbox"))) diff --git a/src/status_im/components/realm.cljs b/src/status_im/components/realm.cljs deleted file mode 100644 index eff8c1fee5..0000000000 --- a/src/status_im/components/realm.cljs +++ /dev/null @@ -1,9 +0,0 @@ -(ns status-im.components.realm - (:require [reagent.core :as r])) - -(set! js/window.RealmReactNative (js/require "realm/react-native")) - -(def list-view-class (r/adapt-react-class (.-ListView js/RealmReactNative))) - -(defn list-view [props] - [list-view-class (merge {:enableEmptySections true} props)]) diff --git a/src/status_im/components/toolbar.cljs b/src/status_im/components/toolbar.cljs index 3f21fc8a35..0591c1aba1 100644 --- a/src/status_im/components/toolbar.cljs +++ b/src/status_im/components/toolbar.cljs @@ -12,9 +12,7 @@ color-purple text1-color text2-color - toolbar-background1]] - [status-im.components.realm :refer [list-view]] - [reagent.core :as r])) + toolbar-background1]])) (defn toolbar [{:keys [title nav-action hide-nav? action custom-action background-color custom-content style]}] diff --git a/src/status_im/i18n.cljs b/src/status_im/i18n.cljs index 9abde5c46e..4a6157cc23 100644 --- a/src/status_im/i18n.cljs +++ b/src/status_im/i18n.cljs @@ -2,22 +2,11 @@ (:require [status-im.translations.en :as en])) -(set! js/window.I18n (js/require "react-native-i18n")) -(set! (.-fallbacks js/I18n) true) -(set! (.-defaultSeparator js/I18n) "/") +(def i18n (js/require "react-native-i18n")) +(set! (.-fallbacks i18n) true) +(set! (.-defaultSeparator i18n) "/") -(set! (.-translations js.I18n) (clj->js {:en en/translations})) +(set! (.-translations i18n) (clj->js {:en en/translations})) (defn label [path & options] - (.t js/I18n (name path) (clj->js options))) - -(comment - (defn deep-merge [& maps] - (if (every? map? maps) - (apply merge-with deep-merge maps) - (last maps))) - - (defn add-translations [new-translations] - (let [translations (.-translations js/I18n)] - (set! (.-translations js/I18n) (clj->js (deep-merge (js->clj translations) new-translations))))) - ) \ No newline at end of file + (.t i18n (name path) (clj->js options))) diff --git a/src/status_im/utils/crypt.cljs b/src/status_im/utils/crypt.cljs index 722581d10c..87730efe8c 100644 --- a/src/status_im/utils/crypt.cljs +++ b/src/status_im/utils/crypt.cljs @@ -3,7 +3,7 @@ [clojure.string :as s]) (:import goog.crypt.Sha256)) -(set! js/window.RnRandomBytes (js/require "react-native-randombytes")) +(def random-bytes (js/require "react-native-randombytes")) (def sha-256 (Sha256.)) @@ -19,7 +19,7 @@ (byteArrayToHex (.digest sha-256))) (defn gen-random-bytes [length cb] - (.randomBytes js/window.RnRandomBytes length (fn [& [err buf]] - (if err - (cb {:error err}) - (cb {:buffer buf}))))) + (.randomBytes random-bytes length (fn [& [err buf]] + (if err + (cb {:error err}) + (cb {:buffer buf}))))) diff --git a/src/status_im/utils/listview.cljs b/src/status_im/utils/listview.cljs index bd9dfe5dc5..dcd63da8bd 100644 --- a/src/status_im/utils/listview.cljs +++ b/src/status_im/utils/listview.cljs @@ -1,6 +1,5 @@ (ns status-im.utils.listview - (:require-macros [natal-shell.data-source :refer [data-source]]) - (:require [status-im.components.realm])) + (:require-macros [natal-shell.data-source :refer [data-source]])) (defn clone-with-rows [ds rows] (.cloneWithRows ds (reduce (fn [ac el] (.push ac el) ac) From 59cf02194b0f3b06384c86bd8e528edcc1aa2e15 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Sun, 29 May 2016 10:30:46 +0300 Subject: [PATCH 11/19] js/window Former-commit-id: 043d28c44d8c62496627e39fd0cb21d4a70fb27e --- src/status_im/android/core.cljs | 3 +- .../components/carousel/carousel.cljs | 5 ++- src/status_im/components/drawer/view.cljs | 5 ++- .../components/invertible_scroll_view.cljs | 5 ++- src/status_im/components/react.cljs | 45 ++++++++++--------- src/status_im/discovery/views/popular.cljs | 6 +-- src/status_im/persistence/realm.cljs | 6 +-- 7 files changed, 41 insertions(+), 34 deletions(-) diff --git a/src/status_im/android/core.cljs b/src/status_im/android/core.cljs index 080a91fa54..cf3c7d48e1 100644 --- a/src/status_im/android/core.cljs +++ b/src/status_im/android/core.cljs @@ -60,4 +60,5 @@ (dispatch [:init-console-chat]) (dispatch [:init-chat]) (init-back-button-handler!) - (.registerComponent app-registry "StatusIm" #(r/reactify-component app-root))) + ;(.registerComponent app-registry "StatusIm" #(r/reactify-component app-root)) + ) diff --git a/src/status_im/components/carousel/carousel.cljs b/src/status_im/components/carousel/carousel.cljs index c3181df6ce..8c61cb114e 100644 --- a/src/status_im/components/carousel/carousel.cljs +++ b/src/status_im/components/carousel/carousel.cljs @@ -5,11 +5,12 @@ touchable-without-feedback text]] [status-im.components.carousel.styles :as st] - [status-im.utils.logging :as log])) + [status-im.utils.logging :as log] + [status-im.components.react :as r])) (defn window-page-width [] - (.-width (.get (.. js/React -Dimensions) "window"))) + (.-width (.get (.. r/react -Dimensions) "window"))) (def defaults {:gap 10 :sneak 10 diff --git a/src/status_im/components/drawer/view.cljs b/src/status_im/components/drawer/view.cljs index 1cd4ae43e8..0ac23a7dbb 100644 --- a/src/status_im/components/drawer/view.cljs +++ b/src/status_im/components/drawer/view.cljs @@ -12,7 +12,8 @@ touchable-opacity]] [status-im.resources :as res] [status-im.components.drawer.styles :as st] - [status-im.i18n :refer [label]])) + [status-im.i18n :refer [label]] + [status-im.components.react :refer [react]])) (defonce drawer-atom (atom)) @@ -72,7 +73,7 @@ (defn drawer-view [items] [drawer-layout-android {:drawerWidth 260 - :drawerPosition js/React.DrawerLayoutAndroid.positions.Left + :drawerPosition react.DrawerLayoutAndroid.positions.Left :render-navigation-view #(r/as-element [drawer-menu]) :ref (fn [drawer] (reset! drawer-atom drawer))} diff --git a/src/status_im/components/invertible_scroll_view.cljs b/src/status_im/components/invertible_scroll_view.cljs index ba4a1d546a..429d66d6ed 100644 --- a/src/status_im/components/invertible_scroll_view.cljs +++ b/src/status_im/components/invertible_scroll_view.cljs @@ -1,7 +1,8 @@ -(ns status-im.components.invertible-scroll-view) +(ns status-im.components.invertible-scroll-view + (:require [reagent.core :as r])) (def class (js/require "react-native-invertible-scroll-view")) (defn invertible-scroll-view [props] - (js/React.createElement class (clj->js (merge {:inverted true} props)))) + (r/create-element class (clj->js (merge {:inverted true} props)))) diff --git a/src/status_im/components/react.cljs b/src/status_im/components/react.cljs index 930f6deedf..d79d7d4fa9 100644 --- a/src/status_im/components/react.cljs +++ b/src/status_im/components/react.cljs @@ -2,25 +2,28 @@ (:require [reagent.core :as r] [status-im.components.styles :as st])) -(set! js/window.React (js/require "react-native")) +(when (exists? js/window) + (set! js/window.React (js/require "react-native"))) -(def app-registry (.-AppRegistry js/React)) -(def navigator (r/adapt-react-class (.-Navigator js/React))) -(def text (r/adapt-react-class (.-Text js/React))) -(def view (r/adapt-react-class (.-View js/React))) -(def image (r/adapt-react-class (.-Image js/React))) -(def touchable-highlight-class (r/adapt-react-class (.-TouchableHighlight js/React))) +(def react (js/require "react-native")) + +(def app-registry (.-AppRegistry react)) +(def navigator (r/adapt-react-class (.-Navigator react))) +(def text (r/adapt-react-class (.-Text react))) +(def view (r/adapt-react-class (.-View react))) +(def image (r/adapt-react-class (.-Image react))) +(def touchable-highlight-class (r/adapt-react-class (.-TouchableHighlight react))) (defn touchable-highlight [props content] [touchable-highlight-class (merge {:underlay-color :transparent} props) content]) -(def toolbar-android (r/adapt-react-class (.-ToolbarAndroid js/React))) -(def list-view-class (r/adapt-react-class (.-ListView js/React))) +(def toolbar-android (r/adapt-react-class (.-ToolbarAndroid react))) +(def list-view-class (r/adapt-react-class (.-ListView react))) (defn list-view [props] [list-view-class (merge {:enableEmptySections true} props)]) -(def scroll-view (r/adapt-react-class (.-ScrollView js/React))) -(def touchable-without-feedback (r/adapt-react-class (.-TouchableWithoutFeedback js/React))) -(def text-input-class (r/adapt-react-class (.-TextInput js/React))) +(def scroll-view (r/adapt-react-class (.-ScrollView react))) +(def touchable-without-feedback (r/adapt-react-class (.-TouchableWithoutFeedback react))) +(def text-input-class (r/adapt-react-class (.-TextInput react))) (defn text-input [props text] [text-input-class (merge {:underlineColorAndroid :transparent @@ -28,11 +31,11 @@ :placeholder "Type"} props) text]) -(def drawer-layout-android (r/adapt-react-class (.-DrawerLayoutAndroid js/React))) -(def touchable-opacity (r/adapt-react-class (.-TouchableOpacity js/React))) -(def modal (r/adapt-react-class (.-Modal js/React))) -(def picker (r/adapt-react-class (.-Picker js/React))) -(def picker-item (r/adapt-react-class (.-Item (.-Picker js/React)))) +(def drawer-layout-android (r/adapt-react-class (.-DrawerLayoutAndroid react))) +(def touchable-opacity (r/adapt-react-class (.-TouchableOpacity react))) +(def modal (r/adapt-react-class (.-Modal react))) +(def picker (r/adapt-react-class (.-Picker react))) +(def picker-item (r/adapt-react-class (.-Item (.-Picker react)))) (defn icon @@ -44,13 +47,13 @@ ;(def react-linear-gradient (.-default (js/require "react-native-linear-gradient"))) ;(def linear-gradient (r/adapt-react-class react-linear-gradient)) -(set! js/window.LinearGradient (js/require "react-native-linear-gradient")) +(def linear-gradient-class (js/require "react-native-linear-gradient")) (defn linear-gradient [props] - (js/React.createElement js/LinearGradient - (clj->js (merge {:inverted true} props)))) + (r/creacteElement linear-gradient-class + (clj->js (merge {:inverted true} props)))) -(def platform (.. js/React -Platform -OS)) +(def platform (.. react -Platform -OS)) (def android? (= platform "android")) diff --git a/src/status_im/discovery/views/popular.cljs b/src/status_im/discovery/views/popular.cljs index 9fbeb4f9fb..b91b233603 100644 --- a/src/status_im/discovery/views/popular.cljs +++ b/src/status_im/discovery/views/popular.cljs @@ -2,16 +2,16 @@ (:require-macros [status-im.utils.views :refer [defview]]) (:require [re-frame.core :refer [subscribe]] - [status-im.utils.logging :as log] [status-im.components.react :refer [android? text]] [status-im.components.carousel.carousel :refer [carousel]] [status-im.discovery.styles :as st] [status-im.discovery.views.popular-list :refer [discovery-popular-list]] - [status-im.i18n :refer [label]])) + [status-im.i18n :refer [label]] + [status-im.components.react :as r])) (defn page-width [] - (.-width (.get (.. js/React -Dimensions) "window"))) + (.-width (.get (.. r/react -Dimensions) "window"))) (defview popular [] [popular-tags [:get-popular-tags 3]] diff --git a/src/status_im/persistence/realm.cljs b/src/status_im/persistence/realm.cljs index a7d564f143..7056c11e9d 100644 --- a/src/status_im/persistence/realm.cljs +++ b/src/status_im/persistence/realm.cljs @@ -5,8 +5,6 @@ [status-im.utils.types :refer [to-string]]) (:refer-clojure :exclude [exists?])) -(set! js/window.Realm (js/require "realm")) - (def opts {:schema [{:name :contacts :primaryKey :whisper-identity :properties {:phone-number {:type "string" @@ -70,7 +68,9 @@ :objectType "tag"} :last-updated "date"}}]}) -(def realm (js/Realm. (clj->js opts))) +(def realm-class (js/require "realm")) + +(def realm (realm-class. (clj->js opts))) (def schema-by-name (->> (:schema opts) (mapv (fn [{:keys [name] :as schema}] From 3ea8b2cb828e92b0c6b1a4db1f6d9b7fd83ea9c8 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Sun, 29 May 2016 21:14:34 +0300 Subject: [PATCH 12/19] first unit test Former-commit-id: 1766b1af1295f6773f580a3a6d3a1afba3dbff0a --- .gitignore | 5 ++ project.clj | 15 ++-- src/status_im/android/core.cljs | 3 +- src/status_im/components/drawer/view.cljs | 84 +++++++++++------------ src/status_im/components/react.cljs | 60 +++++++++------- src/status_im/contacts/handlers.cljs | 2 +- src/status_im/handlers.cljs | 16 +++-- src/status_im/i18n.cljs | 9 ++- src/status_im/persistence/realm.cljs | 8 ++- src/status_im/utils/crypt.cljs | 7 +- src/status_im/utils/phone_number.cljs | 13 ++-- src/status_im/utils/sms_listener.cljs | 5 +- src/status_im/utils/utils.cljs | 5 ++ test/{ => clj}/status_im/appium.clj | 0 test/{ => clj}/status_im/console.clj | 0 test/cljs/status_im/test/handlers.cljs | 6 ++ test/cljs/status_im/test/runner.cljs | 5 ++ 17 files changed, 145 insertions(+), 98 deletions(-) rename test/{ => clj}/status_im/appium.clj (100%) rename test/{ => clj}/status_im/console.clj (100%) create mode 100644 test/cljs/status_im/test/handlers.cljs create mode 100644 test/cljs/status_im/test/runner.cljs diff --git a/.gitignore b/.gitignore index ea7f8f836b..3e79181fd8 100644 --- a/.gitignore +++ b/.gitignore @@ -54,3 +54,8 @@ figwheel_server.log # Lein # .lein-failures + +## Doo +# +out +doo-index.html diff --git a/project.clj b/project.clj index d68172cc05..4007f3100d 100644 --- a/project.clj +++ b/project.clj @@ -8,7 +8,7 @@ [reagent "0.5.1" :exclusions [cljsjs/react]] [re-frame "0.6.0"] [prismatic/schema "1.0.4"] - ^{:voom {:repo "git@github.com:status-im/status-lib.git" + ^{:voom {:repo "git@github.com:status-im/status-lib.git" :branch "master"}} [status-im/protocol "0.1.1-20160525_083359-g53ab2c2"] [natal-shell "0.1.6"] @@ -20,11 +20,12 @@ ["do" "clean" ["with-profile" "prod" "cljsbuild" "once" "ios"] ["with-profile" "prod" "cljsbuild" "once" "android"]]} + :test-paths ["test/clj"] :figwheel {:nrepl-port 7888} :profiles {:dev {:dependencies [[figwheel-sidecar "0.5.0-2"] [com.cemerick/piggieback "0.2.1"] - [io.appium/java-client "3.4.1"] - ] + [io.appium/java-client "3.4.1"]] + :plugins [[lein-doo "0.1.6"]] :source-paths ["src" "env/dev"] :cljsbuild {:builds {:ios {:source-paths ["src" "env/dev"] :figwheel true @@ -37,7 +38,13 @@ :compiler {:output-to "target/android/not-used.js" :main "env.android.main" :output-dir "target/android" - :optimizations :none}}}} + :optimizations :none}} + :test {:source-paths ["src" "test/cljs"] + :compiler + {:main status-im.test.runner + :output-to "target/test/test.js" + :optimizations :none + :target :nodejs}}}} :repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}} :prod {:cljsbuild {:builds {:ios {:source-paths ["src" "env/prod"] :compiler {:output-to "index.ios.js" diff --git a/src/status_im/android/core.cljs b/src/status_im/android/core.cljs index cf3c7d48e1..080a91fa54 100644 --- a/src/status_im/android/core.cljs +++ b/src/status_im/android/core.cljs @@ -60,5 +60,4 @@ (dispatch [:init-console-chat]) (dispatch [:init-chat]) (init-back-button-handler!) - ;(.registerComponent app-registry "StatusIm" #(r/reactify-component app-root)) - ) + (.registerComponent app-registry "StatusIm" #(r/reactify-component app-root))) diff --git a/src/status_im/components/drawer/view.cljs b/src/status_im/components/drawer/view.cljs index 0ac23a7dbb..61b7d698b6 100644 --- a/src/status_im/components/drawer/view.cljs +++ b/src/status_im/components/drawer/view.cljs @@ -2,18 +2,16 @@ (:require [clojure.string :as s] [re-frame.core :refer [subscribe dispatch dispatch-sync]] [reagent.core :as r] - [status-im.components.react :refer [android? - view - text - image - navigator - toolbar-android - drawer-layout-android - touchable-opacity]] + [status-im.components.react :as re :refer [view + text + image + navigator + toolbar-android + drawer-layout-android + touchable-opacity]] [status-im.resources :as res] [status-im.components.drawer.styles :as st] - [status-im.i18n :refer [label]] - [status-im.components.react :refer [react]])) + [status-im.i18n :refer [label]])) (defonce drawer-atom (atom)) @@ -30,7 +28,7 @@ :style st/user-photo}]) (defn menu-item [{:keys [name handler]}] - [touchable-opacity {:style st/menu-item-touchable + [touchable-opacity {:style st/menu-item-touchable :onPress (fn [] (close-drawer) (handler))} @@ -41,40 +39,40 @@ (let [username (subscribe [:get :username])] (fn [] [view st/drawer-menu - [view st/user-photo-container - [user-photo {}]] - [view st/name-container - [text {:style st/name-text} - @username]] - [view st/menu-items-container - [menu-item {:name (label :t/profile) - :handler #(dispatch [:navigate-to :my-profile])}] - [menu-item {:name (label :t/settings) - :handler (fn [] - ;; TODO not implemented - )}] - [menu-item {:name (label :t/discovery) - :handler #(dispatch [:navigate-to :discovery])}] - [menu-item {:name (label :t/contacts) - :handler #(dispatch [:show-contacts navigator])}] - [menu-item {:name (label :t/invite-friends) - :handler (fn [] - ;; TODO not implemented - )}] - [menu-item {:name (label :t/faq) - :handler (fn [])}]] - [view st/switch-users-container - [touchable-opacity {:onPress (fn [] - (close-drawer) - ;; TODO not implemented - )} - [text {:style st/switch-users-text} - (label :t/switch-users)]]]]))) + [view st/user-photo-container + [user-photo {}]] + [view st/name-container + [text {:style st/name-text} + @username]] + [view st/menu-items-container + [menu-item {:name (label :t/profile) + :handler #(dispatch [:navigate-to :my-profile])}] + [menu-item {:name (label :t/settings) + :handler (fn [] + ;; TODO not implemented + )}] + [menu-item {:name (label :t/discovery) + :handler #(dispatch [:navigate-to :discovery])}] + [menu-item {:name (label :t/contacts) + :handler #(dispatch [:show-contacts navigator])}] + [menu-item {:name (label :t/invite-friends) + :handler (fn [] + ;; TODO not implemented + )}] + [menu-item {:name (label :t/faq) + :handler (fn [])}]] + [view st/switch-users-container + [touchable-opacity {:onPress (fn [] + (close-drawer) + ;; TODO not implemented + )} + [text {:style st/switch-users-text} + (label :t/switch-users)]]]]))) (defn drawer-view [items] [drawer-layout-android {:drawerWidth 260 - :drawerPosition react.DrawerLayoutAndroid.positions.Left + :drawerPosition re/react.DrawerLayoutAndroild.positions.Left :render-navigation-view #(r/as-element [drawer-menu]) - :ref (fn [drawer] - (reset! drawer-atom drawer))} + :ref (fn [drawer] + (reset! drawer-atom drawer))} items]) diff --git a/src/status_im/components/react.cljs b/src/status_im/components/react.cljs index d79d7d4fa9..5daccaee88 100644 --- a/src/status_im/components/react.cljs +++ b/src/status_im/components/react.cljs @@ -1,29 +1,39 @@ (ns status-im.components.react (:require [reagent.core :as r] - [status-im.components.styles :as st])) + [status-im.components.styles :as st] + [status-im.utils.utils :as u])) (when (exists? js/window) (set! js/window.React (js/require "react-native"))) -(def react (js/require "react-native")) +(def react (u/require "react-native")) -(def app-registry (.-AppRegistry react)) -(def navigator (r/adapt-react-class (.-Navigator react))) -(def text (r/adapt-react-class (.-Text react))) -(def view (r/adapt-react-class (.-View react))) -(def image (r/adapt-react-class (.-Image react))) -(def touchable-highlight-class (r/adapt-react-class (.-TouchableHighlight react))) +(defn get-react-property [name] + (aget react name)) + +(defn adapt-class [class] + (when class (r/adapt-react-class class))) + +(defn get-class [name] + (adapt-class (get-react-property name))) + +(def app-registry (get-react-property "AppRegistry")) +(def navigator (get-class "Navigator")) +(def text (get-class "Text")) +(def view (get-class "View")) +(def image (get-class "Image")) +(def touchable-highlight-class (get-class "TouchableHighlight")) (defn touchable-highlight [props content] [touchable-highlight-class (merge {:underlay-color :transparent} props) content]) -(def toolbar-android (r/adapt-react-class (.-ToolbarAndroid react))) -(def list-view-class (r/adapt-react-class (.-ListView react))) +(def toolbar-android (get-class "ToolbarAndroid")) +(def list-view-class (get-class "ListView")) (defn list-view [props] [list-view-class (merge {:enableEmptySections true} props)]) -(def scroll-view (r/adapt-react-class (.-ScrollView react))) -(def touchable-without-feedback (r/adapt-react-class (.-TouchableWithoutFeedback react))) -(def text-input-class (r/adapt-react-class (.-TextInput react))) +(def scroll-view (get-class "ScrollView")) +(def touchable-without-feedback (get-class "TouchableWithoutFeedback")) +(def text-input-class (get-class "TextInput")) (defn text-input [props text] [text-input-class (merge {:underlineColorAndroid :transparent @@ -31,11 +41,13 @@ :placeholder "Type"} props) text]) -(def drawer-layout-android (r/adapt-react-class (.-DrawerLayoutAndroid react))) -(def touchable-opacity (r/adapt-react-class (.-TouchableOpacity react))) -(def modal (r/adapt-react-class (.-Modal react))) -(def picker (r/adapt-react-class (.-Picker react))) -(def picker-item (r/adapt-react-class (.-Item (.-Picker react)))) +(def drawer-layout-android (get-class "DrawerLayoutAndroid")) +(def touchable-opacity (get-class "TouchableOpacity")) +(def modal (get-class "Modal")) +(def picker (get-class "Picker")) +(def picker-item + (when-let [picker (get-react-property "Picker")] + (adapt-class (.-Item picker)))) (defn icon @@ -44,20 +56,18 @@ [image {:source {:uri (keyword (str "icon_" (name n)))} :style style}])) -;(def react-linear-gradient (.-default (js/require "react-native-linear-gradient"))) -;(def linear-gradient (r/adapt-react-class react-linear-gradient)) - -(def linear-gradient-class (js/require "react-native-linear-gradient")) +(def linear-gradient-class (u/require "react-native-linear-gradient")) (defn linear-gradient [props] - (r/creacteElement linear-gradient-class + (r/create-element linear-gradient-class (clj->js (merge {:inverted true} props)))) -(def platform (.. react -Platform -OS)) +(def platform + (when-let [pl (.-Platform react)] (.-OS pl))) (def android? (= platform "android")) (defn list-item [component] (r/as-element component)) -(def dismiss-keyboard! (js/require "dismissKeyboard")) +(def dismiss-keyboard! (u/require "dismissKeyboard")) diff --git a/src/status_im/contacts/handlers.cljs b/src/status_im/contacts/handlers.cljs index 268b701815..bbb7fd8b7c 100644 --- a/src/status_im/contacts/handlers.cljs +++ b/src/status_im/contacts/handlers.cljs @@ -26,7 +26,7 @@ (register-handler :load-contacts load-contacts!) ;; TODO see https://github.com/rt2zz/react-native-contacts/issues/45 -(def react-native-contacts (js/require "react-native-contacts")) +(def react-native-contacts #_(js/require "react-native-contacts")) (defn contact-name [contact] (->> contact diff --git a/src/status_im/handlers.cljs b/src/status_im/handlers.cljs index 4010049665..6aa74b5c5f 100644 --- a/src/status_im/handlers.cljs +++ b/src/status_im/handlers.cljs @@ -35,15 +35,19 @@ ;; -- Common -------------------------------------------------------------- +(defn set-el [db [_ k v]] + (assoc db k v)) + (register-handler :set - (debug - (fn [db [_ k v]] - (assoc db k v)))) + debug + set-el) + +(defn set-in [db [_ path v]] + (assoc-in db path v)) (register-handler :set-in - (debug - (fn [db [_ path v]] - (assoc-in db path v)))) + debug + set-in) (register-handler :initialize-db (fn [_ _] diff --git a/src/status_im/i18n.cljs b/src/status_im/i18n.cljs index 4a6157cc23..aff04c97b2 100644 --- a/src/status_im/i18n.cljs +++ b/src/status_im/i18n.cljs @@ -1,12 +1,15 @@ (ns status-im.i18n (:require - [status-im.translations.en :as en])) + [status-im.translations.en :as en] + [status-im.utils.utils :as u])) -(def i18n (js/require "react-native-i18n")) +(def i18n (u/require "react-native-i18n")) (set! (.-fallbacks i18n) true) (set! (.-defaultSeparator i18n) "/") (set! (.-translations i18n) (clj->js {:en en/translations})) (defn label [path & options] - (.t i18n (name path) (clj->js options))) + (if (exists? i18n.t) + (.t i18n (name path) (clj->js options)) + (name path))) diff --git a/src/status_im/persistence/realm.cljs b/src/status_im/persistence/realm.cljs index 7056c11e9d..5d304828fe 100644 --- a/src/status_im/persistence/realm.cljs +++ b/src/status_im/persistence/realm.cljs @@ -2,7 +2,8 @@ (:require [cljs.reader :refer [read-string]] [status-im.components.styles :refer [default-chat-color]] [status-im.utils.logging :as log] - [status-im.utils.types :refer [to-string]]) + [status-im.utils.types :refer [to-string]] + [status-im.utils.utils :as u]) (:refer-clojure :exclude [exists?])) (def opts {:schema [{:name :contacts @@ -68,9 +69,10 @@ :objectType "tag"} :last-updated "date"}}]}) -(def realm-class (js/require "realm")) +(def realm-class (u/require "realm")) -(def realm (realm-class. (clj->js opts))) +(def realm (when (cljs.core/exists? js/window) + (realm-class. (clj->js opts)))) (def schema-by-name (->> (:schema opts) (mapv (fn [{:keys [name] :as schema}] diff --git a/src/status_im/utils/crypt.cljs b/src/status_im/utils/crypt.cljs index 87730efe8c..0b3f2dd7d0 100644 --- a/src/status_im/utils/crypt.cljs +++ b/src/status_im/utils/crypt.cljs @@ -1,9 +1,10 @@ (ns status-im.utils.crypt (:require [goog.crypt :refer [byteArrayToHex]] - [clojure.string :as s]) + [clojure.string :as s] + [status-im.utils.utils :as u]) (:import goog.crypt.Sha256)) -(def random-bytes (js/require "react-native-randombytes")) +(def random-bytes (u/require "react-native-randombytes")) (def sha-256 (Sha256.)) @@ -19,7 +20,7 @@ (byteArrayToHex (.digest sha-256))) (defn gen-random-bytes [length cb] - (.randomBytes random-bytes length (fn [& [err buf]] + #_(.randomBytes random-bytes length (fn [& [err buf]] (if err (cb {:error err}) (cb {:buffer buf}))))) diff --git a/src/status_im/utils/phone_number.cljs b/src/status_im/utils/phone_number.cljs index 137a1c37b5..da0ada6733 100644 --- a/src/status_im/utils/phone_number.cljs +++ b/src/status_im/utils/phone_number.cljs @@ -1,16 +1,17 @@ -(ns status-im.utils.phone-number) +(ns status-im.utils.phone-number + (:require [status-im.utils.utils :as u])) -(def i18n (js/require "react-native-i18n")) -(def locale (.-locale i18n)) +(def i18n (u/require "react-native-i18n")) +(def locale (or (.-locale i18n) "___en")) (def country-code (subs locale 3 5)) -(set! js/PhoneNumber (js/require "awesome-phonenumber")) +(def awesome-phonenumber (u/require "awesome-phonenumber")) ;; todo check wrong numbers, .getNumber returns empty string (defn format-phone-number [number] - (str (.getNumber (js/PhoneNumber. number country-code "international")))) + (str (.getNumber (awesome-phonenumber. number country-code "international")))) (defn valid-mobile-number? [number] (when (string? number) - (let [number-obj (js/PhoneNumber. number country-code "international")] + (let [number-obj (awesome-phonenumber. number country-code "international")] (and (.isValid number-obj) (.isMobile number-obj))))) diff --git a/src/status_im/utils/sms_listener.cljs b/src/status_im/utils/sms_listener.cljs index f00d54b7e9..04204116a2 100644 --- a/src/status_im/utils/sms_listener.cljs +++ b/src/status_im/utils/sms_listener.cljs @@ -1,7 +1,8 @@ (ns status-im.utils.sms-listener - (:require [status-im.components.react :refer [android?]])) + (:require [status-im.components.react :refer [android?]] + [status-im.utils.utils :as u])) -(def sms-listener (.-default (js/require "react-native-android-sms-listener"))) +(def sms-listener (.-default (u/require "react-native-android-sms-listener"))) ;; Only android is supported! diff --git a/src/status_im/utils/utils.cljs b/src/status_im/utils/utils.cljs index 02d54d3f88..c20a6c1e2a 100644 --- a/src/status_im/utils/utils.cljs +++ b/src/status_im/utils/utils.cljs @@ -5,6 +5,11 @@ [natal-shell.toast-android :as toast]) (:require [status-im.constants :as const])) +(defn require [module] + (if (exists? js/window) + (js/require module) + #js {})) + (defn log [obj] (.log js/console obj)) diff --git a/test/status_im/appium.clj b/test/clj/status_im/appium.clj similarity index 100% rename from test/status_im/appium.clj rename to test/clj/status_im/appium.clj diff --git a/test/status_im/console.clj b/test/clj/status_im/console.clj similarity index 100% rename from test/status_im/console.clj rename to test/clj/status_im/console.clj diff --git a/test/cljs/status_im/test/handlers.cljs b/test/cljs/status_im/test/handlers.cljs new file mode 100644 index 0000000000..70f4ae44c6 --- /dev/null +++ b/test/cljs/status_im/test/handlers.cljs @@ -0,0 +1,6 @@ +(ns status-im.test.handlers + (:require [cljs.test :refer-macros [deftest is]] + [status-im.handlers :as h])) + +(deftest test-set-val + (is (= {:key :val} (h/set-el {} [nil :key :val])))) diff --git a/test/cljs/status_im/test/runner.cljs b/test/cljs/status_im/test/runner.cljs new file mode 100644 index 0000000000..14bda7de00 --- /dev/null +++ b/test/cljs/status_im/test/runner.cljs @@ -0,0 +1,5 @@ +(ns status-im.test.runner + (:require [doo.runner :refer-macros [doo-tests]] + [status-im.test.handlers])) + +(doo-tests 'status-im.test.handlers) From eedf38895d593a48843fd0890dcbdd644c1e2238 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Mon, 30 May 2016 10:22:29 +0300 Subject: [PATCH 13/19] doc for appium-test Former-commit-id: c8d0f590c21797dfed5f7deb74e022c65b3d2a2c --- test/clj/status_im/appium.clj | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/test/clj/status_im/appium.clj b/test/clj/status_im/appium.clj index 061ed3f4b4..d3a77bc435 100644 --- a/test/clj/status_im/appium.clj +++ b/test/clj/status_im/appium.clj @@ -59,7 +59,25 @@ (defn quit [driver] (.quit driver)) -(defmacro appium-test [name & body] +(defmacro appium-test + "Defines test which will create new appium session and will pass that + session as first argument to each command inside it's body. After execution + of all commands session will be closed. + + For instance, + + (appium-test my-test + (click :button) + (write :input \"oops\")) + + will be expanded to + + (deftest my-test + (let [session (init)] + (click session :button) + (write session :input \"oops\") + (quit session)))" + [name & body] (let [sym (gensym)] `(deftest ~name (let [~sym (init)] From c4d3436bfcc3e4900f080a83d3d614f6e9eaf339 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Mon, 30 May 2016 11:01:57 +0300 Subject: [PATCH 14/19] move js/React to cljsjs.react.cljs Former-commit-id: f30248e7fea10649bebf2b412ecef12f4920e663 --- src/cljsjs/react.cljs | 5 ++++- src/status_im/components/drawer/view.cljs | 17 +++++++++-------- src/status_im/components/react.cljs | 3 --- src/status_im/profile/screen.cljs | 22 +++++++++++----------- 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/cljsjs/react.cljs b/src/cljsjs/react.cljs index aac9de2f4b..582c4c83e0 100644 --- a/src/cljsjs/react.cljs +++ b/src/cljsjs/react.cljs @@ -1 +1,4 @@ -(ns cljsjs.react) \ No newline at end of file +(ns cljsjs.react) + +(when (exists? js/window) + (set! js/window.React (js/require "react-native"))) diff --git a/src/status_im/components/drawer/view.cljs b/src/status_im/components/drawer/view.cljs index 61b7d698b6..a98fb9d542 100644 --- a/src/status_im/components/drawer/view.cljs +++ b/src/status_im/components/drawer/view.cljs @@ -2,13 +2,14 @@ (:require [clojure.string :as s] [re-frame.core :refer [subscribe dispatch dispatch-sync]] [reagent.core :as r] - [status-im.components.react :as re :refer [view - text - image - navigator - toolbar-android - drawer-layout-android - touchable-opacity]] + [status-im.components.react :refer [react + view + text + image + navigator + toolbar-android + drawer-layout-android + touchable-opacity]] [status-im.resources :as res] [status-im.components.drawer.styles :as st] [status-im.i18n :refer [label]])) @@ -71,7 +72,7 @@ (defn drawer-view [items] [drawer-layout-android {:drawerWidth 260 - :drawerPosition re/react.DrawerLayoutAndroild.positions.Left + :drawerPosition js/React.DrawerLayoutAndroid.positions.Left :render-navigation-view #(r/as-element [drawer-menu]) :ref (fn [drawer] (reset! drawer-atom drawer))} diff --git a/src/status_im/components/react.cljs b/src/status_im/components/react.cljs index 5daccaee88..0ab2d2b755 100644 --- a/src/status_im/components/react.cljs +++ b/src/status_im/components/react.cljs @@ -3,9 +3,6 @@ [status-im.components.styles :as st] [status-im.utils.utils :as u])) -(when (exists? js/window) - (set! js/window.React (js/require "react-native"))) - (def react (u/require "react-native")) (defn get-react-property [name] diff --git a/src/status_im/profile/screen.cljs b/src/status_im/profile/screen.cljs index f2de5dcb41..bb0c52a1d8 100644 --- a/src/status_im/profile/screen.cljs +++ b/src/status_im/profile/screen.cljs @@ -2,14 +2,14 @@ (:require-macros [status-im.utils.views :refer [defview]]) (:require [re-frame.core :refer [subscribe dispatch]] [status-im.components.react :refer [view - text - image - icon - scroll-view - touchable-highlight - touchable-opacity]] + text + image + icon + scroll-view + touchable-highlight + touchable-opacity]] [status-im.components.chat-icon.screen :refer [profile-icon - my-profile-icon]] + my-profile-icon]] [status-im.profile.styles :as st] [status-im.i18n :refer [label]])) @@ -60,11 +60,11 @@ [text {:style st/report-user-text} (label :t/report-user)]]]]]) (defview my-profile [] - [username [:get :username] - photo-path [:get :photo-path] + [username [:get :username] + photo-path [:get :photo-path] phone-number [:get :phone-number] - email [:get :email] - status [:get :status]] + email [:get :email] + status [:get :status]] [scroll-view {:style st/profile} [touchable-highlight {:style st/back-btn-touchable :on-press #(dispatch [:navigate-back])} From 7fbbf8b4aabd9e17e21d88a288ca0811e76fbbfe Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 1 Jun 2016 14:09:43 +0300 Subject: [PATCH 15/19] remove println Former-commit-id: 2bfd90cec410750bd31b9e487cc236192ac8b7ae --- src/status_im/utils/subs.cljs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/status_im/utils/subs.cljs b/src/status_im/utils/subs.cljs index 3be283c37e..60bb24c53b 100644 --- a/src/status_im/utils/subs.cljs +++ b/src/status_im/utils/subs.cljs @@ -5,7 +5,6 @@ "Creates subscrition that cheks if collection (map or set) contains element" [collection] (fn [db [_ element]] - (println "WWWWWWWWWW" (type db)) (-> (collection @db) (contains? element) (reaction)))) From 4d5c5755c6ab4b74c7ed5c5c35d7216404ac0629 Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Wed, 1 Jun 2016 14:44:04 +0300 Subject: [PATCH 16/19] fix translation pluralization Former-commit-id: a46f60c854a6d17d982da3ffdc62ae186a8fa981 --- src/status_im/chat/screen.cljs | 16 ++++++++-------- src/status_im/i18n.cljs | 3 +++ src/status_im/translations/en.cljs | 9 ++++++++- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/status_im/chat/screen.cljs b/src/status_im/chat/screen.cljs index 8c20bb1136..3ff250e238 100644 --- a/src/status_im/chat/screen.cljs +++ b/src/status_im/chat/screen.cljs @@ -3,12 +3,12 @@ (:require [re-frame.core :refer [subscribe dispatch]] [clojure.string :as s] [status-im.components.react :refer [view - text - image - icon - touchable-highlight - list-view - list-item]] + text + image + icon + touchable-highlight + list-view + list-item]] [status-im.components.chat-icon.screen :refer [chat-icon-view-action chat-icon-view-menu-item]] [status-im.chat.styles.screen :as st] @@ -18,7 +18,7 @@ [status-im.components.toolbar :refer [toolbar]] [status-im.chat.views.message :refer [chat-message]] [status-im.chat.views.new-message :refer [chat-message-new]] - [status-im.i18n :refer [label]])) + [status-im.i18n :refer [label label-pluralize]])) (defn contacts-by-identity [contacts] @@ -186,7 +186,7 @@ [icon :group st/group-icon] [text {:style st/members} (let [cnt (inc (count @contacts))] - (label :t/members {:count cnt}))]] + (label-pluralize cnt :t/members))]] ;; TODO stub data: last activity [text {:style st/last-activity} (label :t/last-active)])]))) diff --git a/src/status_im/i18n.cljs b/src/status_im/i18n.cljs index 9abde5c46e..de557041fc 100644 --- a/src/status_im/i18n.cljs +++ b/src/status_im/i18n.cljs @@ -11,6 +11,9 @@ (defn label [path & options] (.t js/I18n (name path) (clj->js options))) +(defn label-pluralize [count path & options] + (.p js/I18n count (name path) (clj->js options))) + (comment (defn deep-merge [& maps] (if (every? map? maps) diff --git a/src/status_im/translations/en.cljs b/src/status_im/translations/en.cljs index be71f9037b..cf3424d440 100644 --- a/src/status_im/translations/en.cljs +++ b/src/status_im/translations/en.cljs @@ -18,7 +18,8 @@ :and-you "and you" :search-chat "Search chat" :members {:one "1 member, 1 active" - :other "{{count}} members, {{count}} active"} + :other "{{count}} members, {{count}} active" + :zero "no members"} :last-active "Active a minute ago" ;profile @@ -70,6 +71,7 @@ ;contacts :contacts "Contacts" :no-name "Noname" + :new-contact "New Contact" ;group-settings :remove "Remove" @@ -112,4 +114,9 @@ :removed "removed" :You "You" + ;new-contact + :import-qr "Import from QR" + :contact-name "Contact Name" + :contact-address "Contact Address" + }) \ No newline at end of file From ce80c8a330f8f496cffb411966d347c0e2d78ecb Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 1 Jun 2016 19:42:38 +0300 Subject: [PATCH 17/19] fix exception at fetching of the contacts Former-commit-id: 084f067ae82eca5576f2fc84450c961b3b75cc2b --- src/status_im/contacts/handlers.cljs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/status_im/contacts/handlers.cljs b/src/status_im/contacts/handlers.cljs index bbb7fd8b7c..b3320db158 100644 --- a/src/status_im/contacts/handlers.cljs +++ b/src/status_im/contacts/handlers.cljs @@ -5,7 +5,8 @@ [clojure.string :as s] [status-im.utils.utils :refer [http-post]] [status-im.utils.phone-number :refer [format-phone-number]] - [status-im.utils.handlers :as u])) + [status-im.utils.handlers :as u] + [status-im.utils.utils :refer [require]])) (defn save-contact [_ [_ contact]] @@ -26,7 +27,7 @@ (register-handler :load-contacts load-contacts!) ;; TODO see https://github.com/rt2zz/react-native-contacts/issues/45 -(def react-native-contacts #_(js/require "react-native-contacts")) +(def react-native-contacts (require "react-native-contacts")) (defn contact-name [contact] (->> contact From ed65ba0ba711714fcb142ddec5c4d6cb582a44fc Mon Sep 17 00:00:00 2001 From: Jarrad Hope Date: Thu, 2 Jun 2016 11:51:44 +0200 Subject: [PATCH 18/19] update run-osx for unit tests and iTerm new release Former-commit-id: 058f470ea7fd00d50de7f6ef20642d5608b44831 --- .re-natal | 2 +- env/dev/env/android/main.cljs | 2 +- run-osx.sh | 13 ++++++++----- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.re-natal b/.re-natal index b4f25ba62a..1455b14c43 100644 --- a/.re-natal +++ b/.re-natal @@ -1,7 +1,7 @@ { "name": "StatusIm", "interface": "reagent", - "androidHost": "10.0.3.2", + "androidHost": "localhost", "modules": [ "react-native-contacts", "react-native-invertible-scroll-view", diff --git a/env/dev/env/android/main.cljs b/env/dev/env/android/main.cljs index f0c3d96fca..1bf474e505 100644 --- a/env/dev/env/android/main.cljs +++ b/env/dev/env/android/main.cljs @@ -10,7 +10,7 @@ (def root-el (r/as-element [reloader])) (figwheel/watch-and-reload - :websocket-url "ws://10.0.3.2:3449/figwheel-ws" + :websocket-url "ws://localhost:3449/figwheel-ws" :heads-up-display false :jsload-callback #(swap! cnt inc)) diff --git a/run-osx.sh b/run-osx.sh index d02de2a3e1..64a86b653f 100755 --- a/run-osx.sh +++ b/run-osx.sh @@ -17,11 +17,13 @@ function tab () { fi osascript &>/dev/null < Date: Thu, 2 Jun 2016 14:23:28 +0300 Subject: [PATCH 19/19] fix contacts loading Former-commit-id: 9ae6e752d894170d65e8d8da813c5386796a3fe8 --- src/status_im/chat/handlers.cljs | 6 +++--- src/status_im/components/chat_icon/screen.cljs | 11 ++++++----- src/status_im/contacts/handlers.cljs | 10 +++++++--- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 011749f25f..0d0af3a2f3 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -230,9 +230,9 @@ (sign-up-service/stop-listening-confirmation-code-sms db))) (register-handler :sign-up-confirm - (fn [db [_ confirmation-code]] - (server/sign-up-confirm confirmation-code sign-up-service/on-send-code-response) - db)) + (u/side-effect! + (fn [_ [_ confirmation-code]] + (server/sign-up-confirm confirmation-code sign-up-service/on-send-code-response)))) (register-handler :set-signed-up (fn [db [_ signed-up]] diff --git a/src/status_im/components/chat_icon/screen.cljs b/src/status_im/components/chat_icon/screen.cljs index e44d334e33..0d93e38cbb 100644 --- a/src/status_im/components/chat_icon/screen.cljs +++ b/src/status_im/components/chat_icon/screen.cljs @@ -6,7 +6,8 @@ image icon]] [status-im.components.chat-icon.styles :as st] - [status-im.components.styles :refer [color-purple]])) + [status-im.components.styles :refer [color-purple]] + [clojure.string :as s])) (defn default-chat-icon [name styles] [view (:default-chat-icon styles) @@ -26,10 +27,10 @@ (defview chat-icon-view [chat-id group-chat name online styles] [photo-path [:chat-photo chat-id]] [view (:container styles) - (if (and photo-path (not (empty? photo-path))) + (if-not (s/blank? photo-path) [chat-icon photo-path styles] [default-chat-icon name styles]) - (when (not group-chat) + (when-not group-chat [contact-online online styles])]) (defn chat-icon-view-chat-list [chat-id group-chat name color online] @@ -80,7 +81,7 @@ [contact [:contact]] (let [;; TODO stub data online true - color color-purple] + color color-purple] [profile-icon-view (:photo-path contact) (:name contact) color online])) (defview my-profile-icon [] @@ -88,5 +89,5 @@ photo-path [:get :photo-path]] (let [;; TODO stub data online true - color color-purple] + color color-purple] [profile-icon-view photo-path name color online])) diff --git a/src/status_im/contacts/handlers.cljs b/src/status_im/contacts/handlers.cljs index b3320db158..acb9be9b6c 100644 --- a/src/status_im/contacts/handlers.cljs +++ b/src/status_im/contacts/handlers.cljs @@ -92,10 +92,14 @@ (defn add-new-contacts [{:keys [contacts] :as db} [_ new-contacts]] (let [identities (set (map :whisper-identity contacts)) - new-contacts' (remove #(identities (:whisper-identity %)) new-contacts)] + new-contacts' (->> new-contacts + (remove #(identities (:whisper-identity %))) + (map #(vector (:whisper-identity %) %)) + (into {}))] + (println new-contacts') (-> db - (update :contacts concat new-contacts') - (assoc :new-contacts new-contacts')))) + (update :contacts merge new-contacts') + (assoc :new-contacts (vals new-contacts'))))) (register-handler :add-contacts (after save-contacts!)