Browse Source

app update

Leon 1 năm trước cách đây
mục cha
commit
5214fd6f16

+ 1 - 1
ios/hola.xcodeproj/project.pbxproj

@@ -661,7 +661,7 @@
 				ENABLE_STRICT_OBJC_MSGSEND = YES;
 				ENABLE_TESTABILITY = YES;
 				EXCLUDED_ARCHS = "";
-				"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
+				"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "";
 				GCC_C_LANGUAGE_STANDARD = gnu99;
 				GCC_DYNAMIC_NO_PIC = NO;
 				GCC_NO_COMMON_BLOCKS = YES;

+ 81 - 0
src/features/trackTimeDuration/actions/TrackTimeActions.tsx

@@ -1,5 +1,14 @@
+import { API_LOCAL_PUSHES } from "@/services/http/api";
+import { request } from "@/services/http/request";
 import { recordCheck } from "@/services/trackTimeDuration";
 import trackTimeService, { machine } from "@/store/trackTimeMachine"
+import dayjs from 'dayjs'
+
+let PushNotification, Importance;
+if (process.env.TARO_ENV == 'rn') {
+    PushNotification = require('react-native-push-notification')
+    Importance = require('react-native-push-notification').Importance
+}
 
 export const startFast = (start_time: number, duration: number) => {
     return new Promise((resolve) => {
@@ -16,6 +25,7 @@ export const startFast = (start_time: number, duration: number) => {
         }).then(res => {
             resolve(res)
             trackTimeService.send({ type: 'START_FAST' });
+            getLocalPush()
         });
     });
 }
@@ -35,6 +45,7 @@ export const endFast = (start_time: number) => {
             trackTimeService.send({ type: 'RESET' });
             trackTimeService.send({ type: global.scenario });
             resolve(res)
+            getLocalPush()
         }).catch(e => {
             reject(e)
         });
@@ -57,6 +68,7 @@ export const startSleep = (start_time: number, duration: number) => {
         }).then(res => {
             trackTimeService.send({ type: 'START_SLEEP' });
             resolve(res)
+            getLocalPush()
         }).catch(e => {
             reject(e)
         });
@@ -75,9 +87,78 @@ export const endSleep = (start_time: number) => {
         }).then(res => {
             trackTimeService.send({ type: 'END_SLEEP' });
             resolve(res)
+            getLocalPush()
         }).catch(e => {
             reject(e)
         });
     });
 }
 
+export const getLocalPush = () => {
+    request({
+        url: API_LOCAL_PUSHES, method: 'GET', data: {}
+    }).then(res => {
+        const { messages } = res as any;
+        if (messages.length == 0) {
+            return;
+        }
+        if (process.env.TARO_ENV == 'weapp') {
+            return;
+        }
+        PushNotification.configure({
+            onRegister: function (token) {
+                console.log('TOKEN:', token);
+            },
+
+            onNotification: function (notification) {
+                console.log('NOTIFICATION:', notification);
+                // notification.finish(PushNotificationIOS.FetchResult.NoData);
+            },
+
+            permissions: {
+                alert: true,
+                badge: true,
+                sound: true,
+            },
+
+            popInitialNotification: true,
+            requestPermissions: true,
+        });
+        PushNotification.cancelAllLocalNotifications()
+
+        messages.map(item => {
+            if (item.mode == 'ONCE') {
+                PushNotification.localNotificationSchedule({
+                    //... You can use all the options from localNotifications
+                    title: item.title,
+                    message: item.content + '  ', // (required)
+                    date: new Date(item.once), // in 60 secs
+                    allowWhileIdle: true, // (optional) set notification to work while on doze, default: false
+                    messageId: item.id,
+                    // repeatType:'minute',
+                    /* Android Only Properties */
+
+                })
+            }
+            else if (item.mode == 'RECURRING') {
+                const { time, repeat_type } = item.recurring;
+                const date = dayjs().format('YYYY-MM-DD')
+                PushNotification.localNotificationSchedule({
+                    //... You can use all the options from localNotifications
+                    title: item.title,
+                    message: item.content + '  ', // (required)
+                    date: new Date(date + 'T' + time), // in 60 secs
+                    allowWhileIdle: true, // (optional) set notification to work while on doze, default: false
+                    messageId: item.id,
+                    repeatType: repeat_type,
+                    // repeatType:'minute',
+                    /* Android Only Properties */
+
+                })
+            }
+
+        })
+        console.log('notificatin push set', messages)
+    })
+}
+

+ 26 - 13
src/features/trackTimeDuration/components/CheckAccess.scss

@@ -1,17 +1,6 @@
 @import '@/utils/common.scss';
 
-.fast_alert_container {
-    position: fixed;
-    left: 0;
-    top: 0;
-    right: 0;
-    bottom: 0;
-    display: flex;
-    align-items: center;
-    justify-content: center;
-    background-color: #000000e0;
-    z-index: 10000000;
-}
+
 
 .fast_alert_content {
     display: flex;
@@ -82,7 +71,18 @@
     text-fill-color: transparent;
 }
 
