Skip to content

Commit

Permalink
Fixed save route button state
Browse files Browse the repository at this point in the history
  • Loading branch information
lerastromtsova committed May 16, 2020
1 parent b9adfe3 commit 178fbe2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
5 changes: 1 addition & 4 deletions src/features/profile/ProfileScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,8 @@ const ProfileScreen = props => {
}
}

if (props.userInfoInvalid && !props.isFetching) {
props.fetchUserInfo();
}

useEffect(getSavedRoutes, []);
useEffect(props.fetchUserInfo, []);

if (props.isFetching) {
return (
Expand Down
15 changes: 8 additions & 7 deletions src/features/routes/RouteDescriptionScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ const RouteDescriptionScreen = props => {
const styles = useStyleSheet(routeScreenStyles);

const routeId = props.route.params.routeId;
const allRoutes = useSelector(state => routes(state));
const thisRoute = allRoutes.find(item => item.id === routeId);
const thisRoute = useSelector(state => routes(state)).find(
item => item.id === routeId,
);

const [isSaved, setIsSaved] = useState(thisRoute.isSaved);

const allLocations = useSelector(state => locations(state));

Expand Down Expand Up @@ -50,10 +53,12 @@ const RouteDescriptionScreen = props => {
await removeFromSaved(thisRoute.id);
thisRoute.isSaved = false;
updateRoute(thisRoute);
setIsSaved(false);
} else {
await addToSaved(thisRoute.id);
thisRoute.isSaved = true;
updateRoute(thisRoute);
setIsSaved(true);
}
} else {
props.navigation.navigate('Profile');
Expand Down Expand Up @@ -85,11 +90,7 @@ const RouteDescriptionScreen = props => {
renderIcon={style => (
<Icon
{...style}
name={
thisRoute.isSaved
? 'star'
: 'star-outline'
}
name={isSaved ? 'star' : 'star-outline'}
/>
)}
onPress={handleSavePress}
Expand Down

0 comments on commit 178fbe2

Please sign in to comment.