-
Notifications
You must be signed in to change notification settings - Fork 984
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
5 changed files
with
185 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
(ns status-im.activity-center.core | ||
(:require [re-frame.core :as re-frame] | ||
[status-im.data-store.activities :as data-store.activities] | ||
[status-im.ethereum.json-rpc :as json-rpc] | ||
[status-im.utils.fx :as fx] | ||
[taoensso.timbre :as log])) | ||
|
||
(def notifications-per-page | ||
20) | ||
|
||
(def start-or-end-cursor | ||
"") | ||
|
||
(defn notifications-group->rpc-method | ||
[notifications-group] | ||
(if (= notifications-group :notifications-read) | ||
"wakuext_readActivityCenterNotifications" | ||
"wakuext_unreadActivityCenterNotifications")) | ||
|
||
(defn notifications-read-status->group | ||
[status-filter] | ||
(if (= status-filter :read) | ||
:notifications-read | ||
:notifications-unread)) | ||
|
||
(fx/defn notifications-fetch | ||
[{:keys [db]} cursor notifications-group] | ||
(when-not (get-in db [:activity-center notifications-group :loading?]) | ||
{:db (assoc-in db [:activity-center notifications-group :loading?] true) | ||
::json-rpc/call [{:method (notifications-group->rpc-method notifications-group) | ||
:params [cursor notifications-per-page] | ||
:on-success #(re-frame/dispatch [:activity-center/notifications-fetch-success notifications-group %]) | ||
:on-error #(re-frame/dispatch [:activity-center/notifications-fetch-error notifications-group %])}]})) | ||
|
||
(fx/defn notifications-fetch-first-page | ||
{:events [:activity-center/notifications-fetch-first-page]} | ||
[{:keys [db] :as cofx} {:keys [status-filter] :or {status-filter :unread}}] | ||
(let [notifications-group (notifications-read-status->group status-filter)] | ||
(fx/merge cofx | ||
{:db (-> db | ||
(assoc-in [:activity-center :current-status-filter] status-filter) | ||
(update-in [:activity-center notifications-group] dissoc :loading?) | ||
(update-in [:activity-center notifications-group] dissoc :data))} | ||
(notifications-fetch start-or-end-cursor notifications-group)))) | ||
|
||
(fx/defn notifications-fetch-next-page | ||
{:events [:activity-center/notifications-fetch-next-page]} | ||
[{:keys [db] :as cofx}] | ||
(let [status-filter (get-in db [:activity-center :current-status-filter]) | ||
notifications-group (notifications-read-status->group status-filter) | ||
{:keys [cursor]} (get-in db [:activity-center notifications-group])] | ||
(when-not (= cursor start-or-end-cursor) | ||
(notifications-fetch cofx cursor notifications-group)))) | ||
|
||
(fx/defn notifications-fetch-success | ||
{:events [:activity-center/notifications-fetch-success]} | ||
[{:keys [db]} notifications-group {:keys [cursor notifications]}] | ||
{:db (-> db | ||
(update-in [:activity-center notifications-group] dissoc :loading?) | ||
(assoc-in [:activity-center notifications-group :cursor] cursor) | ||
(update-in [:activity-center notifications-group :data] | ||
concat | ||
(map data-store.activities/<-rpc notifications)))}) | ||
|
||
(fx/defn notifications-fetch-error | ||
{:events [:activity-center/notifications-fetch-error]} | ||
[{:keys [db]} notifications-group error] | ||
(log/warn "Failed to load Activity Center notifications" error) | ||
{:db (update-in db [:activity-center notifications-group] dissoc :loading?)}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
(ns status-im.ui.screens.activity-center.views | ||
(:require [quo.react-native :as rn] | ||
[quo2.components.buttons.button :as button] | ||
[quo2.components.notifications.activity-logs :as activity-logs] | ||
[quo2.components.tags.context-tags :as context-tags] | ||
[quo2.foundations.colors :as colors] | ||
[reagent.core :as reagent] | ||
[status-im.i18n.i18n :as i18n] | ||
[status-im.ui.components.topbar :as topbar] | ||
[status-im.utils.handlers :refer [<sub >evt]])) | ||
|
||
(defn render-notification | ||
[notification index] | ||
[rn/view {:flex 1 | ||
:flex-direction :column | ||
:margin-top (if (= 0 index) 0 4)} | ||
[activity-logs/activity-log {:context [[context-tags/group-avatar-tag "Name" {:color :purple | ||
:override-theme :dark | ||
:size :small | ||
:style {:background-color colors/white-opa-10} | ||
:text-style {:color colors/white}}] | ||
[rn/text {:style {:color colors/white}} "did something here."]] | ||
:icon :placeholder | ||
:message {:body (get-in notification [:message :content :text])} | ||
:timestamp (:timestamp notification) | ||
:title "Activity Title" | ||
:unread? (not (:read notification))}]]) | ||
|
||
(defn notifications-list | ||
[] | ||
(let [notifications (<sub [:activity-center/notifications-per-read-status])] | ||
[rn/flat-list {:style {:padding-horizontal 8} | ||
:data notifications | ||
:key-fn :id | ||
:on-end-reached #(>evt [:activity-center/notifications-fetch-next-page]) | ||
:render-fn render-notification}])) | ||
|
||
(defn activity-center [] | ||
(reagent/create-class | ||
{:component-did-mount #(>evt [:activity-center/notifications-fetch-first-page {:status-filter :unread}]) | ||
:reagent-render | ||
(fn [] | ||
[:<> | ||
[topbar/topbar {:navigation {:on-press #(>evt [:navigate-back])} | ||
:title (i18n/label :t/activity)}] | ||
;; TODO(ilmotta): Temporary solution to switch between read/unread | ||
;; notifications while the Design team works on the mockups. | ||
[button/button {:on-press #(>evt [:activity-center/notifications-fetch-first-page {:status-filter :unread}])} | ||
"Unread"] | ||
[button/button {:on-press #(>evt [:activity-center/notifications-fetch-first-page {:status-filter :read}])} | ||
"Read"] | ||
[notifications-list]])})) |
Oops, something went wrong.