Move Activity Center to new app structure (#14554)

This commit is contained in:
Icaro Motta 2022-12-16 10:45:00 -03:00 committed by GitHub
parent fc07fbf787
commit 269d13e2f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
32 changed files with 300 additions and 303 deletions

View File

@ -7,7 +7,7 @@
(defn consumer [component]
[consumer-raw
(fn [insets]
(fn [^js insets]
(reagent/as-element
[component (js->clj insets :keywordize-keys true)]))])

View File

@ -7,7 +7,7 @@
[status-im.chat.models.message-list :as message-list]
[taoensso.timbre :as log]
[status-im.ethereum.json-rpc :as json-rpc]
[status-im.activity-center.core :as activity-center]))
[status-im2.contexts.activity-center.events :as activity-center]))
(defn cursor->clock-value
[^js cursor]

View File

@ -15,7 +15,7 @@
[status-im2.navigation.events :as navigation]
[status-im.utils.handlers :refer [>evt]]
[status-im.ui.components.emoji-thumbnail.styles :as emoji-thumbnail-styles]
[status-im.activity-center.core :as activity-center]))
[status-im2.contexts.activity-center.events :as activity-center]))
(def crop-size 1000)

View File

@ -6,7 +6,7 @@
[status-im.data-store.contacts :as contacts-store]
[status-im2.navigation.events :as navigation]
[status-im.utils.types :as types]
[status-im.activity-center.core :as activity-center]
[status-im2.contexts.activity-center.events :as activity-center]
[status-im.utils.fx :as fx]))
(fx/defn clean-up-chat

View File

@ -1,7 +1,7 @@
(ns status-im.data-store.activities
(:require [clojure.set :as set]
[status-im.constants :as constants]
[status-im.activity-center.notification-types :as notification-types]
[status-im2.contexts.activity-center.notification-types :as notification-types]
[status-im.data-store.messages :as messages]))
(defn- rpc->type [{:keys [type name] :as chat}]

View File

@ -1,7 +1,7 @@
(ns status-im.data-store.activities-test
(:require [cljs.test :refer [deftest is testing]]
[status-im.constants :as constants]
[status-im.activity-center.notification-types :as notification-types]
[status-im2.contexts.activity-center.notification-types :as notification-types]
[status-im.data-store.activities :as store]))
(def chat-id

View File

@ -32,7 +32,7 @@
status-im.multiaccounts.update.core
[status-im.native-module.core :as status]
[status-im2.navigation.events :as navigation]
status-im.activity-center.core
status-im2.contexts.activity-center.events
status-im.pairing.core
status-im.profile.core
status-im.search.core

View File

@ -9,7 +9,7 @@
[status-im.utils.fx :as fx]
[status-im.constants :as constants]
[status-im.i18n.i18n :as i18n]
[status-im.activity-center.core :as activity-center]))
[status-im2.contexts.activity-center.events :as activity-center]))
(fx/defn navigate-chat-updated
{:events [:navigate-chat-updated]}

View File

@ -32,7 +32,7 @@
[status-im.chat.models.link-preview :as link-preview]
[status-im.utils.mobile-sync :as utils.mobile-sync]
[status-im.async-storage.core :as async-storage]
[status-im.activity-center.core :as activity-center]
[status-im2.contexts.activity-center.events :as activity-center]
[status-im2.navigation.events :as navigation]
[status-im.signing.eip1559 :as eip1559]
[status-im.data-store.chats :as data-store.chats]

View File

@ -1,6 +1,6 @@
(ns ^{:doc "Definition of the StatusMessage protocol"}
status-im.transport.message.core
(:require [status-im.activity-center.core :as activity-center]
(:require [status-im2.contexts.activity-center.events :as activity-center]
[status-im.chat.models.message :as models.message]
[status-im2.contexts.chat.messages.pin.events :as messages.pin]
[status-im.chat.models :as models.chat]

View File

@ -1,53 +0,0 @@
(ns status-im.ui.screens.activity-center.notification.contact-request.view
(:require [quo.components.animated.pressable :as animation]
[quo2.core :as quo2]
[status-im.constants :as constants]
[status-im.i18n.i18n :as i18n]
[status-im.ui.screens.activity-center.notification.common.view :as common]
[status-im.utils.datetime :as datetime]
[utils.re-frame :as rf]))
(defn view
[{:keys [id author message last-message] :as notification}]
(let [message (or message last-message)
pressable (case (:contact-request-state message)
constants/contact-request-message-state-accepted
;; NOTE(2022-09-21): We need to dispatch to
;; `:contact.ui/send-message-pressed` instead of
;; `:chat.ui/navigate-to-chat`, otherwise the chat screen
;; looks completely broken if it has never been opened
;; before for the accepted contact.
[animation/pressable {:on-press (fn []
(rf/dispatch [:hide-popover])
(rf/dispatch [:contact.ui/send-message-pressed {:public-key author}]))}]
[:<>])]
(conj pressable
[quo2/activity-log
(merge {:title (i18n/label :t/contact-request)
:icon :main-icons2/add-user
:timestamp (datetime/timestamp->relative (:timestamp notification))
:unread? (not (:read notification))
:context [[common/user-avatar-tag author]
(i18n/label :t/contact-request-sent)]
:message {:body (get-in message [:content :text])}
:status (case (:contact-request-state message)
constants/contact-request-message-state-accepted
{:type :positive :label (i18n/label :t/accepted)}
constants/contact-request-message-state-declined
{:type :negative :label (i18n/label :t/declined)}
nil)}
(case (:contact-request-state message)
constants/contact-request-state-mutual
{:button-1 {:label (i18n/label :t/decline)
:accessibility-label :decline-contact-request
:type :danger
:on-press (fn []
(rf/dispatch [:contact-requests.ui/decline-request id])
(rf/dispatch [:activity-center.notifications/mark-as-read id]))}
:button-2 {:label (i18n/label :t/accept)
:accessibility-label :accept-contact-request
:type :positive
:on-press (fn []
(rf/dispatch [:contact-requests.ui/accept-request id])
(rf/dispatch [:activity-center.notifications/mark-as-read id]))}}
nil))])))

View File

@ -1,48 +0,0 @@
(ns status-im.ui.screens.activity-center.notification.mentions.view
(:require [quo.components.animated.pressable :as animation]
[quo2.core :as quo2]
[quo2.foundations.colors :as colors]
[status-im.i18n.i18n :as i18n]
[status-im.ui.screens.activity-center.notification.common.view :as common]
[status-im.ui.screens.activity-center.notification.mentions.style :as style]
[status-im.utils.datetime :as datetime]
[utils.re-frame :as rf]
[clojure.string :as string]))
(defn message-body [message]
(let [parsed-text (get-in message [:content :parsed-text])
parsed-text-children (:children (first parsed-text))]
(into [quo2/text {:number-of-lines 2
:style style/tag-text
:accessibility-label :activity-message-body
:size :paragraph-1}]
(map-indexed (fn [index {:keys [type literal]}]
^{:key index}
(case type
"mention" [quo2/text {:style style/mention-text
:size :paragraph-1}
(str "@" (rf/sub [:contacts/contact-name-by-identity literal]))]
literal)) parsed-text-children))))
(defn view
[{:keys [author chat-name chat-id message] :as notification}]
[animation/pressable
{:on-press (fn []
(rf/dispatch [:hide-popover])
(rf/dispatch [:chat.ui/navigate-to-chat chat-id]))}
[quo2/activity-log
{:title (i18n/label :t/mention)
:icon :i/mention
:timestamp (datetime/timestamp->relative (:timestamp notification))
:unread? (not (:read notification))
:context [[common/user-avatar-tag author]
[quo2/text {:style style/tag-text} (string/lower-case (i18n/label :t/on))]
;; TODO (@smohamedjavid): The `group-avatar-tag` component
;; does NOT support displaying channel name along with community/chat name.
;; Need to update the component to support it.
[quo2/group-avatar-tag chat-name {:size :small
:override-theme :dark
:color colors/primary-50
:style style/tag
:text-style style/tag-text}]]
:message {:body (message-body message)}}]])

View File

@ -1,9 +0,0 @@
(ns status-im.ui.screens.activity-center.sheet.contact-verification
(:require [status-im.ui.screens.activity-center.notification.contact-verification.view :as contact-verification]))
(defn- reply-view
[{:keys [notification replying?]}]
[contact-verification/view notification {:replying? replying?}])
(def reply
{:content reply-view})

View File

@ -1,137 +0,0 @@
(ns status-im.ui.screens.activity-center.views
(:require [quo.components.safe-area :as safe-area]
[quo.react :as react]
[quo.react-native :as rn]
[quo2.core :as quo2]
[quo2.foundations.colors :as colors]
[status-im.activity-center.notification-types :as types]
[status-im.i18n.i18n :as i18n]
[status-im.ui.screens.activity-center.notification.contact-request.view :as contact-request]
[status-im.ui.screens.activity-center.notification.contact-verification.view :as contact-verification]
[status-im.ui.screens.activity-center.notification.mentions.view :as mentions]
[status-im.ui.screens.activity-center.style :as style]
[utils.re-frame :as rf]))
(defn filter-selector-read-toggle
[]
(let [unread-filter-enabled? (rf/sub [:activity-center/filter-status-unread-enabled?])]
;; TODO(@ilmotta): Replace the button by a Filter Selector.
;; https://github.com/status-im/status-mobile/issues/14355
[quo2/button {:icon true
:type (if unread-filter-enabled? :primary :blur-bg-outline)
:size 32
:override-theme :dark
:on-press #(rf/dispatch [:activity-center.notifications/fetch-first-page
{:filter-status (if unread-filter-enabled?
:all
:unread)}])}
:i/unread]))
;; TODO(@ilmotta,2022-10-07): The empty state is still under design analysis, so we
;; shouldn't even care about translations at this point. A placeholder box is
;; used instead of an image.
(defn empty-tab
[]
[rn/view {:style {:align-items :center
:flex 1
:justify-content :center
:padding-vertical 12}}
[rn/view {:style {:background-color colors/neutral-80
:height 120
:margin-bottom 20
:width 120}}]
[quo2/text {:size :paragraph-1
:style {:padding-bottom 2}
:weight :semi-bold}
"No notifications"]
[quo2/text {:size :paragraph-2}
"Your notifications will be here"]])
(defn tabs
[]
(let [filter-type (rf/sub [:activity-center/filter-type])]
[quo2/scrollable-tabs {:size 32
:blur? true
:override-theme :dark
:style style/tabs
:fade-end-percentage 0.79
:scroll-on-press? true
:fade-end? true
:on-change #(rf/dispatch [:activity-center.notifications/fetch-first-page {:filter-type %}])
:default-active filter-type
:data [{:id types/no-type
:label (i18n/label :t/all)}
{:id types/admin
:label (i18n/label :t/admin)}
{:id types/mention
:label (i18n/label :t/mentions)}
{:id types/reply
:label (i18n/label :t/replies)}
{:id types/contact-request
:label (i18n/label :t/contact-requests)}
{:id types/contact-verification
:label (i18n/label :t/identity-verification)}
{:id types/tx
:label (i18n/label :t/transactions)}
{:id types/membership
:label (i18n/label :t/membership)}
{:id types/system
:label (i18n/label :t/system)}]}]))
(defn header
[]
(let [screen-padding 20]
[rn/view
[quo2/button {:icon true
:type :blur-bg
:size 32
:accessibility-label :close-activity-center
:override-theme :dark
:style style/header-button
:on-press #(rf/dispatch [:hide-popover])}
:i/close]
[quo2/text {:size :heading-1
:weight :semi-bold
:style style/header-heading}
(i18n/label :t/notifications)]
[rn/view {:flex-direction :row
:padding-vertical 12}
[rn/view {:flex 1
:align-self :stretch}
[tabs]]
[rn/view {:flex-grow 0
:margin-left 16
:padding-right screen-padding}
[filter-selector-read-toggle]]]]))
(defn render-notification
[notification index]
[rn/view {:style (style/notification-container index)}
(case (:type notification)
types/contact-verification
[contact-verification/view notification {}]
types/contact-request
[contact-request/view notification]
types/mention
[mentions/view notification]
nil)])
(defn activity-center
[]
[:f>
(fn []
(let [notifications (rf/sub [:activity-center/filtered-notifications])
window-width (rf/sub [:dimensions/window-width])
{:keys [top bottom]} (safe-area/use-safe-area)]
(react/effect! #(rf/dispatch [:activity-center.notifications/fetch-first-page]))
[rn/view {:style (style/screen-container window-width top bottom)}
[header]
[rn/flat-list {:data notifications
:empty-component [empty-tab]
:key-fn :id
:on-scroll-to-index-failed identity
:on-end-reached #(rf/dispatch [:activity-center.notifications/fetch-next-page])
:render-fn render-notification}]]))])

View File

@ -2,7 +2,6 @@
(:require [quo.core :as quo]
[re-frame.core :as re-frame]
[status-im.ui.screens.about-app.views :as about-app]
[status-im.ui.screens.activity-center.sheet.contact-verification :as contact-verification.sheet]
[status-im.ui.screens.home.sheet.views :as home.sheet]
[status-im.ui.screens.keycard.views :as keycard]
[status-im.ui.screens.mobile-network-settings.view :as mobile-network-settings]
@ -29,9 +28,6 @@
(= view :add-new)
(merge home.sheet/add-new)
(= view :activity-center.contact-verification/reply)
(merge contact-verification.sheet/reply)
(= view :keycard.login/more)
(merge keycard/more-sheet)

View File

@ -20,7 +20,7 @@
[status-im.ui.screens.keycard.frozen-card.view :as frozen-card]
[status-im.ui.screens.chat.message.pinned-message :as pinned-message]
[status-im.ui.screens.signing.sheets :as signing-sheets]
[status-im.ui.screens.activity-center.views :as activity-center]))
[status-im2.contexts.activity-center.view :as activity-center]))
(defn hide-panel-anim
[bottom-anim-value alpha-value window-height]
@ -176,7 +176,7 @@
[signing-sheets/fees-warning]
(= :activity-center view)
[activity-center/activity-center]
[activity-center/view]
:else
[view])]]]])))})))

