From 2a92a5611cfb2caaf0329f485d042cbaedfe0e24 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sun, 21 Apr 2019 14:38:57 -0700 Subject: Add site editing. - Fixes #96 --- ui/src/components/main.tsx | 85 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 69 insertions(+), 16 deletions(-) (limited to 'ui/src/components/main.tsx') diff --git a/ui/src/components/main.tsx b/ui/src/components/main.tsx index c64773f3..0687ffbc 100644 --- a/ui/src/components/main.tsx +++ b/ui/src/components/main.tsx @@ -1,10 +1,11 @@ -import { Component } from 'inferno'; +import { Component, linkEvent } from 'inferno'; import { Link } from 'inferno-router'; import { Subscription } from "rxjs"; import { retryWhen, delay, take } from 'rxjs/operators'; -import { UserOperation, CommunityUser, GetFollowedCommunitiesResponse, ListCommunitiesForm, ListCommunitiesResponse, Community, SortType, GetSiteResponse, ListingType } from '../interfaces'; +import { UserOperation, CommunityUser, GetFollowedCommunitiesResponse, ListCommunitiesForm, ListCommunitiesResponse, Community, SortType, GetSiteResponse, ListingType, SiteResponse } from '../interfaces'; import { WebSocketService, UserService } from '../services'; import { PostListings } from './post-listings'; +import { SiteForm } from './site-form'; import { msgOp, repoUrl, mdToHtml } from '../utils'; @@ -16,6 +17,7 @@ interface MainState { subscribedCommunities: Array; trendingCommunities: Array; site: GetSiteResponse; + showEditSite: boolean; loading: boolean; } @@ -40,6 +42,7 @@ export class Main extends Component { admins: [], banned: [], }, + showEditSite: false, loading: true } @@ -68,6 +71,8 @@ export class Main extends Component { } WebSocketService.Instance.listCommunities(listCommunitiesForm); + + this.handleEditCancel = this.handleEditCancel.bind(this); } componentWillUnmount() { @@ -87,16 +92,16 @@ export class Main extends Component {
{this.trendingCommunities()} {UserService.Instance.user && this.state.subscribedCommunities.length > 0 && -
-
Subscribed forums
-
    - {this.state.subscribedCommunities.map(community => -
  • {community.community_name}
  • - )} -
-
+
+
Subscribed forums
+
    + {this.state.subscribedCommunities.map(community => +
  • {community.community_name}
  • + )} +
+
} - {this.landing()} + {this.sidebar()}
} @@ -118,17 +123,39 @@ export class Main extends Component { ) } - landing() { + sidebar() { return (
-
{`${this.state.site.site.name}`}
-
    + {!this.state.showEditSite ? + this.siteInfo() : + + } + {this.landing()} +
+ ) + } + + siteInfo() { + return ( +
+
{`${this.state.site.site.name}`}
+ {this.canAdmin && +
    +
  • + edit +
  • +
+ } +
  • {this.state.site.site.number_of_users} Users
  • {this.state.site.site.number_of_posts} Posts
  • {this.state.site.site.number_of_comments} Comments
  • Modlog
-
    +
    • admins:
    • {this.state.site.admins.map(admin =>
    • {admin.name}
    • @@ -141,6 +168,13 @@ export class Main extends Component {
} + + ) + } + + landing() { + return ( +
Welcome to LemmyBeta @@ -154,6 +188,20 @@ export class Main extends Component { ) } + get canAdmin(): boolean { + return UserService.Instance.user && this.state.site.admins.map(a => a.id).includes(UserService.Instance.user.id); + } + + handleEditClick(i: Main) { + i.state.showEditSite = true; + i.setState(i.state); + } + + handleEditCancel() { + this.state.showEditSite = false; + this.setState(this.state); + } + parseMessage(msg: any) { console.log(msg); let op: UserOperation = msgOp(msg); @@ -181,7 +229,12 @@ export class Main extends Component { this.state.site.site = res.site; this.state.site.banned = res.banned; this.setState(this.state); - } + } else if (op == UserOperation.EditSite) { + let res: SiteResponse = msg; + this.state.site.site = res.site; + this.state.showEditSite = false; + this.setState(this.state); + } } } -- cgit v1.2.3