From: Dessalines Date: Fri, 5 Apr 2019 20:22:59 +0000 (-0700) Subject: Adding comment permalinks. X-Git-Url: http://these/git/%7B%60%24%7BwebArchiveUrl%7D/%22%7B%7D/%24%7B%60data:application/%22https:/hacktivis.me/README.es.md?a=commitdiff_plain;h=751cf26be6ff598bd1ef213e4a60df5f0db8ceed;p=lemmy.git Adding comment permalinks. Fixes #18 --- diff --git a/ui/src/components/post-listings.tsx b/ui/src/components/post-listings.tsx index fcc41cf5..98fe8f21 100644 --- a/ui/src/components/post-listings.tsx +++ b/ui/src/components/post-listings.tsx @@ -83,7 +83,7 @@ export class PostListings extends Component 0 ? this.state.posts.map(post => ) - :
No Listings
+ :
No Listings. Subscribe to some forums.
} ) diff --git a/ui/src/components/post.tsx b/ui/src/components/post.tsx index 2a870c4d..e7c66e94 100644 --- a/ui/src/components/post.tsx +++ b/ui/src/components/post.tsx @@ -21,6 +21,7 @@ interface PostState { commentSort: CommentSortType; community: Community; moderators: Array; + scrolled: boolean; } export class Post extends Component { @@ -31,7 +32,8 @@ export class Post extends Component { comments: [], commentSort: CommentSortType.Hot, community: null, - moderators: [] + moderators: [], + scrolled: false } constructor(props, context) { @@ -60,6 +62,15 @@ export class Post extends Component { autosize(document.querySelectorAll('textarea')); } + componentDidUpdate(lastProps: any, lastState: PostState, snapshot: any) { + if (!this.state.scrolled && lastState.comments.length > 0 && window.location.href.includes('#comment-')) { + let id = window.location.hash.split("#")[2]; + var elmnt = document.getElementById(`${id}`); + elmnt.scrollIntoView(); + this.state.scrolled = true; + } + } + render() { return (
@@ -294,7 +305,7 @@ export class CommentNode extends Component { render() { let node = this.props.node; return ( -
+
▲
{node.comment.score}
@@ -336,7 +347,7 @@ export class CommentNode extends Component { }
  • - link + link