-
+.fast_alert_container {
+    position: fixed;
+    left: 0;
+    top: 0;
+    right: 0;
+    bottom: 0;
+    display: flex;
+    align-items: center;
+    justify-content: center;
+    background-color: #000000e0;
+    z-index: 10000000;
+}
 
 /* #endif */
 
@@ -91,6 +91,19 @@
     color: #fff;
     font-size: 20px;
 }
+
+.fast_alert_container {
+    position: absolute;
+    left: 0;
+    top: 0;
+    right: 0;
+    bottom: 0;
+    display: flex;
+    align-items: center;
+    justify-content: center;
+    background-color: #000000e0;
+    z-index: 10000000;
+}
 /* #endif */
 
 

+ 10 - 3
src/features/trackTimeDuration/components/CheckAccess.tsx

@@ -16,9 +16,10 @@ let confirmAction: any = null;
 let cancelAction: any = null;
 let timer;
 let access;
-let useNavigation, AppState;
+let useNavigation, AppState, Modal;
 if (process.env.TARO_ENV == 'rn') {
     AppState = require("react-native").AppState
+    Modal = require("react-native").Modal
     useNavigation = require("@react-navigation/native").useNavigation
 }
 
@@ -281,7 +282,6 @@ export default function CheckAccess(props: { record: any, count: number }) {
         }
 
         console.error('失去资格弹窗', trigger_event, desc);
-        debugger
 
 
         setShowFastAlert(true)
@@ -474,7 +474,14 @@ export default function CheckAccess(props: { record: any, count: number }) {
 
     return <View>
         {
-            showFastAlert && alertPop()
+            showFastAlert && process.env.TARO_ENV == 'weapp' && alertPop()
+        }
+        {
+            showFastAlert && process.env.TARO_ENV == 'rn' && <Modal transparent={true}>
+                <View style={{ backgroundColor: 'rgba(0,0,0,0.95)', width: '100%', height: '100%', alignItems: 'center', justifyContent: 'center' }}>
+                    {alertPop()}
+                </View>
+            </Modal>
         }
     </View>
 }

+ 52 - 52
src/pages/clock/Clock.tsx

