From eb47557cc4ee5824b56d5d27b30ff560f0cb6a4f Mon Sep 17 00:00:00 2001 From: natjms Date: Sat, 22 May 2021 13:24:35 -0300 Subject: [PATCH] Enable bookmarking posts Due to #22, this is definitely broken on Pixelfed instances, though it may or may not otherwise work on Mastodon. Further investigation is needed to determine why this issue persists --- src/components/posts/post-action-bar.js | 3 --- src/components/posts/post.js | 26 ++++++++++++++++++++++++- src/requests.js | 11 +++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/components/posts/post-action-bar.js b/src/components/posts/post-action-bar.js index 6621877..f47c8bc 100644 --- a/src/components/posts/post-action-bar.js +++ b/src/components/posts/post-action-bar.js @@ -44,19 +44,16 @@ const PostActionBarJsx = (props) => { return ( { @@ -250,6 +250,29 @@ export const PostByDataJsx = (props) => { }); }; + const _handleBookmark = async () => { + let newStatus; + + if (!state.data.bookmarked) { + newStatus = await requests.bookmarkStatus( + state.instance, + state.data.id, + state.accessToken + ); + } else { + newStatus = await requests.unbookmarkStatus( + state.instance, + state.data.id, + state.accessToken + ); + } + console.warn(newStatus.bookmarked); + + setState({...state, + data: newStatus, + }); + }; + return ( { state.loaded ? @@ -258,6 +281,7 @@ export const PostByDataJsx = (props) => { dimensions = { state.dimensions } onFavourite = { _handleFavourite } onReblog = { _handleReblog } + onBookmark = { _handleBookmark } navigation = { props.navigation }/> : } diff --git a/src/requests.js b/src/requests.js index 25f3af6..fde88c0 100644 --- a/src/requests.js +++ b/src/requests.js @@ -116,6 +116,17 @@ 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 bookmarkStatus(domain, id, token) { + const resp = await post(`https://${domain}/api/v1/statuses/${id}/bookmark`, token); + return resp.json(); +} + +export async function unbookmarkStatus(domain, id, token) { + const resp = await post(`https://${domain}/api/v1/statuses/${id}/unbookmark`, 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();