import { Component, linkEvent } from 'inferno'; import { Link } from 'inferno-router'; import { Community, CommunityUser } 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, context) { 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}

{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.description &&

}

Moderators

{this.props.moderators.map(mod => {mod.user_name} )}
); } handleEditClick(i: Sidebar, event) { i.state.showEdit = true; i.setState(i.state); } handleEditCommunity(community: Community) { 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) { } 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); } }