View File

@ -74,7 +74,6 @@
[status-im.ui.screens.network.edit-network.views :as edit-network]
[status-im.ui.screens.network.network-details.views :as network-details]
[status-im.ui.screens.network.views :as network]
[status-im.ui.screens.activity-center.views :as activity-center]
[status-im.ui.screens.notifications-settings.views :as notifications-settings]
[status-im.ui.screens.offline-messaging-settings.edit-mailserver.views
:as
@ -232,9 +231,6 @@
{:name :stickers-pack
:component stickers/pack}
{:name :activity-center
:options {:topBar {:visible false}}
:component activity-center/activity-center}
;; Community
{:name :community
;;TODO custom

View File

@ -1,9 +1,9 @@
(ns status-im.activity-center.core
(ns status-im2.contexts.activity-center.events
(:require [re-frame.core :as rf]
[status-im.activity-center.notification-types :as types]
[status-im.data-store.activities :as data-store.activities]
[status-im.ethereum.json-rpc :as json-rpc]
[status-im.utils.fx :as fx]
[status-im2.contexts.activity-center.notification-types :as types]
[taoensso.timbre :as log]))
(def defaults

View File

@ -1,13 +1,13 @@
(ns status-im.activity-center.core-test
(ns status-im2.contexts.activity-center.events-test
(:require [cljs.test :refer [deftest is testing]]
[day8.re-frame.test :as rf-test]
[re-frame.core :as rf]
[status-im.activity-center.core :as activity-center]
[status-im.activity-center.notification-types :as types]
[status-im.constants :as constants]
[status-im.ethereum.json-rpc :as json-rpc]
status-im.events
[status-im.test-helpers :as h]))
[status-im.test-helpers :as h]
[status-im2.contexts.activity-center.events :as activity-center]
[status-im2.contexts.activity-center.notification-types :as types]))
(def notification-id "0x1")

View File

@ -1,8 +1,8 @@
(ns status-im.ui.screens.activity-center.notification.common.style
(ns status-im2.contexts.activity-center.notification.common.style
(:require [quo2.foundations.colors :as colors]))
(def user-avatar-tag
{:background-color colors/white-opa-10})
(def user-avatar-tag-text
{:color colors/white})
{:color colors/white})

View File

@ -1,17 +1,17 @@
(ns status-im.ui.screens.activity-center.notification.common.view
(:require [utils.re-frame :as rf]
[quo2.core :as quo2]
(ns status-im2.contexts.activity-center.notification.common.view
(:require [quo2.core :as quo]
[status-im.multiaccounts.core :as multiaccounts]
[status-im.ui.screens.activity-center.notification.common.style :as style]
[status-im.ui.screens.activity-center.utils :as activity-center.utils]))
[status-im2.contexts.activity-center.notification.common.style :as style]
[status-im2.contexts.activity-center.utils :as activity-center.utils]
[utils.re-frame :as rf]))
(defn user-avatar-tag [user]
(let [contact (rf/sub [:contacts/contact-by-identity user])]
[quo2/user-avatar-tag
[quo/user-avatar-tag
{:color :purple
:override-theme :dark
:size :small
:style style/user-avatar-tag
:text-style style/user-avatar-tag-text}
(activity-center.utils/contact-name contact)
(multiaccounts/displayed-photo contact)]))
(multiaccounts/displayed-photo contact)]))

View File

@ -0,0 +1,55 @@
(ns status-im2.contexts.activity-center.notification.contact-request.view
(:require [i18n.i18n :as i18n]
[quo2.core :as quo]
[react-native.core :as rn]
[status-im.constants :as constants]
[status-im.utils.datetime :as datetime]
[status-im2.contexts.activity-center.notification.common.view :as common]
[utils.re-frame :as rf]))
(defn view
[{:keys [id author message last-message] :as notification}]
(let [message (or message last-message)
pressable (case (:contact-request-state message)
constants/contact-request-message-state-accepted
;; NOTE(2022-09-21): We need to dispatch to
;; `:contact.ui/send-message-pressed` instead of
;; `:chat.ui/navigate-to-chat`, otherwise the chat screen
;; looks completely broken if it has never been opened
;; before for the accepted contact.
[rn/touchable-without-feedback
{:on-press (fn []
(rf/dispatch [:hide-popover])
(rf/dispatch [:contact.ui/send-message-pressed {:public-key author}]))}]
[:<>])]
(conj pressable
[rn/view
[quo/activity-log
(merge {:title (i18n/label :t/contact-request)
:icon :main-icons2/add-user
:timestamp (datetime/timestamp->relative (:timestamp notification))
:unread? (not (:read notification))
:context [[common/user-avatar-tag author]
(i18n/label :t/contact-request-sent)]
:message {:body (get-in message [:content :text])}
:status (case (:contact-request-state message)
constants/contact-request-message-state-accepted
{:type :positive :label (i18n/label :t/accepted)}
constants/contact-request-message-state-declined
{:type :negative :label (i18n/label :t/declined)}
nil)}
(case (:contact-request-state message)
constants/contact-request-state-mutual
{:button-1 {:label (i18n/label :t/decline)
:accessibility-label :decline-contact-request
:type :danger
:on-press (fn []
(rf/dispatch [:contact-requests.ui/decline-request id])
(rf/dispatch [:activity-center.notifications/mark-as-read id]))}
:button-2 {:label (i18n/label :t/accept)
:accessibility-label :accept-contact-request
:type :positive
:on-press (fn []
(rf/dispatch [:contact-requests.ui/accept-request id])
(rf/dispatch [:activity-center.notifications/mark-as-read id]))}}
nil))]])))

View File

@ -1,10 +1,10 @@
(ns status-im.ui.screens.activity-center.notification.contact-verification.view
(ns status-im2.contexts.activity-center.notification.contact-verification.view
(:require [clojure.string :as string]
[quo2.core :as quo2]
[i18n.i18n :as i18n]
[quo2.core :as quo]
[status-im.constants :as constants]
[status-im.i18n.i18n :as i18n]
[status-im.ui.screens.activity-center.notification.common.view :as common]
[status-im.utils.datetime :as datetime]
[status-im2.contexts.activity-center.notification.common.view :as common]
[utils.re-frame :as rf]))
(defn- hide-bottom-sheet-and-dispatch
@ -60,7 +60,7 @@
;; challengee, not the challenger.
;; https://github.com/status-im/status-mobile/issues/14354
(when-not (and challenger? (= contact-verification-status constants/contact-verification-status-declined))
[quo2/activity-log
[quo/activity-log
(merge {:title (i18n/label :t/identity-verification-request)
:icon :i/friend
:timestamp (datetime/timestamp->relative (:timestamp notification))
@ -101,7 +101,8 @@
{:label (i18n/label :t/message-reply)
:accessibility-label :send-reply-to-contact-verification
:type :primary
:on-press #(rf/dispatch [:bottom-sheet/show-sheet
:activity-center.contact-verification/reply
{:notification notification
:replying? true}])})})))])))))
:on-press (fn []
(rf/dispatch [:bottom-sheet/show-sheet
{:content view}
{:notification notification
:replying? true}]))})})))])))))

