Enable favouriting comments
This commit is contained in:
parent
3d22ed71c7
commit
7968aa2ffc
|
@ -213,7 +213,8 @@ const CommentJsx = (props) => {
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
<TouchableOpacity>
|
<TouchableOpacity
|
||||||
|
onPress = { props.onFavourite(props.data) }>
|
||||||
<Image
|
<Image
|
||||||
style = { [styles.heart, styles.action] }
|
style = { [styles.heart, styles.action] }
|
||||||
source = { activeOrNot(props.data.favourited, packs.favourited) } />
|
source = { activeOrNot(props.data.favourited, packs.favourited) } />
|
||||||
|
@ -272,6 +273,35 @@ const ViewCommentsJsx = (props) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const _onFavouriteFactory = (data) => {
|
||||||
|
return async () => {
|
||||||
|
if(!data.favourited) {
|
||||||
|
await requests.favouriteStatus(
|
||||||
|
state.instance,
|
||||||
|
data.id,
|
||||||
|
state.accessToken
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
await requests.unfavouriteStatus(
|
||||||
|
state.instance,
|
||||||
|
data.id,
|
||||||
|
state.accessToken
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch the updated context to rerender the page
|
||||||
|
const newContext = await requests.fetchStatusContext(
|
||||||
|
state.instance,
|
||||||
|
state.postData.id,
|
||||||
|
state.accessToken,
|
||||||
|
);
|
||||||
|
|
||||||
|
setState({...state,
|
||||||
|
descendants: threadify(newContext.descendants),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const _handleCancelSubReply = () => {
|
const _handleCancelSubReply = () => {
|
||||||
setState({...state,
|
setState({...state,
|
||||||
inReplyTo: {
|
inReplyTo: {
|
||||||
|
@ -323,6 +353,7 @@ const ViewCommentsJsx = (props) => {
|
||||||
? <View>
|
? <View>
|
||||||
<View style = { styles.parentPost }>
|
<View style = { styles.parentPost }>
|
||||||
<CommentJsx
|
<CommentJsx
|
||||||
|
onFavourite = { _onFavouriteFactory }
|
||||||
onReply = { _onReplyFactory }
|
onReply = { _onReplyFactory }
|
||||||
data = { state.postData } />
|
data = { state.postData } />
|
||||||
</View>
|
</View>
|
||||||
|
@ -334,6 +365,7 @@ const ViewCommentsJsx = (props) => {
|
||||||
return (
|
return (
|
||||||
<View key = { i }>
|
<View key = { i }>
|
||||||
<CommentJsx
|
<CommentJsx
|
||||||
|
onFavourite = { _onFavouriteFactory }
|
||||||
onReply = { _onReplyFactory }
|
onReply = { _onReplyFactory }
|
||||||
data = { comment }/>
|
data = { comment }/>
|
||||||
{
|
{
|
||||||
|
@ -343,6 +375,7 @@ const ViewCommentsJsx = (props) => {
|
||||||
key = { j }
|
key = { j }
|
||||||
style = { styles.sub }>
|
style = { styles.sub }>
|
||||||
<CommentJsx
|
<CommentJsx
|
||||||
|
onFavourite = { _onFavouriteFactory }
|
||||||
onReply = { _onReplyFactory }
|
onReply = { _onReplyFactory }
|
||||||
data = { sub }/>
|
data = { sub }/>
|
||||||
</View>
|
</View>
|
||||||
|
|
Loading…
Reference in New Issue