mirror of
https://github.com/status-im/status-react.git
synced 2025-01-23 01:09:49 +00:00
Communities join screens - add toast after joining/leaving (#14735)
* Add toast after joining/leaving a community * leftover removal * Better code for adding toasts * Fixes * Lint fix
This commit is contained in:
parent
55d11d1a18
commit
43da198c3f
@ -4,6 +4,7 @@
|
|||||||
[clojure.walk :as walk]
|
[clojure.walk :as walk]
|
||||||
[quo.design-system.colors :as colors]
|
[quo.design-system.colors :as colors]
|
||||||
[re-frame.core :as re-frame]
|
[re-frame.core :as re-frame]
|
||||||
|
[i18n.i18n :as i18n]
|
||||||
[status-im.async-storage.core :as async-storage]
|
[status-im.async-storage.core :as async-storage]
|
||||||
[status-im.bottom-sheet.core :as bottom-sheet]
|
[status-im.bottom-sheet.core :as bottom-sheet]
|
||||||
[status-im.constants :as constants]
|
[status-im.constants :as constants]
|
||||||
@ -11,6 +12,7 @@
|
|||||||
[utils.re-frame :as rf]
|
[utils.re-frame :as rf]
|
||||||
[status-im.utils.universal-links.core :as universal-links]
|
[status-im.utils.universal-links.core :as universal-links]
|
||||||
[status-im2.contexts.activity-center.events :as activity-center]
|
[status-im2.contexts.activity-center.events :as activity-center]
|
||||||
|
[status-im2.common.toasts.events :as toasts]
|
||||||
[status-im2.navigation.events :as navigation]
|
[status-im2.navigation.events :as navigation]
|
||||||
[taoensso.timbre :as log]))
|
[taoensso.timbre :as log]))
|
||||||
|
|
||||||
@ -110,15 +112,28 @@
|
|||||||
(rf/defn left
|
(rf/defn left
|
||||||
{:events [::left]}
|
{:events [::left]}
|
||||||
[cofx response-js]
|
[cofx response-js]
|
||||||
(rf/merge cofx
|
(let [community-name (aget response-js "communities" 0 "name")]
|
||||||
(handle-response cofx response-js)
|
(rf/merge cofx
|
||||||
(navigation/pop-to-root-tab :chat-stack)
|
(handle-response cofx response-js)
|
||||||
(activity-center/notifications-fetch-unread-count)))
|
(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
|
(rf/defn joined
|
||||||
{:events [::joined ::requested-to-join]}
|
{:events [::joined ::requested-to-join]}
|
||||||
[cofx response-js]
|
[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
|
(rf/defn export
|
||||||
{:events [::export-pressed]}
|
{:events [::export-pressed]}
|
||||||
|
@ -3,25 +3,25 @@
|
|||||||
|
|
||||||
(rf/defn upsert
|
(rf/defn upsert
|
||||||
{:events [:toasts/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]
|
[{:keys [db]} opts]
|
||||||
(let [next-toast-id (or (get-in [:toasts :next-toast-id] db) 1)]
|
(let [{:keys [ordered toasts]} (:toasts db)
|
||||||
{:db (assoc-in db [:toasts :next-toast-id] (inc next-toast-id))
|
next-toast-number (get-in db [:toasts :next-toast-number] 1)
|
||||||
:dispatch [:toasts/upsert (str "toast-" next-toast-id) opts]}))
|
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
|
(rf/defn hide-toasts-with-check
|
||||||
{:events [:toasts/hide-with-check]}
|
{:events [:toasts/hide-with-check]}
|
||||||
|
@ -71,8 +71,9 @@
|
|||||||
|
|
||||||
:dispatch-n
|
:dispatch-n
|
||||||
[[:toasts/close :delete-message-for-everyone]
|
[[:toasts/close :delete-message-for-everyone]
|
||||||
[:toasts/upsert :delete-message-for-everyone
|
[:toasts/upsert
|
||||||
{:icon :info
|
{:id :delete-message-for-everyone
|
||||||
|
:icon :info
|
||||||
:icon-color colors/danger-50-opa-40
|
:icon-color colors/danger-50-opa-40
|
||||||
:message-deleted-for-everyone-count toast-count
|
:message-deleted-for-everyone-count toast-count
|
||||||
:message-deleted-for-everyone-undos existing-undos
|
:message-deleted-for-everyone-undos existing-undos
|
||||||
|
@ -60,8 +60,9 @@
|
|||||||
existing-undos)}
|
existing-undos)}
|
||||||
chat-id)
|
chat-id)
|
||||||
:dispatch-n [[:toasts/close :delete-message-for-me]
|
:dispatch-n [[:toasts/close :delete-message-for-me]
|
||||||
[:toasts/upsert :delete-message-for-me
|
[:toasts/upsert
|
||||||
{:icon :info
|
{:id :delete-message-for-me
|
||||||
|
:icon :info
|
||||||
:icon-color colors/danger-50-opa-40
|
:icon-color colors/danger-50-opa-40
|
||||||
:message-deleted-for-me-count toast-count
|
:message-deleted-for-me-count toast-count
|
||||||
:message-deleted-for-me-undos existing-undos
|
:message-deleted-for-me-undos existing-undos
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
([text id opts]
|
([text id opts]
|
||||||
(let [toast-opts (rf/sub [:toasts/toast id])
|
(let [toast-opts (rf/sub [:toasts/toast id])
|
||||||
dismiss! #(rf/dispatch [:toasts/close 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)]
|
dismissed? (not toast-opts)]
|
||||||
[rn/view {:style {:margin-bottom 10}}
|
[rn/view {:style {:margin-bottom 10}}
|
||||||
[button/button
|
[button/button
|
||||||
@ -34,7 +34,7 @@
|
|||||||
:duration 4000
|
:duration 4000
|
||||||
:undo-duration 4
|
:undo-duration 4
|
||||||
:undo-on-press #(do
|
:undo-on-press #(do
|
||||||
(rf/dispatch [:toasts/create
|
(rf/dispatch [:toasts/upsert
|
||||||
{:icon :placeholder
|
{:icon :placeholder
|
||||||
:icon-color "green"
|
:icon-color "green"
|
||||||
:text "Undo pressed"}])
|
:text "Undo pressed"}])
|
||||||
@ -53,7 +53,7 @@
|
|||||||
:undo-on-press
|
:undo-on-press
|
||||||
#(do
|
#(do
|
||||||
(rf/dispatch
|
(rf/dispatch
|
||||||
[:toasts/create
|
[:toasts/upsert
|
||||||
{:icon :placeholder :icon-color "green" :text "Undo pressed"}])
|
{:icon :placeholder :icon-color "green" :text "Undo pressed"}])
|
||||||
(rf/dispatch [:toasts/close "Toast: with undo action"]))}])
|
(rf/dispatch [:toasts/close "Toast: with undo action"]))}])
|
||||||
|
|
||||||
@ -78,8 +78,8 @@
|
|||||||
:on-press
|
:on-press
|
||||||
#(rf/dispatch
|
#(rf/dispatch
|
||||||
[:toasts/upsert
|
[:toasts/upsert
|
||||||
"Toast: 30s duration"
|
{:id "Toast: 30s duration"
|
||||||
{:icon :placeholder
|
:icon :placeholder
|
||||||
:icon-color "red"
|
:icon-color "red"
|
||||||
:text (str "This is an updated example toast" " - " (swap! suffix inc))
|
:text (str "This is an updated example toast" " - " (swap! suffix inc))
|
||||||
:duration 3000}])}
|
:duration 3000}])}
|
||||||
|
@ -702,6 +702,7 @@
|
|||||||
"join-me": "Hey join me on Status: {{url}}",
|
"join-me": "Hey join me on Status: {{url}}",
|
||||||
"join-a-community": "or join a community",
|
"join-a-community": "or join a community",
|
||||||
"join-open-community": "Join Community",
|
"join-open-community": "Join Community",
|
||||||
|
"joined-community": "You joined “{{community}}”",
|
||||||
"http-gateway-error": "Oops, request failed!",
|
"http-gateway-error": "Oops, request failed!",
|
||||||
"sign-request-failed": "Could not sign message",
|
"sign-request-failed": "Could not sign message",
|
||||||
"invite-friends": "Invite friends",
|
"invite-friends": "Invite friends",
|
||||||
@ -819,6 +820,7 @@
|
|||||||
"leave": "Leave",
|
"leave": "Leave",
|
||||||
"leave-community?": "Leave community?",
|
"leave-community?": "Leave community?",
|
||||||
"leave-community-message": "We’ll be sad to see you go but remember, you can come back at any time!",
|
"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",
|
"joined": "Joined",
|
||||||
"leave-group": "Leave group",
|
"leave-group": "Leave group",
|
||||||
"left": "left",
|
"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-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": "Request to join",
|
||||||
"request-to-join-community": "Request to join Community",
|
"request-to-join-community": "Request to join Community",
|
||||||
|
"requested-to-join-community": "You requested to join “{{community}}”",
|
||||||
"request-transaction": "Request transaction",
|
"request-transaction": "Request transaction",
|
||||||
"required-field": "Required field",
|
"required-field": "Required field",
|
||||||
"resend-message": "Resend",
|
"resend-message": "Resend",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user