-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1279 user profile UI changes for mvp (#1295)
* Follow Button changes * Change non pressable count icons to gray, removed onPress, hide post mvp sections of userprofile * createRelationships api call, follow/unfollow functionality * Unfollow and follow button functionality, refactoring
- Loading branch information
Showing
11 changed files
with
320 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// @flow | ||
|
||
import { | ||
Button | ||
} from "components/SharedComponents"; | ||
import { t } from "i18next"; | ||
import type { Node } from "react"; | ||
import React from "react"; | ||
|
||
type Props = { | ||
following: boolean, | ||
follow: Function, | ||
unfollow: Function, | ||
loading: boolean | ||
}; | ||
|
||
const FollowButton = ( { | ||
following, follow, unfollow, loading | ||
}: Props ): Node => { | ||
if ( following ) { | ||
return ( | ||
<Button | ||
level="primary" | ||
className="grow" | ||
text={t( "UNFOLLOW" )} | ||
onPress={unfollow} | ||
testID="UserProfile.followButton" | ||
/> | ||
); | ||
} | ||
return ( | ||
<Button | ||
level="primary" | ||
className="grow" | ||
loading={loading} | ||
text={t( "FOLLOW" )} | ||
onPress={follow} | ||
testID="UserProfile.followButton" | ||
/> | ||
|
||
); | ||
}; | ||
|
||
export default FollowButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// @flow | ||
|
||
import { createRelationships, updateRelationships } from "api/relationships"; | ||
import type { Node } from "react"; | ||
import React, { useEffect, useState } from "react"; | ||
import { Alert } from "react-native"; | ||
import { useAuthenticatedMutation } from "sharedHooks"; | ||
|
||
import FollowButton from "./FollowButton"; | ||
|
||
type Props = { | ||
userId: number, | ||
relationship: Object, | ||
refetchRelationship: Function, | ||
setShowLoginSheet: Function, | ||
setShowUnfollowSheet: Function, | ||
currentUser: Object | ||
}; | ||
|
||
const FollowButtonContainer = ( { | ||
userId, setShowLoginSheet, setShowUnfollowSheet, | ||
currentUser, relationship, refetchRelationship | ||
}: Props ): Node => { | ||
const [loading, setLoading] = useState( false ); | ||
const [following, setFollowing] = useState( false ); | ||
|
||
useEffect( ( ) => { | ||
if ( relationship?.following === true ) { | ||
setFollowing( true ); | ||
return; | ||
} | ||
setFollowing( false ); | ||
}, [relationship, refetchRelationship] ); | ||
|
||
const createRelationshipsMutation = useAuthenticatedMutation( | ||
( id, optsWithAuth ) => createRelationships( id, optsWithAuth ) | ||
); | ||
|
||
const updateRelationshipsMutation = useAuthenticatedMutation( | ||
( id, optsWithAuth ) => updateRelationships( id, optsWithAuth ) | ||
); | ||
|
||
const createRelationshipsMutate = ( ) => createRelationshipsMutation.mutate( { | ||
relationship: { | ||
friend_id: userId, | ||
following: true | ||
} | ||
}, { | ||
onSuccess: () => { | ||
refetchRelationship(); | ||
setLoading( false ); | ||
}, | ||
onError: error => { | ||
setLoading( false ); | ||
Alert.alert( "Error Following/Unfollowing", error ); | ||
} | ||
} ); | ||
|
||
const updateRelationshipsMutate = ( ) => updateRelationshipsMutation.mutate( { | ||
id: relationship.id, | ||
relationship: { | ||
following: true | ||
} | ||
}, { | ||
onSuccess: () => { | ||
refetchRelationship(); | ||
setLoading( false ); | ||
}, | ||
onError: error => { | ||
setLoading( false ); | ||
Alert.alert( "Error Following/Unfollowing", error ); | ||
} | ||
} ); | ||
|
||
const follow = () => { | ||
if ( relationship ) { | ||
updateRelationshipsMutate(); | ||
} else { | ||
createRelationshipsMutate(); | ||
} | ||
}; | ||
|
||
const followUser = () => { | ||
if ( !currentUser ) { | ||
setShowLoginSheet( true ); | ||
return; | ||
} | ||
setLoading( true ); | ||
follow(); | ||
}; | ||
|
||
const unfollowUser = ( ) => { | ||
if ( !currentUser ) { | ||
setShowLoginSheet( true ); | ||
return; | ||
} | ||
setShowUnfollowSheet( true ); | ||
}; | ||
|
||
return ( | ||
<FollowButton | ||
loading={loading} | ||
following={following} | ||
follow={followUser} | ||
unfollow={unfollowUser} | ||
/> | ||
); | ||
}; | ||
|
||
export default FollowButtonContainer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// @flow | ||
import { updateRelationships } from "api/relationships"; | ||
import WarningSheet from "components/SharedComponents/Sheets/WarningSheet"; | ||
import type { Node } from "react"; | ||
import React from "react"; | ||
import { Alert } from "react-native"; | ||
import { useAuthenticatedMutation, useTranslation } from "sharedHooks"; | ||
|
||
type Props = { | ||
relationship: Object, | ||
refetchRelationship: Function, | ||
setShowUnfollowSheet: Function, | ||
} | ||
|
||
const UnfollowSheet = ( { | ||
relationship, | ||
setShowUnfollowSheet, | ||
refetchRelationship | ||
}: Props ): Node => { | ||
const { t } = useTranslation( ); | ||
|
||
const updateRelationshipsMutation = useAuthenticatedMutation( | ||
( id, optsWithAuth ) => updateRelationships( id, optsWithAuth ) | ||
); | ||
|
||
const unfollowUser = ( ) => updateRelationshipsMutation.mutate( { | ||
id: relationship.id, | ||
relationship: { | ||
following: false | ||
} | ||
}, { | ||
onSuccess: () => { | ||
setShowUnfollowSheet( false ); | ||
refetchRelationship(); | ||
}, | ||
onError: error => { | ||
Alert.alert( "Error Following/Unfollowing", error ); | ||
} | ||
} ); | ||
|
||
return ( | ||
<WarningSheet | ||
handleClose={( ) => setShowUnfollowSheet( false )} | ||
secondButtonText={t( "CANCEL" )} | ||
buttonType="warning" | ||
headerText={t( "UNFOLLOW-USER" )} | ||
buttonText={t( "UNFOLLOW" )} | ||
handleSecondButtonPress={( ) => setShowUnfollowSheet( false )} | ||
confirm={( ) => { | ||
if ( relationship ) unfollowUser(); | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
export default UnfollowSheet; |
Oops, something went wrong.