From 0469b5f0c7e8c34b02155e29dfe3234cfc8cc305 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 8 Apr 2019 17:04:03 -0700 Subject: [PATCH] Adding user dropdown. - Fixes #54. - Fixed some styling. --- ui/src/components/comment-node.tsx | 2 +- ui/src/components/community.tsx | 2 +- ui/src/components/main.tsx | 4 +-- ui/src/components/navbar.tsx | 49 +++++++++++++++++++++++++----- ui/src/components/post-listing.tsx | 4 +-- ui/src/components/sidebar.tsx | 3 +- ui/src/components/user.tsx | 4 +-- 7 files changed, 51 insertions(+), 17 deletions(-) diff --git a/ui/src/components/comment-node.tsx b/ui/src/components/comment-node.tsx index 55be7621f..1e5376f22 100644 --- a/ui/src/components/comment-node.tsx +++ b/ui/src/components/comment-node.tsx @@ -46,7 +46,7 @@ export class CommentNode extends Component {
  • - {node.comment.creator_name} + {node.comment.creator_name}
  • ( diff --git a/ui/src/components/community.tsx b/ui/src/components/community.tsx index 1ca9a8af7..06504378b 100644 --- a/ui/src/components/community.tsx +++ b/ui/src/components/community.tsx @@ -63,7 +63,7 @@ export class Community extends Component {

    :
    -

    /f/{this.state.community.name}

    +

    {this.state.community.title}

    diff --git a/ui/src/components/main.tsx b/ui/src/components/main.tsx index 54f185e28..477eec65e 100644 --- a/ui/src/components/main.tsx +++ b/ui/src/components/main.tsx @@ -46,10 +46,10 @@ export class Main extends Component { return (
    -
    +
    -
    +

    A Landing message

    {UserService.Instance.loggedIn &&
    diff --git a/ui/src/components/navbar.tsx b/ui/src/components/navbar.tsx index 9754c935e..c4b51e375 100644 --- a/ui/src/components/navbar.tsx +++ b/ui/src/components/navbar.tsx @@ -3,11 +3,24 @@ import { Link } from 'inferno-router'; import { repoUrl } from '../utils'; import { UserService } from '../services'; -export class Navbar extends Component { +interface NavbarState { + isLoggedIn: boolean; + expanded: boolean; + expandUserDropdown: boolean; +} + +export class Navbar extends Component { + + emptyState: NavbarState = { + isLoggedIn: UserService.Instance.loggedIn, + expanded: false, + expandUserDropdown: false + } constructor(props: any, context: any) { super(props, context); - this.state = {isLoggedIn: UserService.Instance.loggedIn, expanded: false}; + this.state = this.emptyState; + this.handleOverviewClick = this.handleOverviewClick.bind(this); // Subscribe to user changes UserService.Instance.sub.subscribe(user => { @@ -50,24 +63,44 @@ export class Navbar extends Component {
); } - handleLogoutClick() { + expandUserDropdown(i: Navbar) { + i.state.expandUserDropdown = !i.state.expandUserDropdown; + i.setState(i.state); + } + + handleLogoutClick(i: Navbar) { + i.state.expandUserDropdown = false; UserService.Instance.logout(); } + handleOverviewClick(i: Navbar) { + i.state.expandUserDropdown = false; + i.setState(i.state); + let userPage = `/user/${UserService.Instance.user.id}`; + i.context.router.history.push(userPage); + } + expandNavbar(i: Navbar) { i.state.expanded = !i.state.expanded; i.setState(i.state); } } + diff --git a/ui/src/components/post-listing.tsx b/ui/src/components/post-listing.tsx index f3145eff5..d52dc937e 100644 --- a/ui/src/components/post-listing.tsx +++ b/ui/src/components/post-listing.tsx @@ -79,7 +79,7 @@ export class PostListing extends Component {
  • by - {post.creator_name} + {post.creator_name} {this.props.showCommunity && to @@ -99,7 +99,7 @@ export class PostListing extends Component {
  • - {post.number_of_comments} Comments + {post.number_of_comments} Comments
{this.myPost && diff --git a/ui/src/components/sidebar.tsx b/ui/src/components/sidebar.tsx index ffc44562a..6fd2bb5c1 100644 --- a/ui/src/components/sidebar.tsx +++ b/ui/src/components/sidebar.tsx @@ -42,7 +42,8 @@ export class Sidebar extends Component { let community = this.props.community; return (
-

{community.title}

+

{community.title}

+ /f/{community.name} {this.amMod &&
  • diff --git a/ui/src/components/user.tsx b/ui/src/components/user.tsx index 4754111e8..5dd3ac6a2 100644 --- a/ui/src/components/user.tsx +++ b/ui/src/components/user.tsx @@ -77,7 +77,7 @@ export class User extends Component { return (
    -
    +

    /u/{this.state.user.name}

    {this.selects()} {this.state.view == View.Overview && @@ -90,7 +90,7 @@ export class User extends Component { this.posts() }
    -
    +
    {this.userInfo()} {this.moderates()} {this.follows()}