diff --git a/src/status_im/notifications_center/core.cljs b/src/status_im/notifications_center/core.cljs index a026045beb3..20a89e9b9dc 100644 --- a/src/status_im/notifications_center/core.cljs +++ b/src/status_im/notifications_center/core.cljs @@ -61,8 +61,7 @@ (fx/defn ensure-and-open-chat {:events [:ensure-and-open-chat]} [{:keys [db]} response-js] - {:db (update db :activity.center/notifications dissoc :cursor) - :dispatch-n [[:sanitize-messages-and-process-response response-js] + {:dispatch-n [[:sanitize-messages-and-process-response response-js] [:chat.ui/navigate-to-chat (.-id (aget (.-chats response-js) 0))]]}) (fx/defn dismiss-all-activity-center-notifications @@ -93,20 +92,43 @@ :on-success #() :on-error #()}]}) +(fx/defn load-notifications [{:keys [db]} cursor] + (when-not (:activity.center/loading? db) + {:db (assoc db :activity.center/loading? true) + ::json-rpc/call [{:method (json-rpc/call-ext-method "activityCenterNotifications") + :params [cursor 20] + :on-success #(re-frame/dispatch [:activity-center-notifications-success %]) + :on-error #(re-frame/dispatch [:activity-center-notifications-error %])}]})) + +(fx/defn clean-notifications [{:keys [db]}] + {:db (dissoc db :activity.center/notifications)}) + (fx/defn get-activity-center-notifications {:events [:get-activity-center-notifications]} - [{:keys [db]}] + [{:keys [db] :as cofx}] + (let [{:keys [cursor]} (:activity.center/notifications db)] + (fx/merge cofx + (clean-notifications) + (load-notifications "")))) + +(fx/defn load-more-activity-center-notifications + {:events [:load-more-activity-center-notifications]} + [{:keys [db] :as cofx}] (let [{:keys [cursor]} (:activity.center/notifications db)] (when (not= cursor "") - {::json-rpc/call [{:method (json-rpc/call-ext-method "activityCenterNotifications") - :params [cursor 20] - :on-success #(re-frame/dispatch [:activity-center-notifications-success %]) - :on-error #(log/warn "failed to get notification center activities" %)}]}))) + (load-notifications cofx cursor)))) + +(fx/defn activity-center-notifications-error + {:events [:activity-center-notifications-error]} + [{:keys [db]} error] + (log/warn "failed to load activity center notifications" error) + {:db (dissoc db :activity.center/loading?)}) (fx/defn activity-center-notifications-success {:events [:activity-center-notifications-success]} [{:keys [db]} {:keys [cursor notifications]}] {:db (-> db + (dissoc :activity.center/loading?) (assoc-in [:activity.center/notifications :cursor] cursor) (update-in [:activity.center/notifications :notifications] concat @@ -114,5 +136,5 @@ (fx/defn close-center {:events [:close-notifications-center]} - [{:keys [db]}] - {:db (dissoc db :activity.center/notifications)}) + [cofx] + (clean-notifications cofx)) diff --git a/src/status_im/ui/screens/home/views.cljs b/src/status_im/ui/screens/home/views.cljs index 1f47c17b551..c8f23ded621 100644 --- a/src/status_im/ui/screens/home/views.cljs +++ b/src/status_im/ui/screens/home/views.cljs @@ -213,7 +213,6 @@ :style {:margin-left 10} :accessibility-label "notifications-button" :on-press #(do - (re-frame/dispatch [:get-activity-center-notifications]) (re-frame/dispatch [:mark-all-activity-center-notifications-as-read]) (re-frame/dispatch [:navigate-to :notifications-center])) :theme :icon} diff --git a/src/status_im/ui/screens/notifications_center/views.cljs b/src/status_im/ui/screens/notifications_center/views.cljs index 9d8b0487acd..d34ae3fb124 100644 --- a/src/status_im/ui/screens/notifications_center/views.cljs +++ b/src/status_im/ui/screens/notifications_center/views.cljs @@ -74,27 +74,31 @@ (reset-state)) (defn center [] - (let [{:keys [notifications]} @(re-frame/subscribe [:activity.center/notifications])] - [react/keyboard-avoiding-view {:style {:flex 1}} - [topbar/topbar {:navigation {:on-press #(do - (reset-state) - (re-frame/dispatch [:close-notifications-center]) - (re-frame/dispatch [:navigate-back]))} - :title (i18n/label :t/activity)}] - [filter-item] - [list/flat-list - {:key-fn #(or (:chat-id %) (:id %)) - :on-end-reached #(re-frame/dispatch [:get-activity-center-notifications]) - :keyboard-should-persist-taps :always - :data notifications - :render-fn render-fn}] - (when (or @select-all (> (count @selected-items) 0)) - [toolbar/toolbar - {:show-border? true - :left [quo/button {:type :secondary - :theme :negative - :on-press #(toolbar-action false)} - (i18n/label :t/reject-and-delete)] - :right [quo/button {:type :secondary - :on-press #(toolbar-action true)} - (i18n/label :t/accept-and-add)]}])])) \ No newline at end of file + (reagent/create-class + {:display-name "activity-center" + :component-did-mount #(re-frame/dispatch [:get-activity-center-notifications]) + :reagent-render (fn [] + (let [{:keys [notifications]} @(re-frame/subscribe [:activity.center/notifications])] + [react/keyboard-avoiding-view {:style {:flex 1}} + [topbar/topbar {:navigation {:on-press #(do + (reset-state) + (re-frame/dispatch [:close-notifications-center]) + (re-frame/dispatch [:navigate-back]))} + :title (i18n/label :t/activity)}] + [filter-item] + [list/flat-list + {:key-fn #(or (:chat-id %) (:id %)) + :on-end-reached #(re-frame/dispatch [:load-more-activity-center-notifications]) + :keyboard-should-persist-taps :always + :data notifications + :render-fn render-fn}] + (when (or @select-all (> (count @selected-items) 0)) + [toolbar/toolbar + {:show-border? true + :left [quo/button {:type :secondary + :theme :negative + :on-press #(toolbar-action false)} + (i18n/label :t/reject-and-delete)] + :right [quo/button {:type :secondary + :on-press #(toolbar-action true)} + (i18n/label :t/accept-and-add)]}])]))}))