]> Untitled Git - lemmy.git/commitdiff
Adding support for an /all route
authorDessalines <tyhou13@gmx.com>
Sat, 20 Apr 2019 19:42:52 +0000 (12:42 -0700)
committerDessalines <tyhou13@gmx.com>
Sat, 20 Apr 2019 19:42:52 +0000 (12:42 -0700)
- Fixes #85

ui/src/components/home.tsx
ui/src/components/main.tsx
ui/src/components/navbar.tsx
ui/src/components/post-listings.tsx
ui/src/index.tsx

index 8fced5be6fccfbfb170fcf20d358ec36e6f5f365..eff09f7e16fb748b6edbcd1e96220ba9f27b52c9 100644 (file)
@@ -1,12 +1,20 @@
 import { Component } from 'inferno';
 import { Main } from './main';
+import { ListingType } from '../interfaces';
 
 export class Home extends Component<any, any> {
 
+  constructor(props: any, context: any) {
+    super(props, context);
+  }
+
   render() {
     return (
-      <Main />
+      <Main type={this.listType()}/>
     )
   }
 
+  listType(): ListingType { 
+    return (this.props.match.path == '/all') ? ListingType.All : ListingType.Subscribed;
+  }
 }
index e3d6f84429c257b5a7a412e4f9225b6d0b88ff7d..6e0b96b6b78401579a6744a34ef333c35c813481 100644 (file)
@@ -2,22 +2,27 @@ import { Component } 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, GetRepliesResponse, GetRepliesForm } from '../interfaces';
+import { UserOperation, CommunityUser, GetFollowedCommunitiesResponse, ListCommunitiesForm, ListCommunitiesResponse, Community, SortType, GetSiteResponse, GetRepliesResponse, GetRepliesForm, ListingType } from '../interfaces';
 import { WebSocketService, UserService } from '../services';
 import { PostListings } from './post-listings';
 import { msgOp, repoUrl, mdToHtml } from '../utils';
 
-interface State {
+
+interface MainProps {
+  type: ListingType;
+}
+
+interface MainState {
   subscribedCommunities: Array<CommunityUser>;
   trendingCommunities: Array<Community>;
   site: GetSiteResponse;
   loading: boolean;
 }
 
-export class Main extends Component<any, State> {
+export class Main extends Component<MainProps, MainState> {
 
   private subscription: Subscription;
-  private emptyState: State = {
+  private emptyState: MainState = {
     subscribedCommunities: [],
     trendingCommunities: [],
     site: {
@@ -83,7 +88,7 @@ export class Main extends Component<any, State> {
       <div class="container">
         <div class="row">
           <div class="col-12 col-md-8">
-            <PostListings />
+            <PostListings type={this.props.type} />
           </div>
           <div class="col-12 col-md-4">
             {this.state.loading ? 
index fed49e6fd48aa199bfad3c645ee3e99b642a159f..5fc6ed7e9629f525cdfde6615e209358d6a32e9c 100644 (file)
@@ -71,7 +71,7 @@ export class Navbar extends Component<any, NavbarState> {
               {
               <li className="nav-item">
                 <Link class="nav-link" to="/inbox">🖂 
-                  {this.state.unreadCount> 0 && <span class="badge badge-light">{this.state.unreadCount}</span>}
+                  {this.state.unreadCount> 0 && <span class="ml-1 badge badge-light">{this.state.unreadCount}</span>}
                 </Link>
               </li>
             }
index b1e48a61ca51f5025340743e73ecf96d0600e8cd..37b7a648b7940cad308341ada26a67282291b68d 100644 (file)
@@ -8,6 +8,7 @@ import { PostListing } from './post-listing';
 import { msgOp, fetchLimit } from '../utils';
 
 interface PostListingsProps {
+  type?: ListingType;
   communityId?: number;
 }
 
@@ -27,19 +28,19 @@ export class PostListings extends Component<PostListingsProps, PostListingsState
     moderators: [],
     posts: [],
     sortType: SortType.Hot,
-    type_: this.props.communityId 
-    ? ListingType.Community 
-    : UserService.Instance.user
-    ? ListingType.Subscribed 
-    : ListingType.All,
-    page: 1,
-    loading: true
+    type_: (this.props.type !== undefined) ? this.props.type : 
+      this.props.communityId 
+        ? ListingType.Community 
+        : UserService.Instance.user
+          ? ListingType.Subscribed 
+          : ListingType.All,
+          page: 1,
+          loading: true
   }
 
   constructor(props: any, context: any) {
     super(props, context);
 
-
     this.state = this.emptyState;
 
     this.subscription = WebSocketService.Instance.subject
@@ -147,6 +148,11 @@ export class PostListings extends Component<PostListingsProps, PostListingsState
   handleTypeChange(i: PostListings, event: any) {
     i.state.type_ = Number(event.target.value);
     i.state.page = 1;
+    if (i.state.type_ == ListingType.All) {
+      i.context.router.history.push('/all');
+    } else {
+      i.context.router.history.push('/');
+    }
     i.setState(i.state);
     i.refetch();
   }
index 677d7678863b57173e11cea72967ca8b0e0b94fa..716684dee7cedce4202a9e56d81ef4a7e588afcb 100644 (file)
@@ -37,6 +37,7 @@ class Index extends Component<any, any> {
         <Navbar />
         <div class="mt-3 p-0">
           <Switch>
+            <Route exact path="/all" component={Home} />
             <Route exact path="/" component={Home} />
             <Route path={`/login`} component={Login} />
             <Route path={`/create_post`} component={CreatePost} />