From f57004d7fa09908ab0e041e79e838db6d4fc14c3 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 29 Apr 2019 12:14:54 -0700 Subject: Adding proper deletes for Post, Community, and Comments. - Fixes #132 - Fixes #108 --- ui/src/components/comment-node.tsx | 9 ++++++--- ui/src/components/inbox.tsx | 1 + ui/src/components/post-listing.tsx | 16 +++++++++++----- ui/src/components/post.tsx | 1 + ui/src/components/sidebar.tsx | 25 ++++++++++++++++++------- ui/src/components/user.tsx | 1 + ui/src/interfaces.ts | 6 ++++++ 7 files changed, 44 insertions(+), 15 deletions(-) (limited to 'ui') 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 { {this.state.showEdit && } {!this.state.showEdit &&
-
+
    {UserService.Instance.user && !this.props.viewOnly && <> @@ -108,7 +108,9 @@ export class CommentNode extends Component { edit
  • - delete + + {!this.props.node.comment.deleted ? 'delete' : 'restore'} +
  • } @@ -252,11 +254,12 @@ export class CommentNode extends Component { 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 { 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 { {post.removed && removed } + {post.deleted && + deleted + } {post.locked && locked } @@ -140,7 +143,7 @@ export class PostListing extends Component { {UserService.Instance.user && this.props.editable &&
    • - {this.props.post.saved ? 'unsave' : 'save'} + {post.saved ? 'unsave' : 'save'}
    • {this.myPost && <> @@ -148,7 +151,9 @@ export class PostListing extends Component { edit
    • - delete + + {!post.deleted ? 'delete' : 'restore'} +
    • } @@ -237,12 +242,13 @@ export class PostListing extends Component { 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 { 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 { {community.removed && removed } + {community.deleted && + deleted + } /c/{community.name}
        @@ -66,7 +69,9 @@ export class Sidebar extends Component { {this.amCreator &&
      • - {/* delete */} + + {!community.deleted ? 'delete' : 'restore'} +
      • } @@ -142,9 +147,18 @@ export class Sidebar extends Component { 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 { 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 { 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/interfaces.ts b/ui/src/interfaces.ts index 8a16de43..1558f7ae 100644 --- a/ui/src/interfaces.ts +++ b/ui/src/interfaces.ts @@ -52,6 +52,7 @@ export interface Community { category_id: number; creator_id: number; removed: boolean; + deleted: boolean; published: string; updated?: string; creator_name: string; @@ -71,6 +72,7 @@ export interface Post { creator_id: number; community_id: number; removed: boolean; + deleted: boolean; locked: boolean; published: string; updated?: string; @@ -96,6 +98,7 @@ export interface Comment { parent_id?: number; content: string; removed: boolean; + deleted: boolean; read: boolean; published: string; updated?: string; @@ -348,6 +351,7 @@ export interface CommunityForm { category_id: number, edit_id?: number; removed?: boolean; + deleted?: boolean; reason?: string; expires?: number; auth?: string; @@ -392,6 +396,7 @@ export interface PostForm { edit_id?: number; creator_id: number; removed?: boolean; + deleted?: boolean; locked?: boolean; reason?: string; auth: string; @@ -424,6 +429,7 @@ export interface CommentForm { edit_id?: number; creator_id: number; removed?: boolean; + deleted?: boolean; reason?: string; read?: boolean; auth: string; -- cgit v1.2.3