1
+ /* eslint-disable jsx-a11y/media-has-caption */
1
2
import { React , useEffect , useState , useContext , useRef } from "react" ;
2
3
import { useParams } from "react-router-dom" ;
3
4
import useFetch from "../../util/useFetch" ;
@@ -11,7 +12,7 @@ import {
11
12
import PermissionContext from "../../context/permission-context" ;
12
13
import BackButton from "../BackButton" ;
13
14
import { ReactComponent as LocationArrow } from "../../icons/location-arrow-solid.svg" ;
14
- import AudioContext from "../../context/audio -context" ;
15
+ import ApiEndpointContext from "../../context/api-endpoint -context" ;
15
16
16
17
function RoutePage ( ) {
17
18
const { id } = useParams ( ) ;
@@ -25,12 +26,12 @@ function RoutePage() {
25
26
const [ destinationLatitude , setDestinationLatitude ] = useState ( 0 ) ;
26
27
const [ destinationLongitude , setDestinationLongitude ] = useState ( 0 ) ;
27
28
const [ destinationDistance , setDestinationDistance ] = useState ( null ) ;
28
- const [ destination , setDestination ] = useState ( null ) ;
29
29
const [ destinationIndex , setDestinationIndex ] = useState ( 0 ) ;
30
30
const [ nextUnlockableId , setNextUnlockableId ] = useState ( null ) ;
31
+ const [ source , setSource ] = useState ( null ) ;
31
32
const { userLatitude, userLongitude } = useContext ( LatLongContext ) ;
32
33
const { geolocationAvailable } = useContext ( PermissionContext ) ;
33
- const { audio } = useContext ( AudioContext ) ;
34
+ const audioRef = useRef ( ) ;
34
35
const isIOS =
35
36
navigator . userAgent . match ( / ( i P o d | i P h o n e | i P a d ) / ) &&
36
37
navigator . userAgent . match ( / A p p l e W e b K i t / ) ;
@@ -42,6 +43,14 @@ function RoutePage() {
42
43
}
43
44
} , [ data ] ) ;
44
45
46
+ useEffect ( ( ) => {
47
+ if ( audioRef . current ) {
48
+ audioRef . current . pause ( ) ;
49
+ audioRef . current . load ( ) ;
50
+ audioRef . current . play ( ) ;
51
+ }
52
+ } , [ source ] ) ;
53
+
45
54
useEffect ( ( ) => {
46
55
if (
47
56
destinationLatitude &&
@@ -132,9 +141,7 @@ function RoutePage() {
132
141
( poi ) => destinationPoint [ 0 ] . id === poi . id
133
142
) ;
134
143
setDestinationIndex ( index ) ;
135
- setDestination ( destinationPoint [ 0 ] ) ;
136
144
setNextUnlockableId ( destinationPoint [ 0 ] . id ) ;
137
-
138
145
setDestinationLatitude ( destinationPoint [ 0 ] . latitude ) ;
139
146
setDestinationLongitude ( destinationPoint [ 0 ] . longitude ) ;
140
147
}
@@ -144,6 +151,9 @@ function RoutePage() {
144
151
} , [ pointsOfInterest ] ) ;
145
152
146
153
if ( selectedRoute === null ) return null ;
154
+
155
+ const { fileUrl } = useContext ( ApiEndpointContext ) ;
156
+
147
157
return (
148
158
< div className = "flex flex-col place-items-start pb-28" >
149
159
< BackButton > Afslut</ BackButton >
@@ -157,55 +167,60 @@ function RoutePage() {
157
167
index = { index + 1 }
158
168
destinationChanged = { destinationChanged }
159
169
nextUnlockableId = { nextUnlockableId }
170
+ setSource = { setSource }
160
171
/>
161
172
) ) }
162
173
</ div >
163
174
{ /* TODO: Make room for audio player below when playing */ }
164
- < div className = "fixed left-3 bottom-3 right-3 bg-zinc-200 dark:bg-zinc-700 flex gap-3 rounded-lg p-3 pb-15 divide-x dark:divide-zinc-200/5" >
165
- < div >
166
- < div className = "text-sm text-bold" >
167
- Afstand til del
168
- < span className = "ml-1 px-2 font-bold rounded-full bg-emerald-700 text-zinc-100 text-sm" >
169
- { destinationIndex + 1 }
170
- </ span >
175
+ < div className = "fixed flex flex-col left-3 bottom-3 right-3 bg-zinc-200 dark:bg-zinc-700 gap-3 rounded-lg p-3 pb-15 divide-x dark:divide-zinc-200/5" >
176
+ < div className = "flex flex-row justify-between" >
177
+ < div >
178
+ < div className = "text-sm text-bold" >
179
+ Afstand til del
180
+ < span className = "ml-1 px-2 font-bold rounded-full bg-emerald-700 text-zinc-100 text-sm" >
181
+ { destinationIndex + 1 }
182
+ </ span >
183
+ </ div >
184
+ < div className = "" >
185
+ { destinationDistance && `${ destinationDistance } meter` }
186
+ </ div >
171
187
</ div >
172
- < div className = "" >
173
- { destinationDistance && `${ destinationDistance } meter` }
188
+ < div className = "pl-3" >
189
+ { /* TODO: Make this check for compass */ }
190
+ { ( ! orientation || ! angle ) && (
191
+ < button
192
+ className = "bg-zinc-700 dark:bg-zinc-200 dark:text-zinc-800 rounded text-sm py-1 px-3"
193
+ type = "button"
194
+ onClick = { ( ) => startWaypointer ( ) }
195
+ >
196
+ Vis mig vej
197
+ </ button >
198
+ ) }
199
+ { /* TODO: Make this check for compass */ }
200
+ { orientation && angle && (
201
+ < div >
202
+ < div className = "flex justify-between" >
203
+ < span className = "text-sm text-bold mr-5" > Retning</ span >
204
+ < span className = "w-1/2" >
205
+ < LocationArrow
206
+ className = "inline w-5"
207
+ style = { {
208
+ transform : `rotate(${ - rotation } deg)` ,
209
+ } }
210
+ />
211
+ </ span >
212
+ </ div >
213
+ </ div >
214
+ ) }
174
215
</ div >
175
216
</ div >
176
- < div className = "pl-3" >
177
- { /* TODO: Make this check for compass */ }
178
- { ( ! orientation || ! angle ) && (
179
- < button
180
- className = "bg-zinc-700 dark:bg-zinc-200 dark:text-zinc-800 rounded text-sm py-1 px-3"
181
- type = "button"
182
- onClick = { ( ) => startWaypointer ( ) }
183
- >
184
- Vis mig vej
185
- </ button >
186
- ) }
187
- { /* TODO: Make this check for compass */ }
188
- { orientation && angle && (
189
- < div >
190
- < div className = "flex justify-between mb-3" >
191
- < span className = "text-sm text-bold" > Retning</ span >
192
- < span className = "w-1/2" >
193
- < LocationArrow
194
- className = "inline w-5"
195
- style = { {
196
- transform : `rotate(${ - rotation } deg)` ,
197
- } }
198
- />
199
- </ span >
200
- </ div >
201
- { /* <div className="text-xs text-zinc-500">
202
- Lat: {userLatitude}/{latitude}
203
- </div>
204
- <div className="text-xs text-zinc-500">
205
- Long: {userLongitude}/{longitude}
206
- </div> */ }
207
- </ div >
208
- ) }
217
+ < div >
218
+ < audio
219
+ className = "w-full"
220
+ ref = { audioRef }
221
+ controls
222
+ src = { `${ fileUrl } ${ source } ` }
223
+ />
209
224
</ div >
210
225
</ div >
211
226
< div ref = { bottomRef } />
0 commit comments