Hiding create community button. Fixes #754

This commit is contained in:
Dessalines 2022-09-20 23:15:39 -04:00
parent 65fe98659b
commit a120357af8
3 changed files with 12 additions and 9 deletions

View file

@ -21,6 +21,7 @@ import { UserService, WebSocketService } from "../../services";
import { import {
amAdmin, amAdmin,
auth, auth,
canCreateCommunity,
donateLemmyUrl, donateLemmyUrl,
isBrowser, isBrowser,
notifyComment, notifyComment,
@ -270,7 +271,7 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
{i18n.t("create_post")} {i18n.t("create_post")}
</NavLink> </NavLink>
</li> </li>
{this.canCreateCommunity && ( {canCreateCommunity(this.props.siteRes) && (
<li class="nav-item"> <li class="nav-item">
<NavLink <NavLink
to="/create_community" to="/create_community"
@ -524,13 +525,6 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
return amAdmin(Some(this.props.siteRes.admins)); return amAdmin(Some(this.props.siteRes.admins));
} }
get canCreateCommunity(): boolean {
let adminOnly = this.props.siteRes.site_view
.map(s => s.site.community_creation_admin_only)
.unwrapOr(false);
return !adminOnly || this.amAdmin;
}
handleToggleExpandNavbar(i: Navbar) { handleToggleExpandNavbar(i: Navbar) {
i.state.expanded = !i.state.expanded; i.state.expanded = !i.state.expanded;
i.setState(i.state); i.setState(i.state);

View file

@ -38,6 +38,7 @@ import {
import { UserService, WebSocketService } from "../../services"; import { UserService, WebSocketService } from "../../services";
import { import {
auth, auth,
canCreateCommunity,
commentsToFlatNodes, commentsToFlatNodes,
createCommentLikeRes, createCommentLikeRes,
createPostLikeFindRes, createPostLikeFindRes,
@ -426,7 +427,8 @@ export class Home extends Component<any, HomeState> {
<div class="card border-secondary mb-3"> <div class="card border-secondary mb-3">
<div class="card-body"> <div class="card-body">
{this.trendingCommunities()} {this.trendingCommunities()}
{this.createCommunityButton()} {canCreateCommunity(this.state.siteRes) &&
this.createCommunityButton()}
{this.exploreCommunitiesButton()} {this.exploreCommunitiesButton()}
</div> </div>
</div> </div>

View file

@ -1483,3 +1483,10 @@ export function myFirstDiscussionLanguageId(
.map(i => i.id) .map(i => i.id)
); );
} }
export function canCreateCommunity(siteRes: GetSiteResponse): boolean {
let adminOnly = siteRes.site_view
.map(s => s.site.community_creation_admin_only)
.unwrapOr(false);
return !adminOnly || amAdmin(Some(siteRes.admins));
}