diff options
author | Dessalines <tyhou13@gmx.com> | 2019-04-29 12:14:54 -0700 |
---|---|---|
committer | Dessalines <tyhou13@gmx.com> | 2019-04-29 12:14:54 -0700 |
commit | f57004d7fa09908ab0e041e79e838db6d4fc14c3 (patch) | |
tree | 1c58906673d41712a440da063e4f4856070904de /ui/src/components | |
parent | d13a95da27c847e3f53b0bcf38d77d79f67891ad (diff) |
Adding proper deletes for Post, Community, and Comments.
- Fixes #132
- Fixes #108
Diffstat (limited to 'ui/src/components')
-rw-r--r-- | ui/src/components/comment-node.tsx | 9 | ||||
-rw-r--r-- | ui/src/components/inbox.tsx | 1 | ||||
-rw-r--r-- | ui/src/components/post-listing.tsx | 16 | ||||
-rw-r--r-- | ui/src/components/post.tsx | 1 | ||||
-rw-r--r-- | ui/src/components/sidebar.tsx | 25 | ||||
-rw-r--r-- | ui/src/components/user.tsx | 1 |
6 files changed, 38 insertions, 15 deletions
diff --git a/ui/src/components/comment-node.tsx b/ui/src/components/comment-node.tsx index 0c0fd821..92eda3ad 100644 --- a/ui/src/components/comment-node.tsx +++ b/ui/src/components/comment-node.tsx @@ -92,7 +92,7 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> { {this.state.showEdit && <CommentForm node={node} edit onReplyCancel={this.handleReplyCancel} disabled={this.props.locked} />} {!this.state.showEdit && <div> - <div className="md-div" dangerouslySetInnerHTML={mdToHtml(node.comment.removed ? '*removed*' : node.comment.content)} /> + <div className="md-div" dangerouslySetInnerHTML={mdToHtml(node.comment.removed ? '*removed*' : node.comment.deleted ? '*deleted*' : node.comment.content)} /> <ul class="list-inline mb-1 text-muted small font-weight-bold"> {UserService.Instance.user && !this.props.viewOnly && <> @@ -108,7 +108,9 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> { <span class="pointer" onClick={linkEvent(this, this.handleEditClick)}>edit</span> </li> <li className="list-inline-item"> - <span class="pointer" onClick={linkEvent(this, this.handleDeleteClick)}>delete</span> + <span class="pointer" onClick={linkEvent(this, this.handleDeleteClick)}> + {!this.props.node.comment.deleted ? 'delete' : 'restore'} + </span> </li> </> } @@ -252,11 +254,12 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> { handleDeleteClick(i: CommentNode) { let deleteForm: CommentFormI = { - content: '*deleted*', + content: i.props.node.comment.content, edit_id: i.props.node.comment.id, creator_id: i.props.node.comment.creator_id, post_id: i.props.node.comment.post_id, parent_id: i.props.node.comment.parent_id, + deleted: !i.props.node.comment.deleted, auth: null }; WebSocketService.Instance.editComment(deleteForm); diff --git a/ui/src/components/inbox.tsx b/ui/src/components/inbox.tsx index f4ef2ecd..48a9d366 100644 --- a/ui/src/components/inbox.tsx +++ b/ui/src/components/inbox.tsx @@ -178,6 +178,7 @@ export class Inbox extends Component<any, InboxState> { found.content = res.comment.content; found.updated = res.comment.updated; found.removed = res.comment.removed; + found.deleted = res.comment.deleted; found.upvotes = res.comment.upvotes; found.downvotes = res.comment.downvotes; found.score = res.comment.score; diff --git a/ui/src/components/post-listing.tsx b/ui/src/components/post-listing.tsx index 91d6fd2f..87dac92c 100644 --- a/ui/src/components/post-listing.tsx +++ b/ui/src/components/post-listing.tsx @@ -85,6 +85,9 @@ export class PostListing extends Component<PostListingProps, PostListingState> { {post.removed && <small className="ml-2 text-muted font-italic">removed</small> } + {post.deleted && + <small className="ml-2 text-muted font-italic">deleted</small> + } {post.locked && <small className="ml-2 text-muted font-italic">locked</small> } @@ -140,7 +143,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> { {UserService.Instance.user && this.props.editable && <ul class="list-inline mb-1 text-muted small font-weight-bold"> <li className="list-inline-item mr-2"> - <span class="pointer" onClick={linkEvent(this, this.handleSavePostClick)}>{this.props.post.saved ? 'unsave' : 'save'}</span> + <span class="pointer" onClick={linkEvent(this, this.handleSavePostClick)}>{post.saved ? 'unsave' : 'save'}</span> </li> {this.myPost && <> @@ -148,7 +151,9 @@ export class PostListing extends Component<PostListingProps, PostListingState> { <span class="pointer" onClick={linkEvent(this, this.handleEditClick)}>edit</span> </li> <li className="list-inline-item mr-2"> - <span class="pointer" onClick={linkEvent(this, this.handleDeleteClick)}>delete</span> + <span class="pointer" onClick={linkEvent(this, this.handleDeleteClick)}> + {!post.deleted ? 'delete' : 'restore'} + </span> </li> </> } @@ -237,12 +242,13 @@ export class PostListing extends Component<PostListingProps, PostListingState> { handleDeleteClick(i: PostListing) { let deleteForm: PostFormI = { - body: '', + body: i.props.post.body, community_id: i.props.post.community_id, - name: "deleted", - url: '', + name: i.props.post.name, + url: i.props.post.url, edit_id: i.props.post.id, creator_id: i.props.post.creator_id, + deleted: !i.props.post.deleted, auth: null }; WebSocketService.Instance.editPost(deleteForm); diff --git a/ui/src/components/post.tsx b/ui/src/components/post.tsx index 5483338c..5b0a606c 100644 --- a/ui/src/components/post.tsx +++ b/ui/src/components/post.tsx @@ -244,6 +244,7 @@ export class Post extends Component<any, PostState> { found.content = res.comment.content; found.updated = res.comment.updated; found.removed = res.comment.removed; + found.deleted = res.comment.deleted; found.upvotes = res.comment.upvotes; found.downvotes = res.comment.downvotes; found.score = res.comment.score; diff --git a/ui/src/components/sidebar.tsx b/ui/src/components/sidebar.tsx index a897d3d2..d14ad68c 100644 --- a/ui/src/components/sidebar.tsx +++ b/ui/src/components/sidebar.tsx @@ -56,6 +56,9 @@ export class Sidebar extends Component<SidebarProps, SidebarState> { {community.removed && <small className="ml-2 text-muted font-italic">removed</small> } + {community.deleted && + <small className="ml-2 text-muted font-italic">deleted</small> + } </h5> <Link className="text-muted" to={`/c/${community.name}`}>/c/{community.name}</Link> <ul class="list-inline mb-1 text-muted small font-weight-bold"> @@ -66,7 +69,9 @@ export class Sidebar extends Component<SidebarProps, SidebarState> { </li> {this.amCreator && <li className="list-inline-item"> - {/* <span class="pointer" onClick={linkEvent(this, this.handleDeleteClick)}>delete</span> */} + <span class="pointer" onClick={linkEvent(this, this.handleDeleteClick)}> + {!community.deleted ? 'delete' : 'restore'} + </span> </li> } </> @@ -142,9 +147,18 @@ export class Sidebar extends Component<SidebarProps, SidebarState> { this.setState(this.state); } - // TODO no deleting communities yet - // handleDeleteClick(i: Sidebar, event) { - // } + handleDeleteClick(i: Sidebar) { + event.preventDefault(); + let deleteForm: CommunityFormI = { + name: i.props.community.name, + title: i.props.community.title, + category_id: i.props.community.category_id, + edit_id: i.props.community.id, + deleted: !i.props.community.deleted, + auth: null, + }; + WebSocketService.Instance.editCommunity(deleteForm); + } handleUnsubscribe(communityId: number) { let form: FollowCommunityForm = { @@ -174,9 +188,6 @@ export class Sidebar extends Component<SidebarProps, SidebarState> { return UserService.Instance.user && this.props.admins.map(a => a.id).includes(UserService.Instance.user.id); } - handleDeleteClick() { - } - handleModRemoveShow(i: Sidebar) { i.state.showRemoveDialog = true; i.setState(i.state); diff --git a/ui/src/components/user.tsx b/ui/src/components/user.tsx index bd883c32..b55bf41c 100644 --- a/ui/src/components/user.tsx +++ b/ui/src/components/user.tsx @@ -350,6 +350,7 @@ export class User extends Component<any, UserState> { found.content = res.comment.content; found.updated = res.comment.updated; found.removed = res.comment.removed; + found.deleted = res.comment.deleted; found.upvotes = res.comment.upvotes; found.downvotes = res.comment.downvotes; found.score = res.comment.score; |