ordering-ui-react-native 0.21.31 → 0.21.32-test
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,22 +1,32 @@
|
|
|
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'
|
|
1
10
|
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'
|
|
6
11
|
import Icon from 'react-native-vector-icons/Feather'
|
|
7
|
-
import
|
|
12
|
+
import SoundPlayer from 'react-native-sound-player'
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
NewOrderNotification as NewOrderNotificationController,
|
|
16
|
+
useApi,
|
|
17
|
+
useEvent,
|
|
18
|
+
useLanguage,
|
|
19
|
+
useSession
|
|
20
|
+
} from 'ordering-components/native'
|
|
8
21
|
|
|
9
|
-
import { useLocation } from '../../hooks/useLocation'
|
|
10
22
|
import { OIcon, OText } from '../shared'
|
|
11
23
|
import { NotificationContainer } from './styles'
|
|
24
|
+
import { useLocation } from '../../hooks/useLocation'
|
|
12
25
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
26
|
+
const SOUND_REPETITIONS = 3
|
|
27
|
+
const DELAY_SOUND = 2000 // 2 sec
|
|
16
28
|
const windowWidth = Dimensions.get('screen').width
|
|
17
29
|
|
|
18
|
-
const SOUND_LOOP = 3
|
|
19
|
-
|
|
20
30
|
const NewOrderNotificationUI = (props: any) => {
|
|
21
31
|
const { isBusinessApp } = props
|
|
22
32
|
const [events] = useEvent()
|
|
@@ -24,9 +34,11 @@ const NewOrderNotificationUI = (props: any) => {
|
|
|
24
34
|
const [, t] = useLanguage()
|
|
25
35
|
const [{ user, token }] = useSession()
|
|
26
36
|
const [ordering] = useApi()
|
|
27
|
-
const { getCurrentLocation } = useLocation()
|
|
37
|
+
const { getCurrentLocation } = useLocation()
|
|
28
38
|
const [currentEvent, setCurrentEvent] = useState<any>(null)
|
|
29
39
|
|
|
40
|
+
const URL_SOUND = 'https://d33aymufw4jvwf.cloudfront.net/notification.mp3' ?? theme.sounds.notification
|
|
41
|
+
|
|
30
42
|
const evtList: any = {
|
|
31
43
|
1: {
|
|
32
44
|
event: 'messages',
|
|
@@ -45,37 +57,22 @@ const NewOrderNotificationUI = (props: any) => {
|
|
|
45
57
|
},
|
|
46
58
|
}
|
|
47
59
|
|
|
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
|
-
|
|
55
60
|
const handleCloseEvents = () => {
|
|
56
|
-
notificationSound.stop()
|
|
57
61
|
setCurrentEvent(null)
|
|
58
|
-
|
|
62
|
+
SoundPlayer.stop();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const playSoundNotification = async () => {
|
|
66
|
+
for (let i = 0; i < SOUND_REPETITIONS; i++) {
|
|
67
|
+
SoundPlayer.playUrl(URL_SOUND)
|
|
68
|
+
await new Promise(resolve => setTimeout(resolve, DELAY_SOUND));
|
|
69
|
+
SoundPlayer.stop();
|
|
70
|
+
}
|
|
59
71
|
}
|
|
60
72
|
|
|
61
73
|
const handlePlayNotificationSound = (eventObj: any = null) => {
|
|
62
74
|
setCurrentEvent(eventObj)
|
|
63
|
-
|
|
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)
|
|
75
|
+
playSoundNotification()
|
|
79
76
|
}
|
|
80
77
|
|
|
81
78
|
const handleEventNotification = async (evtType: number, value: any) => {
|
|
@@ -96,11 +93,15 @@ const NewOrderNotificationUI = (props: any) => {
|
|
|
96
93
|
handlePlayNotificationSound({ evt: 2, orderId: value?.id })
|
|
97
94
|
}
|
|
98
95
|
}
|
|
99
|
-
if (evtType === 3 || value
|
|
100
|
-
|
|
96
|
+
if (evtType === 3 || value?.author_id === user.id) return
|
|
97
|
+
handlePlayNotificationSound({
|
|
101
98
|
evt: evtType,
|
|
102
|
-
orderId: value?.driver
|
|
103
|
-
|
|
99
|
+
orderId: value?.driver
|
|
100
|
+
? value?.order_id
|
|
101
|
+
: evtList[evtType].event === 'messages'
|
|
102
|
+
? value?.order?.id
|
|
103
|
+
: value?.order_id ?? value?.id
|
|
104
|
+
})
|
|
104
105
|
}
|
|
105
106
|
|
|
106
107
|
useEffect(() => {
|
|
@@ -6,11 +6,6 @@ import { Placeholder, PlaceholderLine, Fade } from 'rn-placeholder';
|
|
|
6
6
|
import FeatherIcon from 'react-native-vector-icons/Feather';
|
|
7
7
|
import FontistoIcon from 'react-native-vector-icons/Fontisto'
|
|
8
8
|
import AntDesignIcon from 'react-native-vector-icons/AntDesign'
|
|
9
|
-
import TrackPlayer, {
|
|
10
|
-
RepeatMode,
|
|
11
|
-
Capability,
|
|
12
|
-
AppKilledPlaybackBehavior
|
|
13
|
-
} from 'react-native-track-player';
|
|
14
9
|
|
|
15
10
|
import { useTheme } from 'styled-components/native';
|
|
16
11
|
import { DeviceOrientationMethods } from '../../../../../src/hooks/DeviceOrientation'
|
|
@@ -112,79 +107,6 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
|
|
|
112
107
|
const HEIGHT_SCREEN = orientationState?.dimensions?.height
|
|
113
108
|
const IS_PORTRAIT = orientationState.orientation === PORTRAIT
|
|
114
109
|
|
|
115
|
-
const URL_SOUND = 'https://d33aymufw4jvwf.cloudfront.net/notification.mp3' ?? theme.sounds.notification
|
|
116
|
-
|
|
117
|
-
const setupPlayer = async (options: any) => {
|
|
118
|
-
const setup = async () => {
|
|
119
|
-
try {
|
|
120
|
-
await TrackPlayer.setupPlayer(options);
|
|
121
|
-
} catch (error) {
|
|
122
|
-
return (error as Error & { code?: string }).code;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
while ((await setup()) === 'android_cannot_setup_player_in_background') {
|
|
126
|
-
await new Promise<void>((resolve) => setTimeout(resolve, 1));
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
const SetupService = async () => {
|
|
131
|
-
await setupPlayer({ autoHandleInterruptions: true });
|
|
132
|
-
await TrackPlayer.updateOptions({
|
|
133
|
-
android: {
|
|
134
|
-
appKilledPlaybackBehavior:
|
|
135
|
-
AppKilledPlaybackBehavior.StopPlaybackAndRemoveNotification,
|
|
136
|
-
},
|
|
137
|
-
capabilities: [
|
|
138
|
-
Capability.Play,
|
|
139
|
-
Capability.Pause,
|
|
140
|
-
Capability.SkipToNext,
|
|
141
|
-
Capability.SkipToPrevious,
|
|
142
|
-
Capability.SeekTo,
|
|
143
|
-
],
|
|
144
|
-
compactCapabilities: [
|
|
145
|
-
Capability.Play,
|
|
146
|
-
Capability.Pause,
|
|
147
|
-
Capability.SkipToNext,
|
|
148
|
-
],
|
|
149
|
-
progressUpdateEventInterval: 2,
|
|
150
|
-
});
|
|
151
|
-
await TrackPlayer.setRepeatMode(RepeatMode.Track);
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
const QueueInitialTracksService = async () => {
|
|
155
|
-
await TrackPlayer.add([
|
|
156
|
-
{
|
|
157
|
-
id: 'notification',
|
|
158
|
-
url: URL_SOUND,
|
|
159
|
-
title: 'notification'
|
|
160
|
-
},
|
|
161
|
-
]);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
function useSetupPlayer() {
|
|
165
|
-
const [playerReady, setPlayerReady] = useState<boolean>(false)
|
|
166
|
-
|
|
167
|
-
useEffect(() => {
|
|
168
|
-
let unmounted = false;
|
|
169
|
-
(async () => {
|
|
170
|
-
await SetupService()
|
|
171
|
-
if (unmounted) return
|
|
172
|
-
setPlayerReady(true)
|
|
173
|
-
const queue = await TrackPlayer.getQueue()
|
|
174
|
-
if (unmounted) return
|
|
175
|
-
if (queue.length <= 0) {
|
|
176
|
-
await QueueInitialTracksService()
|
|
177
|
-
}
|
|
178
|
-
})();
|
|
179
|
-
return () => {
|
|
180
|
-
unmounted = true;
|
|
181
|
-
};
|
|
182
|
-
}, []);
|
|
183
|
-
return playerReady;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
const isPlayerReady = useSetupPlayer()
|
|
187
|
-
|
|
188
110
|
const preorderTypeList = [
|
|
189
111
|
{ key: null, name: t('SLA', 'SLA\'s') },
|
|
190
112
|
{ key: 'in_time', name: t('OK', 'Ok') },
|
|
@@ -780,10 +702,7 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
|
|
|
780
702
|
</View>
|
|
781
703
|
|
|
782
704
|
{isBusinessApp && (
|
|
783
|
-
<NewOrderNotification
|
|
784
|
-
isBusinessApp={isBusinessApp}
|
|
785
|
-
isPlayerReady={isPlayerReady}
|
|
786
|
-
/>
|
|
705
|
+
<NewOrderNotification isBusinessApp={isBusinessApp} />
|
|
787
706
|
)}
|
|
788
707
|
|
|
789
708
|
{(openSearchModal || openSLASettingModal) && (
|