From: Dessalines Date: Sun, 21 Apr 2019 21:38:57 +0000 (-0700) Subject: Add site editing. X-Git-Url: http://these/git/%22https:/join-lemmy.org/%7BmarkdownHelpUrl%7D?a=commitdiff_plain;h=2a92a5611cfb2caaf0329f485d042cbaedfe0e24;p=lemmy.git Add site editing. - Fixes #96 --- diff --git a/ui/src/components/community-form.tsx b/ui/src/components/community-form.tsx index 14c2a6b8..2d5aa3e7 100644 --- a/ui/src/components/community-form.tsx +++ b/ui/src/components/community-form.tsx @@ -168,7 +168,10 @@ export class CommunityForm extends Component; 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); + } } } diff --git a/ui/src/components/sidebar.tsx b/ui/src/components/sidebar.tsx index 95880448..3644903c 100644 --- a/ui/src/components/sidebar.tsx +++ b/ui/src/components/sidebar.tsx @@ -39,7 +39,10 @@ export class Sidebar extends Component {
{!this.state.showEdit ? this.sidebar() - : + : }
) @@ -206,7 +209,4 @@ export class Sidebar extends Component { i.state.showRemoveDialog = false; i.setState(i.state); } - - - } diff --git a/ui/src/components/site-form.tsx b/ui/src/components/site-form.tsx index 55da1667..9c0f472b 100644 --- a/ui/src/components/site-form.tsx +++ b/ui/src/components/site-form.tsx @@ -24,6 +24,12 @@ export class SiteForm extends Component { constructor(props: any, context: any) { super(props, context); this.state = this.emptyState; + if (this.props.site) { + this.state.siteForm = { + name: this.props.site.name, + description: this.props.site.description, + } + } } componentDidMount() { diff --git a/ui/src/interfaces.ts b/ui/src/interfaces.ts index 23b86074..ec111719 100644 --- a/ui/src/interfaces.ts +++ b/ui/src/interfaces.ts @@ -341,7 +341,7 @@ export interface CommunityForm { description?: string, category_id: number, edit_id?: number; - removed: boolean; + removed?: boolean; reason?: string; expires?: number; auth?: string; diff --git a/ui/src/version.ts b/ui/src/version.ts index cb3fdf37..5651d40f 100644 --- a/ui/src/version.ts +++ b/ui/src/version.ts @@ -1 +1 @@ -export let version: string = "v0.0.3-3-gfe52d59"; \ No newline at end of file +export let version: string = "v0.0.3-11-g9278104"; \ No newline at end of file