import { Component, linkEvent } from 'inferno'; import { Link } from 'inferno-router'; import { Community, CommunityUser, FollowCommunityForm } from '../interfaces'; import { WebSocketService, UserService } from '../services'; import { mdToHtml } from '../utils'; import { CommunityForm } from './community-form'; interface SidebarProps { community: Community; moderators: Array; } interface SidebarState { showEdit: boolean; } export class Sidebar extends Component { private emptyState: SidebarState = { showEdit: false } constructor(props: any, context: any) { super(props, context); this.state = this.emptyState; this.handleEditCommunity = this.handleEditCommunity.bind(this); this.handleEditCancel = this.handleEditCancel.bind(this); } render() { return (
{!this.state.showEdit ? this.sidebar() : }
) } sidebar() { let community = this.props.community; return (

{community.title}

/f/{community.name} {this.amMod &&
  • edit
  • {this.amCreator &&
  • {/* delete */}
  • }
}
  • {community.category_name}
  • {community.number_of_subscribers} Subscribers
  • {community.number_of_posts} Posts
  • {community.number_of_comments} Comments
{community.subscribed ? : }
{community.description &&

}

Moderators

{this.props.moderators.map(mod => {mod.user_name} )}
); } handleEditClick(i: Sidebar) { i.state.showEdit = true; i.setState(i.state); } handleEditCommunity() { this.state.showEdit = false; this.setState(this.state); } handleEditCancel() { this.state.showEdit = false; this.setState(this.state); } // TODO no deleting communities yet // handleDeleteClick(i: Sidebar, event) { // } handleUnsubscribe(communityId: number) { let form: FollowCommunityForm = { community_id: communityId, follow: false }; WebSocketService.Instance.followCommunity(form); } handleSubscribe(communityId: number) { let form: FollowCommunityForm = { community_id: communityId, follow: true }; WebSocketService.Instance.followCommunity(form); } private get amCreator(): boolean { return UserService.Instance.loggedIn && this.props.community.creator_id == UserService.Instance.user.id; } private get amMod(): boolean { console.log(this.props.moderators); console.log(this.props); return UserService.Instance.loggedIn && this.props.moderators.map(m => m.user_id).includes(UserService.Instance.user.id); } }