@@ -177,60 +177,60 @@ export default function Page() {
         else {
             loadRNCache()
 
-            PushNotification.configure({
-                onRegister: function (token) {
-                    console.log('TOKEN:', token);
-                },
-
-                onNotification: function (notification) {
-                    console.log('NOTIFICATION:', notification);
-                    // notification.finish(PushNotificationIOS.FetchResult.NoData);
-                },
-
-                permissions: {
-                    alert: true,
-                    badge: true,
-                    sound: true,
-                },
+            // PushNotification.configure({
+            //     onRegister: function (token) {
+            //         console.log('TOKEN:', token);
+            //     },
+
+            //     onNotification: function (notification) {
+            //         console.log('NOTIFICATION:', notification);
+            //         // notification.finish(PushNotificationIOS.FetchResult.NoData);
+            //     },
+
+            //     permissions: {
+            //         alert: true,
+            //         badge: true,
+            //         sound: true,
+            //     },
+
+            //     popInitialNotification: true,
+            //     requestPermissions: true,
+            // });
 
-                popInitialNotification: true,
-                requestPermissions: true,
-            });
-
-            var channelId = "your-channel-id" + new Date().getTime()
-            PushNotification.createChannel({
-                channelId: channelId, // (required)
-                channelName: "My channel", // (required)
-                channelDescription: "A channel to categorise your notifications", // (optional) default: undefined.
-                playSound: false, // (optional) default: true
-                soundName: "default", // (optional) See `soundName` parameter of `localNotification` function
-                importance: Importance.HIGH, // (optional) default: Importance.HIGH. Int value of the Android notification importance
-                vibrate: true, // (optional) default: true. Creates the default vibration pattern if true.
-            }, (created) => {
-                console.log('create channel result',created)
-                PushNotification.localNotificationSchedule({
-                    //... You can use all the options from localNotifications
-                    channelId: channelId,
-                    title: 'Leon test',
-                    message: "Local notification push", // (required)
-                    date: new Date(Date.now() + 10 * 1000), // in 60 secs
-                    allowWhileIdle: true, // (optional) set notification to work while on doze, default: false
-                    // repeatType:'minute',
-                    /* Android Only Properties */
-                    // repeatTime: 1, // (optional) Increment of configured repeatType. Check 'Repeating Notifications' section for more info.
-                });
-            })
+            // var channelId = "your-channel-id" + new Date().getTime()
+            // PushNotification.createChannel({
+            //     channelId: channelId, // (required)
+            //     channelName: "My channel", // (required)
+            //     channelDescription: "A channel to categorise your notifications", // (optional) default: undefined.
+            //     playSound: false, // (optional) default: true
+            //     soundName: "default", // (optional) See `soundName` parameter of `localNotification` function
+            //     importance: Importance.HIGH, // (optional) default: Importance.HIGH. Int value of the Android notification importance
+            //     vibrate: true, // (optional) default: true. Creates the default vibration pattern if true.
+            // }, (created) => {
+            //     console.log('create channel result',created)
+            //     PushNotification.localNotificationSchedule({
+            //         //... You can use all the options from localNotifications
+            //         channelId: channelId,
+            //         title: 'Leon test',
+            //         message: "Local notification push", // (required)
+            //         date: new Date(Date.now() + 10 * 1000), // in 60 secs
+            //         allowWhileIdle: true, // (optional) set notification to work while on doze, default: false
+            //         // repeatType:'minute',
+            //         /* Android Only Properties */
+            //         // repeatTime: 1, // (optional) Increment of configured repeatType. Check 'Repeating Notifications' section for more info.
+            //     });
+            // })
 
-            PushNotification.localNotificationSchedule({
-                //... You can use all the options from localNotifications
-                title: 'Leon test2',
-                message: "Local notification push2", // (required)
-                date: new Date(Date.now() + 15 * 1000), // in 60 secs
-                allowWhileIdle: true, // (optional) set notification to work while on doze, default: false
-                // repeatType:'minute',
-                /* Android Only Properties */
-                // repeatTime: 1, // (optional) Increment of configured repeatType. Check 'Repeating Notifications' section for more info.
-            });
+            // PushNotification.localNotificationSchedule({
+            //     //... You can use all the options from localNotifications
+            //     title: 'Leon test2',
+            //     message: "Local notification push2", // (required)
+            //     date: new Date(Date.now() + 15 * 1000), // in 60 secs
+            //     allowWhileIdle: true, // (optional) set notification to work while on doze, default: false
+            //     // repeatType:'minute',
+            //     /* Android Only Properties */
+            //     // repeatTime: 1, // (optional) Increment of configured repeatType. Check 'Repeating Notifications' section for more info.
+            // });
 
             // PushNotification.localNotificationSchedule({
             //     //... You can use all the options from localNotifications

+ 15 - 9
src/pages/clock/SetGoal.tsx

@@ -232,14 +232,14 @@ export default function SetGoal() {
             if (global.indexPageRefresh) {
                 global.indexPageRefresh()
             }
-            // popMixScheduleAlert(scenario.schedule.fast.start_time, startTime)
 
-            if (process.env.TARO_ENV === 'rn') {
-                popRNAlert()
-            }
-            else {
-                popAlert()
-            }
+            // if (process.env.TARO_ENV === 'rn') {
+            //     popRNAlert()
+            // }
+            // else {
+            //     popAlert()
+            // }
+            popAlert()
 
 
         }).catch(e => {
@@ -248,9 +248,15 @@ export default function SetGoal() {
 
     function popAlert() {
         global.chooseMixed()
-        Taro.navigateBack({ delta: 6 }).then(res => {
 
-        })
+        if (process.env.TARO_ENV === 'weapp') {
+            Taro.navigateBack({ delta: 6 }).then(res => {
+
+            })
+        }
+        else {
+            navigation.popToTop()
+        }
         if (target.isMixed) {
             setTimeout(() => {
                 global.popMixScheduleAlert(fastTarget.start_time, sleepTarget.start_time)

+ 1 - 0
src/services/http/api.js

@@ -47,6 +47,7 @@ export const API_FAST_SCHEDULES = `${baseUrl}/api/fast/schedules`
 export const API_FAST_CALENDARS = `${baseUrl}/api/fast/calendars/`
 export const API_CLOCK_RECORD_UPDATE = `${baseUrl}/api/clock/records`
 export const API_CLOCK_STREAKS = `${baseUrl}/api/clock/streaks`
+export const API_LOCAL_PUSHES = `${baseUrl}/api/user/local-pushes`
 
 
 //track something

+ 3 - 1
src/services/trackTimeDuration.tsx

@@ -1,7 +1,8 @@
 
-import exp from 'constants';
+
 import { API_FAST_PLANS, API_FAST_CHECKS, API_FAST_CLOCKS, API_CLOCK_RECORDS, API_CLOCK_HOME, API_CLOCK_STATS, API_CLOCK_SUMMARY_RECORDS, API_CLOCK_RECORD_UPDATE, API_CLOCK_STREAKS } from './http/api'
 import { request } from './http/request';
+import { getLocalPush } from '@/features/trackTimeDuration/actions/TrackTimeActions';
 
 export const getPlans = () => {
     return new Promise((resolve, reject) => {
@@ -21,6 +22,7 @@ export const setPlan = (params: Record<string, any> | undefined) => {
             url: API_FAST_PLANS, method: 'POST', data: { ...params }
         }).then(res => {
             resolve(res);
+            getLocalPush();
         }).catch(e => {
             reject(e)
         })