From 4e5561283392d2ab1545cabb4455a8ffc490f86b Mon Sep 17 00:00:00 2001 From: Dessalines Date: Fri, 18 Oct 2019 17:20:27 -0700 Subject: Running prettier on code. - #305 , #309 --- ui/src/components/main.tsx | 431 +++++++++++++++++++++++++++++++-------------- 1 file changed, 298 insertions(+), 133 deletions(-) (limited to 'ui/src/components/main.tsx') diff --git a/ui/src/components/main.tsx b/ui/src/components/main.tsx index 1366c162..b1ddef4c 100644 --- a/ui/src/components/main.tsx +++ b/ui/src/components/main.tsx @@ -1,12 +1,35 @@ import { Component, linkEvent } from 'inferno'; import { Link } from 'inferno-router'; -import { Subscription } from "rxjs"; +import { Subscription } from 'rxjs'; import { retryWhen, delay, take } from 'rxjs/operators'; -import { UserOperation, CommunityUser, GetFollowedCommunitiesResponse, ListCommunitiesForm, ListCommunitiesResponse, Community, SortType, GetSiteResponse, ListingType, SiteResponse, GetPostsResponse, CreatePostLikeResponse, Post, GetPostsForm } from '../interfaces'; +import { + UserOperation, + CommunityUser, + GetFollowedCommunitiesResponse, + ListCommunitiesForm, + ListCommunitiesResponse, + Community, + SortType, + GetSiteResponse, + ListingType, + SiteResponse, + GetPostsResponse, + CreatePostLikeResponse, + Post, + GetPostsForm, +} from '../interfaces'; import { WebSocketService, UserService } from '../services'; import { PostListings } from './post-listings'; import { SiteForm } from './site-form'; -import { msgOp, repoUrl, mdToHtml, fetchLimit, routeSortTypeToEnum, routeListingTypeToEnum, postRefetchSeconds } from '../utils'; +import { + msgOp, + repoUrl, + mdToHtml, + fetchLimit, + routeSortTypeToEnum, + routeListingTypeToEnum, + postRefetchSeconds, +} from '../utils'; import { i18n } from '../i18next'; import { T } from 'inferno-i18next'; @@ -23,7 +46,6 @@ interface MainState { } export class Main extends Component { - private subscription: Subscription; private postFetcher: any; private emptyState: MainState = { @@ -52,24 +74,24 @@ export class Main extends Component { type_: this.getListingTypeFromProps(this.props), sort: this.getSortTypeFromProps(this.props), page: this.getPageFromProps(this.props), - } + }; getListingTypeFromProps(props: any): ListingType { - return (props.match.params.type) ? - routeListingTypeToEnum(props.match.params.type) : - UserService.Instance.user ? - ListingType.Subscribed : - ListingType.All; + return props.match.params.type + ? routeListingTypeToEnum(props.match.params.type) + : UserService.Instance.user + ? ListingType.Subscribed + : ListingType.All; } getSortTypeFromProps(props: any): SortType { - return (props.match.params.sort) ? - routeSortTypeToEnum(props.match.params.sort) : - SortType.Hot; + return props.match.params.sort + ? routeSortTypeToEnum(props.match.params.sort) + : SortType.Hot; } getPageFromProps(props: any): number { - return (props.match.params.page) ? Number(props.match.params.page) : 1; + return props.match.params.page ? Number(props.match.params.page) : 1; } constructor(props: any, context: any) { @@ -79,12 +101,19 @@ export class Main extends Component { this.handleEditCancel = this.handleEditCancel.bind(this); this.subscription = WebSocketService.Instance.subject - .pipe(retryWhen(errors => errors.pipe(delay(3000), take(10)))) - .subscribe( - (msg) => this.parseMessage(msg), - (err) => console.error(err), + .pipe( + retryWhen(errors => + errors.pipe( + delay(3000), + take(10) + ) + ) + ) + .subscribe( + msg => this.parseMessage(msg), + err => console.error(err), () => console.log('complete') - ); + ); WebSocketService.Instance.getSite(); @@ -94,8 +123,8 @@ export class Main extends Component { let listCommunitiesForm: ListCommunitiesForm = { sort: SortType[SortType.Hot], - limit: 6 - } + limit: 6, + }; WebSocketService.Instance.listCommunities(listCommunitiesForm); @@ -109,7 +138,10 @@ export class Main extends Component { // Necessary for back button for some reason componentWillReceiveProps(nextProps: any) { - if (nextProps.history.action == 'POP' || nextProps.history.action == 'PUSH') { + if ( + nextProps.history.action == 'POP' || + nextProps.history.action == 'PUSH' + ) { this.state.type_ = this.getListingTypeFromProps(nextProps); this.state.sort = this.getSortTypeFromProps(nextProps); this.state.page = this.getPageFromProps(nextProps); @@ -122,39 +154,47 @@ export class Main extends Component { return (
-
- {this.posts()} -
-
- {this.my_sidebar()} -
+
{this.posts()}
+
{this.my_sidebar()}
- ) + ); } - + my_sidebar() { - return( + return (
- {!this.state.loading && + {!this.state.loading && (
{this.trendingCommunities()} - {UserService.Instance.user && this.state.subscribedCommunities.length > 0 && -
-
- ## -
-
    - {this.state.subscribedCommunities.map(community => -
  • {community.community_name}
  • - )} -
-
- } - + {UserService.Instance.user && + this.state.subscribedCommunities.length > 0 && ( +
+
+ + # + + # + + +
+
    + {this.state.subscribedCommunities.map(community => ( +
  • + + {community.community_name} + +
  • + ))} +
+
+ )} + #
@@ -162,44 +202,54 @@ export class Main extends Component { {this.sidebar()} {this.landing()}
- } + )}
- ) + ); } trendingCommunities() { return (
- ## + + # + + # + +
-
    - {this.state.trendingCommunities.map(community => -
  • {community.name}
  • - )} +
      + {this.state.trendingCommunities.map(community => ( +
    • + {community.name} +
    • + ))}
- ) + ); } sidebar() { return (
- {!this.state.showEditSite ? - this.siteInfo() : + {!this.state.showEditSite ? ( + this.siteInfo() + ) : ( - } + )}
- ) + ); } updateUrl() { let typeStr = ListingType[this.state.type_].toLowerCase(); let sortStr = SortType[this.state.sort].toLowerCase(); - this.props.history.push(`/home/type/${typeStr}/sort/${sortStr}/page/${this.state.page}`); + this.props.history.push( + `/home/type/${typeStr}/sort/${sortStr}/page/${this.state.page}` + ); } siteInfo() { @@ -208,30 +258,66 @@ export class Main extends Component {
{`${this.state.site.site.name}`}
- {this.canAdmin && -
    + {this.canAdmin && ( +
    • - + #
    - } + )}
    • - # + + # +
    • - # + + # +
    • - # + + # +
    • - # + + # +
    • - # + + # +
    • @@ -239,25 +325,37 @@ export class Main extends Component {
    -
      +
      • - #: + + # + + : +
      • + {this.state.site.admins.map(admin => ( +
      • + + {admin.name} +
      • - {this.state.site.admins.map(admin => -
      • {admin.name}
      • + ))} +
      +
+
+ {this.state.site.site.description && ( +
+
+
+ />
- {this.state.site.site.description && -
-
-
-
-
- } -
- ) + )} +
+ ); } landing() { @@ -265,43 +363,73 @@ export class Main extends Component {
- # - # - Lemmybeta + + # + + + # + + + Lemmybeta +

- ###

#

#

#

#### -
-

+ + # + + # + + # +

+ # +

+ # +

+ # +

+ # + # + # + # +
+

+
-
- ) + ); } posts() { return (
- {this.state.loading ? -
: -
- {this.selects()} - - {this.paginator()} -
- } + {this.state.loading ? ( +
+ + + +
+ ) : ( +
+ {this.selects()} + + {this.paginator()} +
+ )}
- ) + ); } selects() { return (
- -
- + + + - - - - - + + + + +
- ) + ); } paginator() { return (
- {this.state.page > 1 && - - } - + {this.state.page > 1 && ( + + )} +
); } get canAdmin(): boolean { - return UserService.Instance.user && this.state.site.admins.map(a => a.id).includes(UserService.Instance.user.id); + return ( + UserService.Instance.user && + this.state.site.admins + .map(a => a.id) + .includes(UserService.Instance.user.id) + ); } handleEditClick(i: Main) { @@ -358,22 +525,22 @@ export class Main extends Component { this.setState(this.state); } - nextPage(i: Main) { + nextPage(i: Main) { i.state.page++; i.state.loading = true; i.setState(i.state); i.updateUrl(); i.fetchPosts(); - window.scrollTo(0,0); + window.scrollTo(0, 0); } - prevPage(i: Main) { + prevPage(i: Main) { i.state.page--; i.state.loading = true; i.setState(i.state); i.updateUrl(); i.fetchPosts(); - window.scrollTo(0,0); + window.scrollTo(0, 0); } handleSortChange(i: Main, event: any) { @@ -383,7 +550,7 @@ export class Main extends Component { i.setState(i.state); i.updateUrl(); i.fetchPosts(); - window.scrollTo(0,0); + window.scrollTo(0, 0); } handleTypeChange(i: Main, event: any) { @@ -393,7 +560,7 @@ export class Main extends Component { i.setState(i.state); i.updateUrl(); i.fetchPosts(); - window.scrollTo(0,0); + window.scrollTo(0, 0); } keepFetchingPosts() { @@ -406,8 +573,8 @@ export class Main extends Component { page: this.state.page, limit: fetchLimit, sort: SortType[this.state.sort], - type_: ListingType[this.state.type_] - } + type_: ListingType[this.state.type_], + }; WebSocketService.Instance.getPosts(getPostsForm); } @@ -430,7 +597,7 @@ export class Main extends Component { // This means it hasn't been set up yet if (!res.site) { - this.context.router.history.push("/setup"); + this.context.router.history.push('/setup'); } this.state.site.admins = res.admins; this.state.site.site = res.site; @@ -438,7 +605,6 @@ export class Main extends Component { this.state.site.online = res.online; this.setState(this.state); document.title = `${WebSocketService.Instance.site.name}`; - } else if (op == UserOperation.EditSite) { let res: SiteResponse = msg; this.state.site.site = res.site; @@ -460,4 +626,3 @@ export class Main extends Component { } } } - -- cgit v1.2.3