View File

@ -1,4 +1,4 @@
(ns status-im.ui.screens.activity-center.notification.mentions.style
(ns status-im2.contexts.activity-center.notification.mentions.style
(:require [quo2.foundations.colors :as colors]))
(def tag
@ -11,4 +11,4 @@
{:color colors/white
:border-radius 6
:padding-horizontal 3
:background-color colors/white-opa-10})
:background-color colors/white-opa-10})

View File

@ -0,0 +1,48 @@
(ns status-im2.contexts.activity-center.notification.mentions.view
(:require [clojure.string :as string]
[i18n.i18n :as i18n]
[quo2.core :as quo]
[quo2.foundations.colors :as colors]
[react-native.core :as rn]
[status-im.utils.datetime :as datetime]
[status-im2.contexts.activity-center.notification.common.view :as common]
[status-im2.contexts.activity-center.notification.mentions.style :as style]
[utils.re-frame :as rf]))
(defn message-body [message]
(let [parsed-text (get-in message [:content :parsed-text])
parsed-text-children (:children (first parsed-text))]
(into [quo/text {:number-of-lines 2
:style style/tag-text
:accessibility-label :activity-message-body
:size :paragraph-1}]
(map-indexed (fn [index {:keys [type literal]}]
^{:key index}
(case type
"mention" [quo/text {:style style/mention-text
:size :paragraph-1}
(str "@" (rf/sub [:contacts/contact-name-by-identity literal]))]
literal)) parsed-text-children))))
(defn view
[{:keys [author chat-name chat-id message] :as notification}]
[rn/touchable-without-feedback
{:on-press (fn []
(rf/dispatch [:hide-popover])
(rf/dispatch [:chat.ui/navigate-to-chat chat-id]))}
[quo/activity-log
{:title (i18n/label :t/mention)
:icon :i/mention
:timestamp (datetime/timestamp->relative (:timestamp notification))
:unread? (not (:read notification))
:context [[common/user-avatar-tag author]
[quo/text {:style style/tag-text} (string/lower-case (i18n/label :t/on))]
;; TODO (@smohamedjavid): The `group-avatar-tag` component
;; does NOT support displaying channel name along with community/chat name.
;; Need to update the component to support it.
[quo/group-avatar-tag chat-name {:size :small
:override-theme :dark
:color colors/primary-50
:style style/tag
:text-style style/tag-text}]]
:message {:body (message-body message)}}]])

