mirror of
https://github.com/hyperspacedev/hyperspace
synced 2025-02-14 10:40:42 +01:00
fixes like/retoot bugs
This commit is contained in:
parent
ca23a4927c
commit
f8ec25a050
@ -60,25 +60,6 @@ import ShareMenu from "./PostShareMenu";
|
|||||||
import { emojifyString } from "../../utilities/emojis";
|
import { emojifyString } from "../../utilities/emojis";
|
||||||
import { PollOption } from "../../types/Poll";
|
import { PollOption } from "../../types/Poll";
|
||||||
|
|
||||||
const log = (post: Status, msg = "") => {
|
|
||||||
let {
|
|
||||||
replies_count,
|
|
||||||
reblogs_count,
|
|
||||||
favourites_count,
|
|
||||||
favourited,
|
|
||||||
reblogged,
|
|
||||||
reblog
|
|
||||||
} = post;
|
|
||||||
console.log(msg, {
|
|
||||||
replies_count,
|
|
||||||
reblogs_count,
|
|
||||||
favourites_count,
|
|
||||||
favourited,
|
|
||||||
reblogged,
|
|
||||||
reblog
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
interface IPostProps {
|
interface IPostProps {
|
||||||
post: Status;
|
post: Status;
|
||||||
classes: any;
|
classes: any;
|
||||||
@ -529,29 +510,54 @@ export class Post extends React.Component<any, IPostState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Toggle the status of a post's action and update the state
|
* Tell server a post has been un/favorited and update post state
|
||||||
* @param type Either the "reblog" or "favorite" action
|
* @param post The post to un/favorite
|
||||||
* @param post The post to toggle the status of
|
|
||||||
*/
|
*/
|
||||||
togglePostStatus(type: "reblog" | "favourite", post: Status) {
|
async toggleFavorite(post: Status) {
|
||||||
const shouldUndo = post.favourited || post.reblogged;
|
let action: string = post.favourited ? "unfavourite" : "favourite";
|
||||||
let requestBuilder = `/statuses/${post.id}/${
|
try {
|
||||||
shouldUndo ? "un" : ""
|
// favorite the original post, not the reblog
|
||||||
}${type}`;
|
let resp: any = await this.client.post(
|
||||||
this.client
|
`/statuses/${post.reblog ? post.reblog.id : post.id}/${action}`
|
||||||
.post(requestBuilder)
|
|
||||||
.then((resp: any) => {
|
|
||||||
this.setState({ post: resp.data as Status });
|
|
||||||
})
|
|
||||||
.catch((err: Error) => {
|
|
||||||
this.props.enqueueSnackbar(
|
|
||||||
`Couldn't ${shouldUndo ? "un" : ""}${type} post: ${
|
|
||||||
err.name
|
|
||||||
}`,
|
|
||||||
{ variant: "error" }
|
|
||||||
);
|
);
|
||||||
console.error(err.message);
|
// compensate for slow server update
|
||||||
});
|
if (action === "unfavourite") {
|
||||||
|
resp.data.favourites_count -= 1;
|
||||||
|
// if you unlike both original and reblog before refresh
|
||||||
|
// and the post has only one favorite:
|
||||||
|
if (resp.data.favourites_count < 0) {
|
||||||
|
resp.data.favourites_count = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.setState({ post: resp.data as Status });
|
||||||
|
} catch (e) {
|
||||||
|
this.props.enqueueSnackbar(`Could not ${action} post: ${e.name}`);
|
||||||
|
console.error(e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tell server a post has been un/reblogged and update post state
|
||||||
|
* @param post The post to un/reblog
|
||||||
|
*/
|
||||||
|
async toggleReblog(post: Status) {
|
||||||
|
let action: string =
|
||||||
|
post.reblogged || post.reblog ? "unreblog" : "reblog";
|
||||||
|
try {
|
||||||
|
// modify the original post, not the reblog
|
||||||
|
let resp: any = await this.client.post(
|
||||||
|
`/statuses/${post.reblog ? post.reblog.id : post.id}/${action}`
|
||||||
|
);
|
||||||
|
// compensate for slow server update
|
||||||
|
if (action === "unreblog") {
|
||||||
|
resp.data.reblogs_count -= 1;
|
||||||
|
}
|
||||||
|
if (resp.data.reblog) resp.data = resp.data.reblog;
|
||||||
|
this.setState({ post: resp.data as Status });
|
||||||
|
} catch (e) {
|
||||||
|
this.props.enqueueSnackbar(`Could not ${action} post: ${e.name}`);
|
||||||
|
console.error(e.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
showDeleteDialog() {
|
showDeleteDialog() {
|
||||||
@ -602,7 +608,6 @@ export class Post extends React.Component<any, IPostState> {
|
|||||||
elevation={this.props.threadHeader ? 0 : 1}
|
elevation={this.props.threadHeader ? 0 : 1}
|
||||||
>
|
>
|
||||||
<CardHeader
|
<CardHeader
|
||||||
onClick={() => log(post)}
|
|
||||||
avatar={
|
avatar={
|
||||||
<LinkableAvatar
|
<LinkableAvatar
|
||||||
to={`/profile/${
|
to={`/profile/${
|
||||||
@ -672,34 +677,20 @@ export class Post extends React.Component<any, IPostState> {
|
|||||||
</Typography>
|
</Typography>
|
||||||
<Tooltip title="Favorite">
|
<Tooltip title="Favorite">
|
||||||
<IconButton
|
<IconButton
|
||||||
onClick={() =>
|
onClick={() => this.toggleFavorite(post)}
|
||||||
this.togglePostStatus("favourite", post)
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
<FavoriteIcon
|
<FavoriteIcon
|
||||||
className={
|
className={
|
||||||
post.reblog
|
post.favourited
|
||||||
? post.reblog.favourited
|
|
||||||
? classes.postDidAction
|
|
||||||
: ""
|
|
||||||
: post.favourited
|
|
||||||
? classes.postDidAction
|
? classes.postDidAction
|
||||||
: ""
|
: ""
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Typography>
|
<Typography>{post.favourites_count}</Typography>
|
||||||
{post.reblog
|
|
||||||
? post.reblog.favourites_count
|
|
||||||
: post.favourites_count}
|
|
||||||
</Typography>
|
|
||||||
<Tooltip title="Boost">
|
<Tooltip title="Boost">
|
||||||
<IconButton
|
<IconButton onClick={() => this.toggleReblog(post)}>
|
||||||
onClick={() =>
|
|
||||||
this.togglePostStatus("reblog", post)
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<AutorenewIcon
|
<AutorenewIcon
|
||||||
className={
|
className={
|
||||||
post.reblog
|
post.reblog
|
||||||
|
Loading…
x
Reference in New Issue
Block a user