Skip to content

Commit

Permalink
fix location favorites not updating
Browse files Browse the repository at this point in the history
  • Loading branch information
bwees committed Nov 19, 2024
1 parent fbbf3ec commit 49173e5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/components/sheets/route_planning/InputRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const InputRoute: React.FC<SheetProps> = ({ sheetRef }) => {
const client = useQueryClient()

// Favorite Location
const { data: favoriteLocations } = useFavoriteLocations();
const { data: favoriteLocations, refetch: refetchFavoriteLocations } = useFavoriteLocations();
const addLocationFavorite = addFavoriteLocationMutation();
const removeLocationFavorite = removeFavoriteLocationMutation();

Expand All @@ -63,6 +63,8 @@ const InputRoute: React.FC<SheetProps> = ({ sheetRef }) => {
} else {
addLocationFavorite.mutate(location)
}

refetchFavoriteLocations()
}

function toggleTimeInputFocused(newValue: boolean) {
Expand Down
5 changes: 4 additions & 1 deletion app/data/storage_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ export const addFavoriteLocationMutation = () => {
mutationFn: async (location: SearchSuggestion) => {
const favorites = await AsyncStorage.getItem('favoriteLocations')

var favoritesArray = JSON.parse(favorites ?? "[]");
var favoritesArray: SearchSuggestion[] = JSON.parse(favorites ?? "[]");

// dont add if its already there
if (favoritesArray.findIndex((fav: SearchSuggestion) => suggestionEqual(fav, location)) != -1) return;

favoritesArray.push(location);

Expand Down

0 comments on commit 49173e5

Please sign in to comment.