ordering-ui-react-native 0.21.31-test → 0.21.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,33 +1,22 @@
|
|
|
1
|
-
import React, { useEffect, useState } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
Modal,
|
|
4
|
-
View,
|
|
5
|
-
StyleSheet,
|
|
6
|
-
Dimensions,
|
|
7
|
-
TouchableOpacity
|
|
8
|
-
} from 'react-native';
|
|
9
|
-
import { useTheme } from 'styled-components/native'
|
|
10
1
|
import moment from 'moment'
|
|
2
|
+
import { NewOrderNotification as NewOrderNotificationController, useApi, useEvent, useLanguage, useSession } from 'ordering-components/native'
|
|
3
|
+
import React, { useEffect, useState } from 'react'
|
|
4
|
+
import { Dimensions, Modal, StyleSheet, TouchableOpacity, View } from 'react-native'
|
|
5
|
+
import Sound from 'react-native-sound'
|
|
11
6
|
import Icon from 'react-native-vector-icons/Feather'
|
|
7
|
+
import { useTheme } from 'styled-components/native'
|
|
12
8
|
|
|
13
|
-
import {
|
|
14
|
-
NewOrderNotification as NewOrderNotificationController,
|
|
15
|
-
useApi,
|
|
16
|
-
useEvent,
|
|
17
|
-
useLanguage,
|
|
18
|
-
useSession
|
|
19
|
-
} from 'ordering-components/native'
|
|
20
|
-
|
|
21
|
-
import TrackPlayer from 'react-native-track-player';
|
|
22
|
-
|
|
9
|
+
import { useLocation } from '../../hooks/useLocation'
|
|
23
10
|
import { OIcon, OText } from '../shared'
|
|
24
11
|
import { NotificationContainer } from './styles'
|
|
25
|
-
import { useLocation } from '../../hooks/useLocation'
|
|
26
12
|
|
|
27
|
-
|
|
28
|
-
|
|
13
|
+
Sound.setCategory('Playback', true)
|
|
14
|
+
Sound.setMode('Default')
|
|
15
|
+
|
|
29
16
|
const windowWidth = Dimensions.get('screen').width
|
|
30
17
|
|
|
18
|
+
const SOUND_LOOP = 3
|
|
19
|
+
|
|
31
20
|
const NewOrderNotificationUI = (props: any) => {
|
|
32
21
|
const { isBusinessApp } = props
|
|
33
22
|
const [events] = useEvent()
|
|
@@ -35,7 +24,7 @@ const NewOrderNotificationUI = (props: any) => {
|
|
|
35
24
|
const [, t] = useLanguage()
|
|
36
25
|
const [{ user, token }] = useSession()
|
|
37
26
|
const [ordering] = useApi()
|
|
38
|
-
const { getCurrentLocation } = useLocation()
|
|
27
|
+
const { getCurrentLocation } = useLocation();
|
|
39
28
|
const [currentEvent, setCurrentEvent] = useState<any>(null)
|
|
40
29
|
|
|
41
30
|
const evtList: any = {
|
|
@@ -56,28 +45,37 @@ const NewOrderNotificationUI = (props: any) => {
|
|
|
56
45
|
},
|
|
57
46
|
}
|
|
58
47
|
|
|
48
|
+
const soundSrc = 'https://d33aymufw4jvwf.cloudfront.net/notification.mp3' ?? theme.sounds.notification
|
|
49
|
+
|
|
50
|
+
const notificationSound = new Sound(soundSrc, '', () => { });
|
|
51
|
+
|
|
52
|
+
let _timeout: any = null
|
|
53
|
+
let times = 0
|
|
54
|
+
|
|
59
55
|
const handleCloseEvents = () => {
|
|
56
|
+
notificationSound.stop()
|
|
60
57
|
setCurrentEvent(null)
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const playSoundNotification = () => {
|
|
64
|
-
let count = 0;
|
|
65
|
-
const intervalId = setInterval(() => {
|
|
66
|
-
TrackPlayer.seekTo(0)
|
|
67
|
-
TrackPlayer.play()
|
|
68
|
-
setTimeout(() => {
|
|
69
|
-
TrackPlayer.pause()
|
|
70
|
-
count++
|
|
71
|
-
if (count === SOUND_LOOP_AMOUNT) {
|
|
72
|
-
clearInterval(intervalId);
|
|
73
|
-
}
|
|
74
|
-
}, 500) // sound duration divide by 2
|
|
75
|
-
}, DURATION_BETWEEN_LOOP) // notification duration
|
|
58
|
+
clearInterval(_timeout)
|
|
76
59
|
}
|
|
77
60
|
|
|
78
61
|
const handlePlayNotificationSound = (eventObj: any = null) => {
|
|
79
62
|
setCurrentEvent(eventObj)
|
|
80
|
-
|
|
63
|
+
if (times > 0) {
|
|
64
|
+
if (times === 3) {
|
|
65
|
+
times = 0
|
|
66
|
+
return
|
|
67
|
+
}
|
|
68
|
+
return
|
|
69
|
+
}
|
|
70
|
+
_timeout = setInterval(() => {
|
|
71
|
+
if (times < SOUND_LOOP) {
|
|
72
|
+
notificationSound.play()
|
|
73
|
+
times++
|
|
74
|
+
} else {
|
|
75
|
+
clearInterval(_timeout)
|
|
76
|
+
return
|
|
77
|
+
}
|
|
78
|
+
}, 2500)
|
|
81
79
|
}
|
|
82
80
|
|
|
83
81
|
const handleEventNotification = async (evtType: number, value: any) => {
|
|
@@ -98,15 +96,11 @@ const NewOrderNotificationUI = (props: any) => {
|
|
|
98
96
|
handlePlayNotificationSound({ evt: 2, orderId: value?.id })
|
|
99
97
|
}
|
|
100
98
|
}
|
|
101
|
-
if (evtType === 3 || value
|
|
102
|
-
handlePlayNotificationSound({
|
|
99
|
+
if (evtType === 3 || value.author_id === user.id) return
|
|
100
|
+
setTimeout(() => handlePlayNotificationSound({
|
|
103
101
|
evt: evtType,
|
|
104
|
-
orderId: value?.driver
|
|
105
|
-
|
|
106
|
-
: evtList[evtType].event === 'messages'
|
|
107
|
-
? value?.order?.id
|
|
108
|
-
: value?.order_id ?? value?.id
|
|
109
|
-
})
|
|
102
|
+
orderId: value?.driver ? value?.order_id : evtList[evtType].event === 'messages' ? value?.order?.id : value?.order_id
|
|
103
|
+
}), 1000)
|
|
110
104
|
}
|
|
111
105
|
|
|
112
106
|
useEffect(() => {
|