diff --git a/package-lock.json b/package-lock.json index 5cb63b3..0dbf8c5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18277,6 +18277,7 @@ "resolved": "https://registry.npmjs.org/metro-react-native-babel-transformer/-/metro-react-native-babel-transformer-0.59.0.tgz", "integrity": "sha512-1O3wrnMq4NcPQ1asEcl9lRDn/t+F1Oef6S9WaYVIKEhg9m/EQRGVrrTVP+R6B5Eeaj3+zNKbzM8Dx/NWy1hUbQ==", "requires": { + "@babel/core": "^7.0.0", "babel-preset-fbjs": "^3.3.0", "metro-babel-transformer": "0.59.0", "metro-react-native-babel-preset": "0.59.0", diff --git a/src/components/pages/view-comments.js b/src/components/pages/view-comments.js index aba42e1..396b9b1 100644 --- a/src/components/pages/view-comments.js +++ b/src/components/pages/view-comments.js @@ -177,7 +177,7 @@ const CommentJsx = (props) => { { + onPress = { props.onFavouriteFactory(props.data) }> { { props.profile.acct == props.data.account.acct ? <> + text = "Delete" + onSelect = { + props.onDeleteFactory(props.data.id) + } /> : <> - - - + + } @@ -273,7 +282,22 @@ const ViewCommentsJsx = (props) => { return threadify(descendants); } - const _onReplyFactory = (acct, id) => { + const _hideStatus = id => { + /* + * Instead of waiting for the server to register that a status + * shouldn't be retrieved next time the context is fetched, it's more + * efficient to just remove it on the client side. + * + * Returns a new collection of threads without the comment with the + * given id + */ + + return state.descendants.map(thread => + thread.filter(comment => comment.id != id) + ).filter(thread => thread.length > 0); + }; + + const onReplyFactory = (acct, id) => { return () => { setState({...state, inReplyTo: { @@ -284,7 +308,7 @@ const ViewCommentsJsx = (props) => { } }; - const _onFavouriteFactory = (data) => { + const onFavouriteFactory = (data) => { return async () => { if(!data.favourited) { await requests.favouriteStatus( @@ -306,28 +330,24 @@ const ViewCommentsJsx = (props) => { } } - const _onDeleteFactory = data => { - return async () => { - await requests.deleteStatus( - state.instance, - data.id, - state.accessToken, - ); + // Returns a function that returns a callback for a context menu option + // It's not every day you get to use third order functions + const _onModerateFactory = request => id => async () => { + await request( + state.instance, + id, + state.accessToken, + ); - // It appears that it takes a moment for the Context of a - // post to register that a comment has been deleted, so instead - // of waiting for it, it's more efficient to just drop the comment - // on the client side. - const newThreads = state.descendants.map(thread => - thread.filter(comment => comment.id != data.id) - ).filter(thread => thread.length > 0); - - setState({...state, - descendants: newThreads, - }); - }; + setState({...state, + descendants: _hideStatus(id), + }); }; + const onDeleteFactory = _onModerateFactory(requests.deleteStatus); + const onMuteFactory = _onModerateFactory(requests.muteAccount); + const onBlockFactory = _onModerateFactory(requests.blockAccount); + const _handleCancelSubReply = () => { setState({...state, inReplyTo: { @@ -366,9 +386,11 @@ const ViewCommentsJsx = (props) => { + onFavouriteFactory = { onFavouriteFactory } + onReplyFactory = { onReplyFactory } + onMuteFactory = { onMuteFactory } + onBlockFactory = { onBlockFactory } + onDeleteFactory = { onDeleteFactory } /> ); return (