From 49bf16e7d451388d894f93a994f3bf18571f9594 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sun, 7 Apr 2019 22:19:02 -0700 Subject: Adding user details / overview page. - Fixes #19 --- ui/package.json | 3 + ui/src/components/comment-form.tsx | 93 +++++++++++ ui/src/components/comment-node.tsx | 148 +++++++++++++++++ ui/src/components/comment-nodes.tsx | 30 ++++ ui/src/components/communities.tsx | 12 +- ui/src/components/community-form.tsx | 22 +-- ui/src/components/community.tsx | 12 +- ui/src/components/create-community.tsx | 4 +- ui/src/components/create-post.tsx | 4 +- ui/src/components/home.tsx | 1 - ui/src/components/login.tsx | 20 +-- ui/src/components/main.tsx | 10 +- ui/src/components/moment-time.tsx | 4 +- ui/src/components/navbar.tsx | 7 +- ui/src/components/post-form.tsx | 23 ++- ui/src/components/post-listing.tsx | 21 ++- ui/src/components/post-listings.tsx | 36 ++--- ui/src/components/post.tsx | 279 ++------------------------------- ui/src/components/sidebar.tsx | 10 +- ui/src/components/user.tsx | 264 +++++++++++++++++++++++++++++++ ui/src/index.tsx | 6 +- ui/src/interfaces.ts | 41 ++++- ui/src/main.css | 9 ++ ui/src/services/WebSocketService.ts | 9 +- ui/src/utils.ts | 1 - ui/yarn.lock | 36 +++++ 26 files changed, 740 insertions(+), 365 deletions(-) create mode 100644 ui/src/components/comment-form.tsx create mode 100644 ui/src/components/comment-node.tsx create mode 100644 ui/src/components/comment-nodes.tsx create mode 100644 ui/src/components/user.tsx (limited to 'ui') diff --git a/ui/package.json b/ui/package.json index 1b82db12..b5bb14ef 100644 --- a/ui/package.json +++ b/ui/package.json @@ -15,7 +15,10 @@ }, "engineStrict": true, "dependencies": { + "@types/autosize": "^3.0.6", "@types/js-cookie": "^2.2.1", + "@types/jwt-decode": "^2.2.1", + "@types/markdown-it": "^0.0.7", "autosize": "^4.0.2", "classcat": "^1.1.3", "dotenv": "^6.1.0", diff --git a/ui/src/components/comment-form.tsx b/ui/src/components/comment-form.tsx new file mode 100644 index 00000000..a87dd356 --- /dev/null +++ b/ui/src/components/comment-form.tsx @@ -0,0 +1,93 @@ +import { Component, linkEvent } from 'inferno'; +import { CommentNode as CommentNodeI, CommentForm as CommentFormI } from '../interfaces'; +import { WebSocketService } from '../services'; +import * as autosize from 'autosize'; + +interface CommentFormProps { + postId?: number; + node?: CommentNodeI; + onReplyCancel?(): any; + edit?: boolean; +} + +interface CommentFormState { + commentForm: CommentFormI; + buttonTitle: string; +} + +export class CommentForm extends Component { + + private emptyState: CommentFormState = { + commentForm: { + auth: null, + content: null, + post_id: this.props.node ? this.props.node.comment.post_id : this.props.postId + }, + buttonTitle: !this.props.node ? "Post" : this.props.edit ? "Edit" : "Reply" + } + + constructor(props: any, context: any) { + super(props, context); + + this.state = this.emptyState; + + if (this.props.node) { + if (this.props.edit) { + this.state.commentForm.edit_id = this.props.node.comment.id; + this.state.commentForm.parent_id = this.props.node.comment.parent_id; + this.state.commentForm.content = this.props.node.comment.content; + } else { + // A reply gets a new parent id + this.state.commentForm.parent_id = this.props.node.comment.id; + } + } + } + + componentDidMount() { + autosize(document.querySelectorAll('textarea')); + } + + render() { + return ( +
+
+
+
+