View File

@ -1,4 +1,4 @@
(ns status-im.activity-center.notification-types)
(ns status-im2.contexts.activity-center.notification-types)
(def ^:const no-type 0)
(def ^:const one-to-one-chat 1)
@ -8,11 +8,6 @@
(def ^:const contact-request 5)
(def ^:const contact-verification 10)
;; TODO: Remove this constant once the old Notification Center code is removed.
;; Its value clashes with the new constant `-contact-verification`
;; used in status-go.
(def ^:const contact-request-retracted 6)
;; TODO: Replace with correct enum values once status-go implements them.
(def ^:const admin 66610)
(def ^:const tx 66612)

View File

@ -1,4 +1,4 @@
(ns status-im.ui.screens.activity-center.style
(ns status-im2.contexts.activity-center.style
(:require [quo2.foundations.colors :as colors]))
(def screen-padding 20)
@ -26,3 +26,25 @@
(def tabs
{:padding-left screen-padding})
(def tabs-container
{:flex 1
:align-self :stretch})
(def filter-toggle-container
{:flex-grow 0
:margin-left 16
:padding-right screen-padding})
(def tabs-and-filter-container
{:flex-direction :row
:padding-vertical 12})
(def empty-container
{:align-items :center
:flex 1
:justify-content :center
:padding-vertical 12})
(def empty-title
{:padding-bottom 2})

View File

@ -1,4 +1,4 @@
(ns status-im.ui.screens.activity-center.utils)
(ns status-im2.contexts.activity-center.utils)
(defn contact-name
[contact]

View File

@ -0,0 +1,125 @@
(ns status-im2.contexts.activity-center.view
(:require [i18n.i18n :as i18n]
[quo.react :as react]
[quo2.core :as quo]
[react-native.core :as rn]
[react-native.safe-area :as safe-area]
[status-im2.contexts.activity-center.notification-types :as types]
[status-im2.contexts.activity-center.notification.contact-request.view :as contact-request]
[status-im2.contexts.activity-center.notification.contact-verification.view :as contact-verification]
[status-im2.contexts.activity-center.notification.mentions.view :as mentions]
[status-im2.contexts.activity-center.style :as style]
[utils.re-frame :as rf]))
(defn filter-selector-read-toggle
[]
(let [unread-filter-enabled? (rf/sub [:activity-center/filter-status-unread-enabled?])]
;; TODO(@ilmotta): Replace the button by a Filter Selector.
;; https://github.com/status-im/status-mobile/issues/14355
[quo/button {:icon true
:type (if unread-filter-enabled? :primary :blur-bg-outline)
:size 32
:override-theme :dark
:on-press #(rf/dispatch [:activity-center.notifications/fetch-first-page
{:filter-status (if unread-filter-enabled?
:all
:unread)}])}
:i/unread]))
(defn empty-tab
[]
[rn/view {:style style/empty-container
:accessibility-label :empty-notifications}
[quo/icon :i/placeholder]
[quo/text {:size :paragraph-1
:style style/empty-title
:weight :semi-bold}
(i18n/label :t/empty-notifications-title)]
[quo/text {:size :paragraph-2}
(i18n/label :t/empty-notifications-subtitle)]])
(defn tabs
[]
(let [filter-type (rf/sub [:activity-center/filter-type])]
[quo/scrollable-tabs {:size 32
:blur? true
:override-theme :dark
:style style/tabs
:fade-end-percentage 0.79
:scroll-on-press? true
:fade-end? true
:on-change #(rf/dispatch [:activity-center.notifications/fetch-first-page {:filter-type %}])
:default-active filter-type
:data [{:id types/no-type
:label (i18n/label :t/all)}
{:id types/admin
:label (i18n/label :t/admin)}
{:id types/mention
:label (i18n/label :t/mentions)}
{:id types/reply
:label (i18n/label :t/replies)}
{:id types/contact-request
:label (i18n/label :t/contact-requests)}
{:id types/contact-verification
:label (i18n/label :t/identity-verification)}
{:id types/tx
:label (i18n/label :t/transactions)}
{:id types/membership
:label (i18n/label :t/membership)}
{:id types/system
:label (i18n/label :t/system)}]}]))
(defn header
[]
[rn/view
[quo/button {:icon true
:type :blur-bg
:size 32
:accessibility-label :close-activity-center
:override-theme :dark
:style style/header-button
:on-press #(rf/dispatch [:hide-popover])}
:i/close]
[quo/text {:size :heading-1
:weight :semi-bold
:style style/header-heading}
(i18n/label :t/notifications)]
[rn/view {:style style/tabs-and-filter-container}
[rn/view {:style style/tabs-container}
[tabs]]
[rn/view {:style style/filter-toggle-container}
[filter-selector-read-toggle]]]])
(defn render-notification
[notification index]
[rn/view {:style (style/notification-container index)}
(case (:type notification)
types/contact-verification
[contact-verification/view notification {}]
types/contact-request
[contact-request/view notification]
types/mention
[mentions/view notification]
nil)])
(defn view
[]
[:f>
(fn []
(react/effect! #(rf/dispatch [:activity-center.notifications/fetch-first-page]))
[safe-area/consumer
(fn [{:keys [top bottom]}]
(let [notifications (rf/sub [:activity-center/filtered-notifications])
window-width (rf/sub [:dimensions/window-width])]
[rn/view {:style (style/screen-container window-width top bottom)}
[header]
[rn/flat-list {:data notifications
:content-container-style {:flex-grow 1}
:empty-component [empty-tab]
:key-fn :id
:on-scroll-to-index-failed identity
:on-end-reached #(rf/dispatch [:activity-center.notifications/fetch-next-page])
:render-fn render-notification}]]))])])

View File

@ -3,6 +3,7 @@
[status-im2.contexts.communities.discover.view :as communities.discover]
[status-im2.contexts.communities.overview.view :as communities.overview]
[status-im2.contexts.shell.view :as shell]
[status-im2.contexts.activity-center.view :as activity-center]
[status-im2.contexts.quo-preview.main :as quo.preview]
[status-im2.contexts.chat.messages.view :as chat]
[status-im2.contexts.syncing.view :as settings-syncing]
@ -15,8 +16,11 @@
(defn screens []
(concat (old-screens/screens)
[{:name :activity-center
:options {:topBar {:visible false}}
:component activity-center/view}
[{:name :shell-stack
{:name :shell-stack
:insets {:top false}
:component shell/shell-stack}

View File

@ -1,6 +1,6 @@
(ns status-im2.subs.activity-center
(:require [re-frame.core :as re-frame]
[status-im.activity-center.notification-types :as types]))
[status-im2.contexts.activity-center.notification-types :as types]))
(re-frame/reg-sub
:activity-center/notifications

View File

@ -1889,6 +1889,8 @@
"bold": "Bold",
"italic": "Italic",
"strikethrough": "Strikethrough",
"empty-notifications-title": "No notifications",
"empty-notifications-subtitle": "Your notifications will be here",
"add-text": "Add text",
"send": "Send",
"unmute-group": "Unmute group",