Enable reblogging

This commit is contained in:
Nat 2021-05-22 11:45:01 -03:00
parent 1cc44eae7f
commit 1e2ec90026
3 changed files with 35 additions and 2 deletions

View File

@ -52,14 +52,14 @@ const PostActionBarJsx = (props) => {
<PostActionJsx <PostActionJsx
field = "reblogged" field = "reblogged"
pack = { icons.reblog } pack = { icons.reblog }
reblogged = { props.reblogged } active = { props.reblogged }
onPress = { props.onReblog }/> onPress = { props.onReblog }/>
<PostActionJsx <PostActionJsx
field = "bookmarked" field = "bookmarked"
pack = { icons.bookmark } pack = { icons.bookmark }
last = { true } last = { true }
bookmarked = { props.bookmarked } active = { props.bookmarked }
onPress = { props.onBookmark } /> onPress = { props.onBookmark } />
</View> </View>
) )

View File

@ -139,6 +139,7 @@ export const RawPostJsx = (props) => {
reblogged = { props.data.reblogged } reblogged = { props.data.reblogged }
bookmarked = { false } bookmarked = { false }
onFavourite = { props.onFavourite } onFavourite = { props.onFavourite }
onReblog = { props.onReblog }
onBookmark = { props.onBookmark } /> onBookmark = { props.onBookmark } />
<View style = { styles.caption }> <View style = { styles.caption }>
<Text> <Text>
@ -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 ( return (
<View> <View>
{ state.loaded ? { state.loaded ?
@ -234,6 +257,7 @@ export const PostByDataJsx = (props) => {
data = { state.data } data = { state.data }
dimensions = { state.dimensions } dimensions = { state.dimensions }
onFavourite = { _handleFavourite } onFavourite = { _handleFavourite }
onReblog = { _handleReblog }
navigation = { props.navigation }/> navigation = { props.navigation }/>
: <View></View> } : <View></View> }
</View> </View>

View File

@ -107,6 +107,15 @@ export async function unfavouriteStatus(domain, id, token) {
return resp.json(); 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) { export async function fetchFollowing(domain, id, token) {
const resp = await get(`https://${domain}/api/v1/accounts/${id}/following`, token); const resp = await get(`https://${domain}/api/v1/accounts/${id}/following`, token);
return resp.json(); return resp.json();