From 7968aa2ffc61ec848e34ad2ee83b0e91bdcb1584 Mon Sep 17 00:00:00 2001 From: natjms Date: Sat, 22 May 2021 16:49:05 -0300 Subject: [PATCH] Enable favouriting comments --- src/components/pages/view-comments.js | 35 ++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/components/pages/view-comments.js b/src/components/pages/view-comments.js index 282f797..7a03ed6 100644 --- a/src/components/pages/view-comments.js +++ b/src/components/pages/view-comments.js @@ -213,7 +213,8 @@ const CommentJsx = (props) => { - + @@ -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 = () => { setState({...state, inReplyTo: { @@ -323,6 +353,7 @@ const ViewCommentsJsx = (props) => { ? @@ -334,6 +365,7 @@ const ViewCommentsJsx = (props) => { return ( { @@ -343,6 +375,7 @@ const ViewCommentsJsx = (props) => { key = { j } style = { styles.sub }>