Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Tracks saving #271

Merged
merged 148 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 146 commits
Commits
Show all changes
148 commits
Select commit Hold shift + click to select a range
77245ee
wip nav changes to allow displaying modal without changing screen
CDFN Apr 11, 2024
2ba1cea
add custom tab bar icon and label
bohdanprog Apr 11, 2024
733746e
add modal with different options
bohdanprog Apr 11, 2024
6bd0461
tracks poc
CDFN Apr 12, 2024
1f597d7
add check if permission granted, add function to request about permis…
bohdanprog Apr 12, 2024
bef576b
add animation, add function for check permission disable strart track…
bohdanprog Apr 12, 2024
d9dfbde
wip nav changes to allow displaying modal without changing screen
CDFN Apr 11, 2024
9620c12
add custom tab bar icon and label
bohdanprog Apr 11, 2024
1d8da9e
add modal with different options
bohdanprog Apr 11, 2024
7245fe7
tracks poc
CDFN Apr 12, 2024
8773faf
add check if permission granted, add function to request about permis…
bohdanprog Apr 12, 2024
dfa1791
add animation, add function for check permission disable strart track…
bohdanprog Apr 12, 2024
dee33fd
fixed problem with custom modal
bohdanprog Apr 12, 2024
94db2fa
merged
bohdanprog Apr 12, 2024
5e338f7
fix hooks dependencies, user location flick
CDFN Apr 12, 2024
e145973
cleanup
CDFN Apr 12, 2024
5cfeb75
place observations exactly at track line
CDFN Apr 12, 2024
8d398c5
store observations found on track
CDFN Apr 12, 2024
82b5c5c
add check if foreground permission is granted, add gps indicator
bohdanprog Apr 15, 2024
d3c53ea
move gps indicator to map header
bohdanprog Apr 15, 2024
9d125b0
create custom bottom sheet component with clicalbe backdrop
bohdanprog Apr 15, 2024
f1b7ede
add icon to start tracking and stop tracking button
bohdanprog Apr 15, 2024
804f42b
fix hooks dependencies, user location flick
CDFN Apr 12, 2024
d56b2b5
cleanup
CDFN Apr 12, 2024
02bab4b
place observations exactly at track line
CDFN Apr 12, 2024
f8b2a3a
store observations found on track
CDFN Apr 12, 2024
b35b1ec
add check if foreground permission is granted, add gps indicator
bohdanprog Apr 15, 2024
577c6db
move gps indicator to map header
bohdanprog Apr 15, 2024
07f8662
fix bug where observations don't display when there's no tracking line
CDFN Apr 12, 2024
44aae30
cleanup track store naming
CDFN Apr 15, 2024
41c3dd5
extract track layer to separate component
CDFN Apr 15, 2024
ce07f72
correct imports, remove unused ones
CDFN Apr 15, 2024
07aab30
implement user location tooltip
CDFN Apr 15, 2024
b1effbe
Merge remote-tracking branch 'origin/feat/tracking-impl' into feat/tr…
CDFN Apr 15, 2024
39abc58
path drawing fixes
CDFN Apr 16, 2024
a2119fb
add timer indicator to stop tracking modal
bohdanprog Apr 16, 2024
1018be7
Merge branch 'main' of github.com:digidem/CoMapeo-mobile into feat/tr…
bohdanprog Apr 16, 2024
f806152
add show timer indicator in bottom tab bar
bohdanprog Apr 16, 2024
8505add
Merge branch 'feat/tracking-impl' of github.com:digidem/CoMapeo-mobil…
bohdanprog Apr 16, 2024
a5fa8b6
remove tab bar label, changed tabbar height
bohdanprog Apr 16, 2024
c2d4080
save only required data for track path drawing
CDFN Apr 16, 2024
e8172db
move TrackPathLayer to track folder
CDFN Apr 16, 2024
d8327d6
move task definition to different place
CDFN Apr 16, 2024
7d6b48d
fix layers order
CDFN Apr 16, 2024
86ceb3a
create context where we keep timer data
bohdanprog Apr 16, 2024
75728e5
Merge branch 'feat/tracking-impl' of github.com:digidem/CoMapeo-mobil…
bohdanprog Apr 16, 2024
7033d6e
extract types from store to common types
CDFN Apr 16, 2024
5593ed2
pre-review cleanups
CDFN Apr 16, 2024
915f28e
add comment explaining distance calc algo
CDFN Apr 16, 2024
56a0d18
correct import
CDFN Apr 16, 2024
465ea18
use luxon for duration formatting
CDFN Apr 16, 2024
eb40ca0
fix eslint rule
CDFN Apr 16, 2024
d15f719
add translations to gps modal
bohdanprog Apr 16, 2024
2c5eccd
Merge branch 'feat/tracking-impl' of github.com:digidem/CoMapeo-mobil…
bohdanprog Apr 16, 2024
815c42c
add changes to en.json
bohdanprog Apr 16, 2024
d36f508
changed GPS pill
bohdanprog Apr 16, 2024
ed9ce3a
add enum type with tab names,changes check in navigation listener
bohdanprog Apr 16, 2024
312bf28
set default route name to navigation store, use enum names in tabs name
bohdanprog Apr 17, 2024
03d0933
add test case for calculate distance function, rename varialbes
bohdanprog Apr 17, 2024
adba278
changed gps pill padding
bohdanprog Apr 17, 2024
9d28264
using in setCurrentTab function enum
bohdanprog Apr 17, 2024
20a32ba
create save track screen, create discard modal
bohdanprog Apr 17, 2024
78e4a87
add translations
bohdanprog Apr 17, 2024
6fa47da
update calculate distance function
bohdanprog Apr 17, 2024
2b1e4ee
remove comment
bohdanprog Apr 17, 2024
2c7da91
fix problem with timing calculation
bohdanprog Apr 17, 2024
9d5f7e4
improve typing a bit
CDFN Apr 16, 2024
19f4ab9
add shared location context
CDFN Apr 18, 2024
fe1d388
fix problem with gps modal and tab screen
bohdanprog Apr 18, 2024
ebec3c1
change place where we get locaiton, using react.memo to memorize trac…
bohdanprog Apr 18, 2024
213b61d
add back rounding of gps precision
CDFN Apr 18, 2024
4070000
add description option to save track screen
bohdanprog Apr 18, 2024
3be3b22
restore changes in podfile
bohdanprog Apr 18, 2024
6f80c3a
create all fields in save track screen
bohdanprog Apr 18, 2024
e0196dd
add translations
bohdanprog Apr 18, 2024
cd7fc9f
update packages, create hook for creating track
bohdanprog Apr 18, 2024
4497d29
add discard button icon
bohdanprog Apr 18, 2024
2fce41a
update calculate distance function
bohdanprog Apr 17, 2024
7e1dfcc
remove comment
bohdanprog Apr 17, 2024
2be2a76
fix problem with timing calculation
bohdanprog Apr 17, 2024
ea50660
fix problem with gps modal and tab screen
bohdanprog Apr 18, 2024
6139e68
improve typing a bit
CDFN Apr 16, 2024
71bc132
add shared location context
CDFN Apr 18, 2024
9d99998
chore: update Mapeo deps
EvanHahn Apr 18, 2024
7c6d4fa
update libs, wip track saving
CDFN Apr 18, 2024
1494b06
Fix @rollup/plugin-esm-shim bug
EvanHahn Apr 18, 2024
8b5e0dd
Merge branch 'main' of github.com:digidem/CoMapeo-mobile into feat/sa…
bohdanprog Apr 19, 2024
80f6899
Merge branch 'update-mapeo-deps' of github.com:digidem/CoMapeo-mobile…
bohdanprog Apr 19, 2024
9167ea9
changed track description
bohdanprog Apr 19, 2024
6c127b1
fixed problem with GPSmodal
bohdanprog Apr 19, 2024
f1e2971
Merge branch 'feat/tracking-impl' of github.com:digidem/CoMapeo-mobil…
bohdanprog Apr 19, 2024
328e4c6
code quality improvement
CDFN Apr 19, 2024
c9e6199
implement track saving
CDFN Apr 22, 2024
bda1a0f
remove temp initial route
CDFN Apr 22, 2024
08d7d30
remove irrelevant change
CDFN Apr 22, 2024
d3eb761
move BottomSheet to shared directory
CDFN Apr 22, 2024
63068f1
general cleanups
CDFN Apr 22, 2024
d082363
extract inline style to stylesheet
CDFN Apr 22, 2024
a56e14d
remove unused var
CDFN Apr 22, 2024
c73ebda
use cheap-ruler instead own distance calc
CDFN Apr 22, 2024
b4f92a4
Use ellipsis symbol instead triple dot
CDFN Apr 22, 2024
cfc9ab7
add header to tab navigator, fixed problem with navigator in homeHead…
bohdanprog Apr 22, 2024
998808a
rename gpsModal to GPSPermissionModal also renamed other connected co…
bohdanprog Apr 22, 2024
4dfc34d
Merge branch 'main' of github.com:digidem/CoMapeo-mobile into feat/tr…
bohdanprog Apr 23, 2024
255f590
fixed problem with dependency in useTracking hook
bohdanprog Apr 23, 2024
719a83f
Apply review suggestions
CDFN Apr 23, 2024
063f160
remove irrelevant changes to navigation
CDFN Apr 23, 2024
119bf56
rename store from useNvigatorStore to useTabNvigatorStore
bohdanprog Apr 23, 2024
44e0872
Merge branch 'feat/tracking-impl' of github.com:digidem/CoMapeo-mobil…
bohdanprog Apr 23, 2024
b9b5f28
restore changes with GPSPill
bohdanprog Apr 23, 2024
f26c348
Merge branch 'feat/tracking-impl' into feat/save-track
CDFN Apr 23, 2024
b59241a
Merge branch 'feat/tracking-impl' into feat/save-track
CDFN Apr 23, 2024
4aef7bc
rename gps components
bohdanprog Apr 23, 2024
9dbec7f
rename gps components
bohdanprog Apr 23, 2024
4d89a79
fix bug with distance not zeroing, adjust store to type changes
CDFN Apr 23, 2024
f727a51
extract inline style to stylesheet
CDFN Apr 23, 2024
3d97b51
unify keys in queries
CDFN Apr 23, 2024
0cf1cb9
improve i18n
CDFN Apr 23, 2024
f32df4c
fixed issue with not resetitng trackingSince, move SharedLocationCont…
bohdanprog Apr 23, 2024
6eb15e4
changed timer type
bohdanprog Apr 23, 2024
22bbfdf
remove unnecessary props isFocused
bohdanprog Apr 24, 2024
ea50a90
remove navigation cast type to as never, add navigation types
bohdanprog Apr 24, 2024
135c56d
remove unnecessary hook and inline task registration
CDFN Apr 24, 2024
09c3bc3
fixed timer nulable case
bohdanprog Apr 24, 2024
c0283c5
rebase to main
bohdanprog Apr 24, 2024
3de6ddf
Merge branch 'feat/tracking-impl' of github.com:digidem/CoMapeo-mobil…
bohdanprog Apr 24, 2024
da725cb
add another solution to track timer
bohdanprog Apr 24, 2024
bc88c90
Merge branch 'feat/tracking-impl' of github.com:digidem/CoMapeo-mobil…
bohdanprog Apr 24, 2024
6b6fccd
save track notes
CDFN Apr 24, 2024
80457ec
Merge branch 'feat/tracking-impl' into feat/save-track
CDFN Apr 24, 2024
c0e71f6
Merge branch 'main' into feat/save-track
CDFN Apr 24, 2024
2c66b30
Merge branch 'feat/save-track' of github.com:digidem/CoMapeo-mobile i…
bohdanprog Apr 25, 2024
358aa50
Merge branch 'main' into feat/save-track
CDFN Apr 25, 2024
1817157
Merge branch 'main' of github.com:digidem/CoMapeo-mobile into feat/sa…
bohdanprog Apr 28, 2024
3ae8458
revert changes in package.json and package.lock
bohdanprog Apr 28, 2024
3f261a5
revert changes with mapeo/ipc
bohdanprog Apr 28, 2024
1e0efcb
revert changes package.json and package-lock.json
bohdanprog Apr 28, 2024
95bddae
add edit track screen, add update track method
bohdanprog Apr 28, 2024
6854969
Merge branch 'feat/save-track' of github.com:digidem/CoMapeo-mobile i…
bohdanprog Apr 28, 2024
b4afdbe
bring back feature flag, remove unnecessary checks
CDFN Apr 24, 2024
8a47fdf
fixed issue with discard track modal, using already created bottom sh…
bohdanprog Apr 29, 2024
c20cb74
create share component DiscardModal, fixed dependency in useTracking …
bohdanprog Apr 30, 2024
b19e32b
add edit track screen, add update track method
bohdanprog Apr 30, 2024
0fa31af
add edit track screen, add update track method
bohdanprog Apr 30, 2024
524b58a
add back handler on Save Track Screen
bohdanprog Apr 30, 2024
af009b0
changed save track screen, using header from react-native-navigation …
bohdanprog Apr 30, 2024
d73fdba
Merge branch 'main' into feat/save-track
CDFN Apr 30, 2024
d2da3c7
Merge branch 'feat/save-track' of github.com:digidem/CoMapeo-mobile i…
bohdanprog Apr 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,24 @@
"description": "Title of dialog that shows when cancelling a new observation",
"message": "Discard observation?"
},
"Modal.DiscardTrack.description": {
"message": "Your Track will not be saved. This cannot be undone."
},
"Modal.DiscardTrack.title": {
"message": "Discard Track?"
},
"Modal.GPSDisable.button": {
"message": "Enable"
},
"Modal.GPSDisable.defaultButton": {
"message": "Continue Editing"
},
"Modal.GPSDisable.description": {
"message": "To create a Track CoMapeo needs access to your location and GPS."
},
"Modal.GPSDisable.discardButton": {
"message": "Discard Track"
},
"Modal.GPSDisable.title": {
"message": "GPS Disabled"
},
Expand Down Expand Up @@ -426,6 +438,26 @@
"description": "message shown whilst observations are loading",
"message": "Loading… this can take a while after synchronizing with a new device"
},
"screens.SaveTrack.TrackEditView.descriptionPlaceholder": {
"description": "Placeholder for description/notes field",
"message": "What is happening here?"
},
"screens.SaveTrack.TrackEditView.saveTrackCamera": {
"description": "Button label for adding photo",
"message": "Camera"
},
"screens.SaveTrack.TrackEditView.saveTrackDetails": {
"description": "Button label for check details",
"message": "Details"
},
"screens.SaveTrack.TrackEditView.title": {
"description": "Title for new track screen",
"message": "New Track"
},
"screens.SaveTrack.track": {
"description": "Category title for new track screen",
"message": "Track"
},
"screens.Security.obscurePassDescriptonPassNotSet": {
"message": "To use, enable App Passcode"
},
Expand Down
16 changes: 15 additions & 1 deletion src/frontend/Navigation/ScreenGroups/AppScreens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ import {TrackingTabBarIcon} from './TabBar/TrackingTabBarIcon';
import {TabName} from '../types';
import {CameraTabBarIcon} from './TabBar/CameraTabBarIcon';
import {MapTabBarIcon} from './TabBar/MapTabBarIcon';
import {SaveTrackScreen} from '../../screens/MapScreen/track/SaveTrackScreen';
import {InviteDeclined} from '../../screens/Settings/ProjectSettings/YourTeam/InviteDeclined';
import {UnableToCancelInvite} from '../../screens/Settings/ProjectSettings/YourTeam/ReviewAndInvite/UnableToCancelInvite';
import {SharedLocationContextProvider} from '../../contexts/SharedLocationContext';
import {
SyncScreen,
createNavigationOptions as createSyncNavOptions,
Expand Down Expand Up @@ -139,6 +141,7 @@ export type AppList = {
UnableToCancelInvite: InviteProps;
DeviceNameDisplay: undefined;
DeviceNameEdit: undefined;
SaveTrack: undefined;
Sync: undefined;
};

Expand Down Expand Up @@ -208,7 +211,11 @@ export const createDefaultScreenGroup = (
<RootStack.Screen
name="Home"
options={{headerShown: false}}
component={HomeTabs}
children={() => (
<SharedLocationContextProvider>
<HomeTabs />
</SharedLocationContextProvider>
)}
/>
<RootStack.Screen
name="AuthScreen"
Expand Down Expand Up @@ -360,6 +367,13 @@ export const createDefaultScreenGroup = (
component={GpsModal}
options={createGpsModalNavigationOptions({intl})}
/>
<RootStack.Screen
name="SaveTrack"
component={SaveTrackScreen}
options={{
headerShown: false,
}}
/>
<RootStack.Screen
name="InviteDeclined"
component={InviteDeclined}
Expand Down
15 changes: 5 additions & 10 deletions src/frontend/contexts/ExternalProviders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {BottomSheetModalProvider} from '@gorhom/bottom-sheet';
import {AppStackList} from '../Navigation/AppStack';
import {GPSModalContextProvider} from './GPSModalContext';
import {TrackTimerContextProvider} from './TrackTimerContext';
import {SharedLocationContextProvider} from './SharedLocationContext';

type ExternalProvidersProp = {
children: React.ReactNode;
Expand All @@ -29,17 +28,13 @@ export const ExternalProviders = ({
return (
<QueryClientProvider client={queryClient}>
<GestureHandlerRootView style={{flex: 1}}>
<SharedLocationContextProvider>
<TrackTimerContextProvider>
<GPSModalContextProvider>
<TrackTimerContextProvider>
<BottomSheetModalProvider>
<NavigationContainer ref={navRef}>
{children}
</NavigationContainer>
</BottomSheetModalProvider>
</TrackTimerContextProvider>
<NavigationContainer ref={navRef}>
<BottomSheetModalProvider>{children}</BottomSheetModalProvider>
</NavigationContainer>
</GPSModalContextProvider>
</SharedLocationContextProvider>
</TrackTimerContextProvider>
</GestureHandlerRootView>
</QueryClientProvider>
);
Expand Down
55 changes: 55 additions & 0 deletions src/frontend/hooks/server/track.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {
useQueryClient,
useMutation,
useSuspenseQuery,
} from '@tanstack/react-query';
import {useProject} from './projects';
import {TrackValue} from '@mapeo/schema';

export const TRACK_KEY = 'tracks';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
export const TRACK_KEY = 'tracks';
export const TRACKS_KEY = 'tracks';


export function useCreateTrack() {
const queryClient = useQueryClient();
const project = useProject();
return useMutation({
mutationFn: async (params: TrackValue) => {
return project.track.create(params);
},
onSuccess: () => {
queryClient.invalidateQueries({queryKey: [TRACK_KEY]});
},
});
}

export function useTracksQuery() {
const project = useProject();
return useSuspenseQuery({
queryKey: [TRACK_KEY],
queryFn: async () => {
return project.track.getMany();
},
});
}

export function useTrackQuery(docId: string) {
const project = useProject();
return useSuspenseQuery({
queryKey: [TRACK_KEY, docId],
queryFn: async () => {
return project.track.getByDocId(docId);
},
});
}

export function useDeleteTrackMutation() {
const queryClient = useQueryClient();
const project = useProject();
return useMutation({
mutationFn: async (docId: string) => {
return project.track.delete(docId);
},
onSuccess: () => {
queryClient.invalidateQueries({queryKey: [TRACK_KEY]});
},
});
}
11 changes: 9 additions & 2 deletions src/frontend/hooks/tracks/useCurrentTrackStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type TracksStoreState = {
distance: number;
addNewObservation: (observationId: string) => void;
addNewLocations: (locationData: LocationHistoryPoint[]) => void;
clearLocationHistory: () => void;
clearCurrentTrack: () => void;
setTracking: (val: boolean) => void;
} & (
| {
Expand Down Expand Up @@ -54,7 +54,14 @@ export const useCurrentTrackStore = create<TracksStoreState>(set => ({
distance: distance + calculateTotalDistance([lastLocation, ...data]),
};
}),
clearLocationHistory: () => set(() => ({locationHistory: []})),
clearCurrentTrack: () =>
set(() => ({
locationHistory: [],
trackingSince: null,
distance: 0,
isTracking: false,
observations: [],
})),
setTracking: (val: boolean) =>
set(() =>
val
Expand Down
46 changes: 25 additions & 21 deletions src/frontend/hooks/tracks/useTracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {useCallback, useState} from 'react';
import {useCurrentTrackStore} from './useCurrentTrackStore';
import React from 'react';
import {FullLocationData} from '../../sharedTypes/location';
import {useGPSModalContext} from '../../contexts/GPSModalContext';

export const LOCATION_TASK_NAME = 'background-location-task';

Expand All @@ -13,32 +14,34 @@ type LocationCallbackInfo = {
};

export function useTracking() {
const {bottomSheetRef} = useGPSModalContext();
const [loading, setLoading] = useState(false);
const addNewLocations = useCurrentTrackStore(state => state.addNewLocations);
const setTracking = useCurrentTrackStore(state => state.setTracking);
const isTracking = useCurrentTrackStore(state => state.isTracking);

const addNewTrackLocations = useCallback(
({data, error}: LocationCallbackInfo) => {
if (error) {
console.error('Error while processing location update callback', error);
}
if (data?.locations) {
addNewLocations(
data.locations.map(loc => ({
latitude: loc.coords.latitude,
longitude: loc.coords.longitude,
timestamp: loc.timestamp,
})),
);
}
},
[addNewLocations],
);

React.useEffect(() => {
TaskManager.defineTask(LOCATION_TASK_NAME, addNewTrackLocations);
}, [addNewTrackLocations]);
TaskManager.defineTask(
LOCATION_TASK_NAME,
({data, error}: LocationCallbackInfo) => {
if (error) {
console.error(
'Error while processing location update callback',
error,
);
}
if (data?.locations) {
addNewLocations(
data.locations.map(loc => ({
latitude: loc.coords.latitude,
longitude: loc.coords.longitude,
timestamp: loc.timestamp,
})),
);
}
},
);
}, [addNewLocations]);

const startTracking = useCallback(async () => {
if (isTracking) {
Expand All @@ -60,8 +63,9 @@ export function useTracking() {

const cancelTracking = useCallback(async () => {
await Location.stopLocationUpdatesAsync(LOCATION_TASK_NAME);
bottomSheetRef.current?.close();
setTracking(false);
}, [setTracking]);
}, [bottomSheetRef, setTracking]);

return {isTracking, startTracking, cancelTracking, loading};
}
18 changes: 18 additions & 0 deletions src/frontend/images/Track.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/frontend/images/camera.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/frontend/images/close.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions src/frontend/images/delete.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/frontend/images/details.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading