vbea 2 лет назад
Родитель
Сommit
b9f538976c

+ 3 - 0
Strides-APP/app/api/apiNotification.js

@@ -26,5 +26,8 @@ export default {
    */
   getTabDotCount() {
     return get(prefix + "tab-count")
+  },
+  readAll() {
+    return get(prefix + "read-all")
   }
 }

+ 15 - 0
Strides-APP/app/pages/alert/AlertUtil.js

@@ -10,5 +10,20 @@ export default {
   },
   getCampaignCount() {
     return global.alertBadgeCountInfo?.campaignCount || 0
+  },
+  getUnreadAlert() {
+    return global.alertBadgeCountInfo?.alertUnreadCount || 0
+  },
+  setOnRefreshListener(listener) {
+    global.notificationPageListener = listener;
+  },
+  requestRefresh() {
+    if (global.notificationPageListener) {
+      global.notificationPageListener();
+    }
+  },
+  release() {
+    global.alertBadgeCountInfo = {};
+    global.notificationPageListener = undefined;
   }
 }

+ 11 - 4
Strides-APP/app/pages/alert/ListAlerts.js

@@ -17,7 +17,8 @@ export default class ListAlerts extends Component {
     super(props);
     this.state = {
       dataList: [],
-      refreshing: false
+      refreshing: false,
+      showReadAll: false
     };
   }
 
@@ -75,7 +76,8 @@ export default class ListAlerts extends Component {
     apiNotification.getNotificationList("").then(res => {
       if (res.data) {
         this.setState({
-          dataList: res.data
+          dataList: res.data,
+          showReadAll: res.data?.length > 0 && AlertUtil.getUnreadAlert() > 0
         })
       }
     }).catch(err => {
@@ -118,7 +120,12 @@ export default class ListAlerts extends Component {
 
   readAllMessage() {
     Dialog.dismissLoading();
-    this.onRefresh();
+    apiNotification.readAll().then(res => {
+      AlertUtil.requestRefresh();
+      this.onRefresh();
+    }).catch(err => {
+      toastShort(err)
+    })
   }
 
   listItem = (props) => {
@@ -132,7 +139,7 @@ export default class ListAlerts extends Component {
   }
 
   topView = (props) => {
-    if (this.state.dataList.length > 0) {
+    if (this.state.showReadAll) {
       return (
         <View style={styles.topView}>
           <Button

+ 4 - 0
Strides-APP/app/pages/alert/Notification.js

@@ -60,9 +60,13 @@ export default class Notification extends Component {
     });
     this.getTotalCount();
     //BackHandler.addEventListener('hardwareBackPress', this.backPage)
+    AlertUtil.setOnRefreshListener(() => {
+      this.getTotalCount();
+    })
   }
 
   componentWillUnmount() {
+    AlertUtil.release();
     //BackHandler.removeEventListener("hardwareBackPress", this.backPage)
   }