mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-22 12:21:13 +00:00
Update so as not to break existing links to comments
This commit is contained in:
parent
61acd39be1
commit
e1cf2b8e02
4 changed files with 58 additions and 27 deletions
|
@ -1194,7 +1194,7 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
|
|||
<>
|
||||
<Link
|
||||
className={classnames}
|
||||
to={`/post/${cv.comment.post_id}/comment/${parentCommentId}`}
|
||||
to={`/comment/${parentCommentId}`}
|
||||
title={title}
|
||||
>
|
||||
<Icon icon="link" classes="icon-inline" />
|
||||
|
|
|
@ -334,7 +334,7 @@ function renderModlogType({ type_, view }: ModlogType) {
|
|||
const mrc = view as ModRemoveCommentView;
|
||||
const {
|
||||
mod_remove_comment: { reason, removed },
|
||||
comment: { id, content, post_id },
|
||||
comment: { id, content },
|
||||
commenter,
|
||||
} = mrc;
|
||||
|
||||
|
@ -342,7 +342,7 @@ function renderModlogType({ type_, view }: ModlogType) {
|
|||
<>
|
||||
<span>{removed ? "Removed " : "Restored "}</span>
|
||||
<span>
|
||||
Comment <Link to={`/post/${post_id}/comment/${id}`}>{content}</Link>
|
||||
Comment <Link to={`/comment/${id}`}>{content}</Link>
|
||||
</span>
|
||||
<span>
|
||||
{" "}
|
||||
|
|
|
@ -198,22 +198,44 @@ export class Post extends Component<any, PostState> {
|
|||
|
||||
const auth = myAuth();
|
||||
const { post_id, comment_id } = this.props.match.params as PostParams;
|
||||
|
||||
this.setState({
|
||||
postRes: await HttpService.client.getPost({
|
||||
id: getIdFromString(post_id),
|
||||
comment_id: getIdFromString(comment_id),
|
||||
const postForm: GetPost = {
|
||||
auth,
|
||||
}),
|
||||
commentsRes: await HttpService.client.getComments({
|
||||
post_id: getIdFromString(post_id),
|
||||
parent_id: getIdFromString(comment_id),
|
||||
};
|
||||
const commentsForm: GetComments = {
|
||||
max_depth: commentTreeMaxDepth,
|
||||
sort: this.state.commentSort,
|
||||
type_: "All",
|
||||
saved_only: false,
|
||||
auth,
|
||||
}),
|
||||
};
|
||||
|
||||
if (post_id) {
|
||||
postForm.id = getIdFromString(post_id);
|
||||
commentsForm.post_id = getIdFromString(post_id);
|
||||
} else {
|
||||
const commentRes = await HttpService.client.getComment({
|
||||
auth,
|
||||
id: getIdFromString(comment_id)!,
|
||||
});
|
||||
|
||||
if (commentRes.state === "success") {
|
||||
const postId = commentRes.data.comment_view.comment.post_id;
|
||||
|
||||
postForm.id = postId;
|
||||
postForm.comment_id = getIdFromString(comment_id);
|
||||
commentsForm.post_id = postId;
|
||||
commentsForm.parent_id = getIdFromString(comment_id);
|
||||
}
|
||||
}
|
||||
|
||||
const [postRes, commentsRes] = await Promise.all([
|
||||
HttpService.client.getPost(postForm),
|
||||
HttpService.client.getComments(commentsForm),
|
||||
]);
|
||||
|
||||
this.setState({
|
||||
postRes,
|
||||
commentsRes,
|
||||
});
|
||||
|
||||
setupTippy();
|
||||
|
@ -234,13 +256,11 @@ export class Post extends Component<any, PostState> {
|
|||
}: InitialFetchRequest): Promise<PostData> {
|
||||
const pathSplit = path.split("/");
|
||||
|
||||
const id = getIdFromString(pathSplit.at(2));
|
||||
const comment_id = getIdFromString(pathSplit.at(4));
|
||||
const pathType = pathSplit.at(1);
|
||||
const id = getIdFromString(pathSplit.at(2))!;
|
||||
|
||||
const postForm: GetPost = {
|
||||
auth,
|
||||
id,
|
||||
comment_id,
|
||||
};
|
||||
|
||||
const commentsForm: GetComments = {
|
||||
|
@ -249,10 +269,23 @@ export class Post extends Component<any, PostState> {
|
|||
type_: "All",
|
||||
saved_only: false,
|
||||
auth,
|
||||
post_id: id,
|
||||
parent_id: comment_id,
|
||||
};
|
||||
|
||||
if (pathType === "post") {
|
||||
postForm.id = id;
|
||||
commentsForm.post_id = id;
|
||||
} else {
|
||||
const commentRes = await client.getComment({ id, auth });
|
||||
|
||||
if (commentRes.state === "success") {
|
||||
const postId = commentRes.data.comment_view.comment.post_id;
|
||||
postForm.id = postId;
|
||||
postForm.comment_id = id;
|
||||
commentsForm.post_id = postId;
|
||||
commentsForm.parent_id = id;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
postRes: await client.getPost(postForm),
|
||||
commentsRes: await client.getComments(commentsForm),
|
||||
|
@ -704,9 +737,7 @@ export class Post extends Component<any, PostState> {
|
|||
const comment = i.state.commentsRes.data.comments.at(0)?.comment;
|
||||
const parentId = getCommentParentId(comment);
|
||||
if (parentId) {
|
||||
i.context.router.history.push(
|
||||
`/post/${comment?.post_id}/comment/${parentId}`,
|
||||
);
|
||||
i.context.router.history.push(`/comment/${parentId}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ export const routes: IRoutePropsWithFetch<Record<string, any>>[] = [
|
|||
fetchInitialData: Communities.fetchInitialData,
|
||||
},
|
||||
{
|
||||
path: `/post/:post_id/comment/:comment_id`,
|
||||
path: `/comment/:comment_id`,
|
||||
component: Post,
|
||||
fetchInitialData: Post.fetchInitialData,
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue