diff --git a/src/components/posts/post-action-bar.js b/src/components/posts/post-action-bar.js index 2cc2326..6621877 100644 --- a/src/components/posts/post-action-bar.js +++ b/src/components/posts/post-action-bar.js @@ -52,14 +52,14 @@ const PostActionBarJsx = (props) => { ) diff --git a/src/components/posts/post.js b/src/components/posts/post.js index 884e87a..cdca69a 100644 --- a/src/components/posts/post.js +++ b/src/components/posts/post.js @@ -139,6 +139,7 @@ export const RawPostJsx = (props) => { reblogged = { props.data.reblogged } bookmarked = { false } onFavourite = { props.onFavourite } + onReblog = { props.onReblog } onBookmark = { props.onBookmark } /> @@ -227,6 +228,28 @@ export const PostByDataJsx = (props) => { }); }; + const _handleReblog = async () => { + let newStatus; + + if (!state.data.reblogged) { + newStatus = await requests.reblogStatus( + state.instance, + state.data.id, + state.accessToken + ); + } else { + newStatus = await requests.unreblogStatus( + state.instance, + state.data.id, + state.accessToken + ); + } + + setState({...state, + data: newStatus, + }); + }; + return ( { state.loaded ? @@ -234,6 +257,7 @@ export const PostByDataJsx = (props) => { data = { state.data } dimensions = { state.dimensions } onFavourite = { _handleFavourite } + onReblog = { _handleReblog } navigation = { props.navigation }/> : } diff --git a/src/requests.js b/src/requests.js index 8caae66..25f3af6 100644 --- a/src/requests.js +++ b/src/requests.js @@ -107,6 +107,15 @@ export async function unfavouriteStatus(domain, id, token) { return resp.json(); } +export async function reblogStatus(domain, id, token) { + const resp = await post(`https://${domain}/api/v1/statuses/${id}/reblog`, token); + return resp.json(); +} + +export async function unreblogStatus(domain, id, token) { + const resp = await post(`https://${domain}/api/v1/statuses/${id}/unreblog`, token); + return resp.json(); +} export async function fetchFollowing(domain, id, token) { const resp = await get(`https://${domain}/api/v1/accounts/${id}/following`, token); return resp.json();