diff --git a/src/status_im/communities/core.cljs b/src/status_im/communities/core.cljs index 62470b09e4..9a55f7d4b3 100644 --- a/src/status_im/communities/core.cljs +++ b/src/status_im/communities/core.cljs @@ -4,6 +4,7 @@ [clojure.walk :as walk] [quo.design-system.colors :as colors] [re-frame.core :as re-frame] + [i18n.i18n :as i18n] [status-im.async-storage.core :as async-storage] [status-im.bottom-sheet.core :as bottom-sheet] [status-im.constants :as constants] @@ -11,6 +12,7 @@ [utils.re-frame :as rf] [status-im.utils.universal-links.core :as universal-links] [status-im2.contexts.activity-center.events :as activity-center] + [status-im2.common.toasts.events :as toasts] [status-im2.navigation.events :as navigation] [taoensso.timbre :as log])) @@ -110,15 +112,28 @@ (rf/defn left {:events [::left]} [cofx response-js] - (rf/merge cofx - (handle-response cofx response-js) - (navigation/pop-to-root-tab :chat-stack) - (activity-center/notifications-fetch-unread-count))) + (let [community-name (aget response-js "communities" 0 "name")] + (rf/merge cofx + (handle-response cofx response-js) + (toasts/upsert {:icon :placeholder + :icon-color (:positive-01 @colors/theme) + :text (i18n/label :t/left-community {:community community-name})}) + (navigation/navigate-back) + (activity-center/notifications-fetch-unread-count)))) (rf/defn joined {:events [::joined ::requested-to-join]} [cofx response-js] - (handle-response cofx response-js)) + (let [[event-name _] (:event cofx) + community-name (aget response-js "communities" 0 "name")] + (rf/merge cofx + (handle-response cofx response-js) + (toasts/upsert {:icon :placeholder + :icon-color (:positive-01 @colors/theme) + :text (i18n/label (if (= event-name ::joined) + :t/joined-community + :t/requested-to-join-community) + {:community community-name})})))) (rf/defn export {:events [::export-pressed]} diff --git a/src/status_im2/common/toasts/events.cljs b/src/status_im2/common/toasts/events.cljs index 0d73f0f46b..f1b5ed485b 100644 --- a/src/status_im2/common/toasts/events.cljs +++ b/src/status_im2/common/toasts/events.cljs @@ -3,25 +3,25 @@ (rf/defn upsert {:events [:toasts/upsert]} - [{:keys [db]} id opts] - (let [{:keys [ordered toasts]} (:toasts db) - update? (some #(= % id) ordered) - ordered (if (not update?) (conj ordered id) ordered) - toasts (assoc toasts id opts) - db (-> db - (update :toasts assoc :ordered ordered :toasts toasts) - (update :toasts dissoc :hide-toasts-timer-set))] - (if (and (not update?) (= (count ordered) 1)) - {:show-toasts [] - :db db} - {:db db}))) - -(rf/defn create - {:events [:toasts/create]} [{:keys [db]} opts] - (let [next-toast-id (or (get-in [:toasts :next-toast-id] db) 1)] - {:db (assoc-in db [:toasts :next-toast-id] (inc next-toast-id)) - :dispatch [:toasts/upsert (str "toast-" next-toast-id) opts]})) + (let [{:keys [ordered toasts]} (:toasts db) + next-toast-number (get-in db [:toasts :next-toast-number] 1) + id (or (:id opts) + (str "toast-" next-toast-number)) + update? (some #(= % id) ordered) + ordered (if (not update?) + (conj ordered id) + ordered) + toasts (assoc toasts id (dissoc opts :id))] + (cond-> {:db (-> db + (update :toasts assoc :ordered ordered :toasts toasts) + (update :toasts dissoc :hide-toasts-timer-set))} + + (and (not update?) (= (count ordered) 1)) + (assoc :show-toasts []) + + (not (:id opts)) + (update-in [:db :toasts :next-toast-number] inc)))) (rf/defn hide-toasts-with-check {:events [:toasts/hide-with-check]} diff --git a/src/status_im2/contexts/chat/messages/delete_message/events.cljs b/src/status_im2/contexts/chat/messages/delete_message/events.cljs index bd8f2ffc7b..af735b0e18 100644 --- a/src/status_im2/contexts/chat/messages/delete_message/events.cljs +++ b/src/status_im2/contexts/chat/messages/delete_message/events.cljs @@ -71,8 +71,9 @@ :dispatch-n [[:toasts/close :delete-message-for-everyone] - [:toasts/upsert :delete-message-for-everyone - {:icon :info + [:toasts/upsert + {:id :delete-message-for-everyone + :icon :info :icon-color colors/danger-50-opa-40 :message-deleted-for-everyone-count toast-count :message-deleted-for-everyone-undos existing-undos diff --git a/src/status_im2/contexts/chat/messages/delete_message_for_me/events.cljs b/src/status_im2/contexts/chat/messages/delete_message_for_me/events.cljs index 1c48646c15..754a9d6400 100644 --- a/src/status_im2/contexts/chat/messages/delete_message_for_me/events.cljs +++ b/src/status_im2/contexts/chat/messages/delete_message_for_me/events.cljs @@ -60,8 +60,9 @@ existing-undos)} chat-id) :dispatch-n [[:toasts/close :delete-message-for-me] - [:toasts/upsert :delete-message-for-me - {:icon :info + [:toasts/upsert + {:id :delete-message-for-me + :icon :info :icon-color colors/danger-50-opa-40 :message-deleted-for-me-count toast-count :message-deleted-for-me-undos existing-undos diff --git a/src/status_im2/contexts/quo_preview/notifications/toast.cljs b/src/status_im2/contexts/quo_preview/notifications/toast.cljs index 4765117c19..306ce5cd50 100644 --- a/src/status_im2/contexts/quo_preview/notifications/toast.cljs +++ b/src/status_im2/contexts/quo_preview/notifications/toast.cljs @@ -10,7 +10,7 @@ ([text id opts] (let [toast-opts (rf/sub [:toasts/toast id]) dismiss! #(rf/dispatch [:toasts/close id]) - toast! #(rf/dispatch [:toasts/upsert id opts]) + toast! #(rf/dispatch [:toasts/upsert (assoc opts :id id)]) dismissed? (not toast-opts)] [rn/view {:style {:margin-bottom 10}} [button/button @@ -34,7 +34,7 @@ :duration 4000 :undo-duration 4 :undo-on-press #(do - (rf/dispatch [:toasts/create + (rf/dispatch [:toasts/upsert {:icon :placeholder :icon-color "green" :text "Undo pressed"}]) @@ -53,7 +53,7 @@ :undo-on-press #(do (rf/dispatch - [:toasts/create + [:toasts/upsert {:icon :placeholder :icon-color "green" :text "Undo pressed"}]) (rf/dispatch [:toasts/close "Toast: with undo action"]))}]) @@ -78,8 +78,8 @@ :on-press #(rf/dispatch [:toasts/upsert - "Toast: 30s duration" - {:icon :placeholder + {:id "Toast: 30s duration" + :icon :placeholder :icon-color "red" :text (str "This is an updated example toast" " - " (swap! suffix inc)) :duration 3000}])} diff --git a/translations/en.json b/translations/en.json index 566b57826f..d53e6917cb 100644 --- a/translations/en.json +++ b/translations/en.json @@ -702,6 +702,7 @@ "join-me": "Hey join me on Status: {{url}}", "join-a-community": "or join a community", "join-open-community": "Join Community", + "joined-community": "You joined “{{community}}”", "http-gateway-error": "Oops, request failed!", "sign-request-failed": "Could not sign message", "invite-friends": "Invite friends", @@ -819,6 +820,7 @@ "leave": "Leave", "leave-community?": "Leave community?", "leave-community-message": "We’ll be sad to see you go but remember, you can come back at any time!", + "left-community": "You left “{{community}}”", "joined": "Joined", "leave-group": "Leave group", "left": "left", @@ -1136,6 +1138,7 @@ "request-processed-after-node-online": "Your request will be processed once the community owner node is back online.", "request-to-join": "Request to join", "request-to-join-community": "Request to join Community", + "requested-to-join-community": "You requested to join “{{community}}”", "request-transaction": "Request transaction", "required-field": "Required field", "resend-message": "Resend",