@@ -5,11 +5,48 @@ import color from "../config/color";
5
5
import ToggleButton from "./ToggleButton" ;
6
6
import OrderBox from "./OrderBox" ;
7
7
import * as Location from "expo-location" ;
8
+ import { DriverContext } from "../context/Context" ;
9
+ import MapView from "./MapView/MapView" ;
8
10
11
+ const DashboardContent = ( navigation ) => {
9
12
10
- const DashboardContent = ( ) => {
11
-
13
+ const [ location , setLocation ] = useState ( null )
14
+ const { getOrders , token , orderList , updateOrderStatus } = useContext ( DriverContext ) ;
12
15
16
+
17
+ useEffect ( ( ) => {
18
+ const getLocation = async ( ) => {
19
+ let { status } = await Location . requestForegroundPermissionsAsync ( ) ;
20
+ if ( status !== "granted" ) {
21
+ console . log ( "Permission denied" ) ;
22
+ return ;
23
+ }
24
+
25
+ try {
26
+ let location = await Location . getLastKnownPositionAsync ( { } ) ;
27
+ if ( location ) {
28
+ console . log ( "Got location" ) ;
29
+ const { latitude, longitude } = location . coords ;
30
+ // updateUserLocation(longitude, latitude);
31
+ setLocation ( [ latitude , longitude ] ) ;
32
+ } else {
33
+ console . log ( "Didn't get location" ) ;
34
+ const defaultLatitude = 9.2656466 ;
35
+ const defaultLongitude = 76.8089454 ;
36
+ // updateUserLocation(defaultLongitude, defaultLatitude);
37
+ setLocation ( [ defaultLatitude , defaultLongitude ] ) ;
38
+ }
39
+ } catch ( error ) {
40
+ console . error ( "Error getting location:" , error ) ;
41
+ const defaultLatitude = 9.2656466 ;
42
+ const defaultLongitude = 76.8089454 ;
43
+ // updateUserLocation(defaultLongitude, defaultLatitude);
44
+ setLocation ( [ defaultLatitude , defaultLongitude ] ) ;
45
+ }
46
+ } ;
47
+ getLocation ( ) ;
48
+ } , [ ] ) ;
49
+
13
50
return (
14
51
< View >
15
52
< View style = { { justifyContent : "center" } } >
@@ -20,18 +57,21 @@ const DashboardContent = () => {
20
57
< Text style = { styles . statustext } > Status</ Text >
21
58
</ View >
22
59
</ View >
23
-
60
+
24
61
< View >
25
- < OrderBox
62
+ < OrderBox navigation = { navigation }
26
63
userimg = { require ( "../assets/girl.jpg" ) }
27
- name = "SERENA"
28
- location = "10.110.21.22"
29
- fuel = "PETROL"
30
- litre = "2"
64
+ name = { orderList [ 0 ] . userInfo . name }
65
+ litre = { orderList [ 0 ] . fuelAmount }
66
+ fuel = { orderList [ 0 ] . fuelType }
67
+ phone = { orderList [ 0 ] . userInfo . phoneNumber }
31
68
distance = "10"
32
69
/>
33
- { /* for map view */ }
34
-
70
+ </ View >
71
+ < View style = { { paddingTop : 23 ,
72
+ paddingLeft : 10 ,
73
+ height : 500 , } } >
74
+ < MapView location = { location } />
35
75
</ View >
36
76
</ View >
37
77
) ;
0 commit comments