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
This commit is contained in:
Nat 2021-05-22 13:24:35 -03:00
parent 1e2ec90026
commit eb47557cc4
3 changed files with 36 additions and 4 deletions

View File

@ -44,19 +44,16 @@ const PostActionBarJsx = (props) => {
return (
<View style = { styles.flexContainer }>
<PostActionJsx
field = "favourited"
pack = { icons.heart }
active = { props.favourited }
onPress = { props.onFavourite } />
<PostActionJsx
field = "reblogged"
pack = { icons.reblog }
active = { props.reblogged }
onPress = { props.onReblog }/>
<PostActionJsx
field = "bookmarked"
pack = { icons.bookmark }
last = { true }
active = { props.bookmarked }

View File

@ -137,7 +137,7 @@ export const RawPostJsx = (props) => {
<PostActionBarJsx
favourited = { props.data.favourited }
reblogged = { props.data.reblogged }
bookmarked = { false }
bookmarked = { props.data.bookmarked }
onFavourite = { props.onFavourite }
onReblog = { props.onReblog }
onBookmark = { props.onBookmark } />
@ -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 (
<View>
{ state.loaded ?
@ -258,6 +281,7 @@ export const PostByDataJsx = (props) => {
dimensions = { state.dimensions }
onFavourite = { _handleFavourite }
onReblog = { _handleReblog }
onBookmark = { _handleBookmark }
navigation = { props.navigation }/>
: <View></View> }
</View>

View File

@ -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();