1
- import {
2
- DashboardSpeed02Icon ,
3
- EarthIcon ,
4
- Home01SolidIcon ,
5
- LatitudeIcon ,
6
- LongitudeIcon ,
7
- MapsLocation02SolidIcon ,
8
- Rocket01Icon ,
9
- Timer02Icon ,
10
- } from '@assets/icons/icons'
1
+ import { Home01SolidIcon , Location01Icon , MapsLocation02SolidIcon } from '@assets/icons/icons'
11
2
import Btn , { BtnTransparent } from '@components/Button'
12
3
import { Gap12 } from '@components/Gap'
13
4
import { Input } from '@components/Input'
@@ -16,55 +7,68 @@ import { PaddingBottom } from '@components/SafePadding'
16
7
import SettGroup from '@components/Settings/SettGroup'
17
8
import { SettOption } from '@components/Settings/SettOption'
18
9
import SettWrapper from '@components/Settings/SettWrapper'
19
- import { Txt } from '@components/Text '
10
+ import { coordinateNotesStore } from '@screens/CoordinateNotes/coordinateNotesStore '
20
11
import { fetchLocation } from '@screens/CoordinateNotes/lib'
21
12
import { useQuery } from '@tanstack/react-query'
22
13
import { NavProp } from '@utils/types'
23
- import { getLatitude , getLongitude } from '@utils/utils '
14
+ import { useState } from 'react '
24
15
import { View } from 'react-native'
25
16
import { GeoPosition } from 'react-native-geolocation-service'
17
+ import LocationDetails from './LocationDetails'
26
18
27
19
export default function NewCoordinateNotes ( { navigation } : NavProp ) {
28
- const { data, isFetching, refetch } = useQuery ( {
20
+ const [ name , setName ] = useState < string > ( '' )
21
+ const [ description , setDescription ] = useState < string > ( '' )
22
+ const newNote = coordinateNotesStore ( ( state ) => state . newNote )
23
+
24
+ const { data, isFetching, refetch, isPending } = useQuery ( {
29
25
queryFn : fetchLocation ,
30
26
queryKey : [ 'currentLocation' ] ,
31
27
} )
32
28
29
+ const isDisabled = name ?. trim ( ) . length === 0 || isFetching || isPending
30
+
31
+ function handleSave ( ) {
32
+ console . log ( 'Save Location Note' )
33
+ console . log ( name , description , data )
34
+ newNote ( {
35
+ title : name ,
36
+ description,
37
+ location : data as GeoPosition ,
38
+ } )
39
+ navigation . goBack ( )
40
+ }
41
+
33
42
return (
34
43
< SettWrapper
35
44
className = 'flex-1'
36
- // Header={
37
- // <BackHeader
38
- // title={'New Location Note'}
39
- // navigation={navigation}
40
- // Right={
41
- // <Press>
42
- // <SemiBold className='text-sm text-accent'>Save</SemiBold>
43
- // </Press>
44
- // }
45
- // />
46
- // }
47
45
title = { 'New Location Note' }
48
46
>
49
47
< Gap12 className = 'mt-3' >
50
48
< SettGroup title = 'Location Name' >
51
49
< Input
52
- Icon = { < RoundedIcon Icon = { MapsLocation02SolidIcon } className = 'bg-blue-500' /> }
50
+ Icon = { < RoundedIcon Icon = { Location01Icon } className = 'bg-blue-500' /> }
53
51
placeholder = 'Enter a name for this location'
52
+ value = { name }
53
+ onChangeText = { setName }
54
+ autoFocus
54
55
/>
55
56
</ SettGroup >
56
57
< SettGroup title = 'Description' >
57
58
< Input
58
59
placeholder = 'This is a input field with multiple lines. You can type as much as you want.'
59
60
multiline
60
61
numberOfLines = { 10 }
62
+ value = { description }
63
+ onChangeText = { setDescription }
64
+ Icon = { < RoundedIcon Icon = { MapsLocation02SolidIcon } className = 'bg-slate-500' /> }
61
65
/>
62
66
</ SettGroup >
63
67
< SettGroup title = 'Tag' >
64
68
< SettOption
65
69
title = ''
66
70
placeholder = 'Add a tag'
67
- Icon = { < RoundedIcon Icon = { Home01SolidIcon } className = 'bg-blue -500' /> }
71
+ Icon = { < RoundedIcon Icon = { Home01SolidIcon } className = 'bg-rose -500' /> }
68
72
onPress = { ( ) => navigation . navigate ( 'Tags' ) }
69
73
arrow
70
74
/>
@@ -76,60 +80,10 @@ export default function NewCoordinateNotes({ navigation }: NavProp) {
76
80
disabled = { isFetching }
77
81
/>
78
82
< View className = 'px-5' >
79
- < Btn title = { 'Save Location Note' } onPress = { ( ) => navigation . goBack ( ) } />
83
+ < Btn title = { 'Save Location Note' } onPress = { handleSave } disabled = { isDisabled } />
80
84
< PaddingBottom />
81
85
</ View >
82
86
</ Gap12 >
83
87
</ SettWrapper >
84
88
)
85
89
}
86
-
87
- function LocationDetails ( { data } : { data : GeoPosition | undefined } ) {
88
- console . log ( data ?. coords . latitude )
89
- const { coords : { latitude, longitude, accuracy, altitude, altitudeAccuracy, speed } = { } , timestamp } = data || { }
90
-
91
- console . log ( latitude , longitude , accuracy , altitude , altitudeAccuracy , speed , timestamp )
92
-
93
- return (
94
- < >
95
- < Gap12 >
96
- < SettGroup title = 'Location Details' >
97
- < SettOption
98
- title = 'Latitude'
99
- Icon = { < RoundedIcon Icon = { LongitudeIcon } className = 'bg-blue-500' /> }
100
- Right = { < Txt skeleton = { latitude === undefined } > { getLatitude ( latitude || 0 ) } </ Txt > }
101
- />
102
- < SettOption
103
- title = 'Longitude'
104
- Icon = { < RoundedIcon Icon = { LatitudeIcon } className = 'bg-green-500' /> }
105
- Right = { < Txt skeleton = { longitude === undefined } > { getLongitude ( longitude || 0 ) } </ Txt > }
106
- />
107
- < SettOption
108
- title = 'Accuracy'
109
- Icon = { < RoundedIcon Icon = { DashboardSpeed02Icon } className = 'bg-rose-500' /> }
110
- Right = { < Txt skeleton = { accuracy === undefined } > { accuracy ?. toFixed ( 0 ) } m</ Txt > }
111
- />
112
- < SettOption
113
- title = 'Altitude'
114
- Icon = { < RoundedIcon Icon = { EarthIcon } className = 'bg-blue-500' /> }
115
- Right = {
116
- < Txt skeleton = { altitude === undefined } >
117
- { altitude ?. toFixed ( 0 ) } m ± { altitudeAccuracy ?. toFixed ( 0 ) } m
118
- </ Txt >
119
- }
120
- />
121
- < SettOption
122
- title = 'Speed'
123
- Icon = { < RoundedIcon Icon = { Rocket01Icon } className = 'bg-orange-500' /> }
124
- Right = { < Txt skeleton = { speed === undefined } > { speed ?. toFixed ( 0 ) } m/s</ Txt > }
125
- />
126
- < SettOption
127
- title = 'Timestamp'
128
- Icon = { < RoundedIcon Icon = { Timer02Icon } className = 'bg-accent' /> }
129
- Right = { < Txt skeleton = { timestamp === undefined } > { new Date ( timestamp || 0 ) . toLocaleString ( ) } </ Txt > }
130
- />
131
- </ SettGroup >
132
- </ Gap12 >
133
- </ >
134
- )
135
- }
0 commit comments