mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-28 04:11:05 +00:00
parent
ff013ccfc2
commit
fe52d594f6
5 changed files with 35 additions and 15 deletions
|
@ -1,12 +1,20 @@
|
||||||
import { Component } from 'inferno';
|
import { Component } from 'inferno';
|
||||||
import { Main } from './main';
|
import { Main } from './main';
|
||||||
|
import { ListingType } from '../interfaces';
|
||||||
|
|
||||||
export class Home extends Component<any, any> {
|
export class Home extends Component<any, any> {
|
||||||
|
|
||||||
|
constructor(props: any, context: any) {
|
||||||
|
super(props, context);
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<Main />
|
<Main type={this.listType()}/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
listType(): ListingType {
|
||||||
|
return (this.props.match.path == '/all') ? ListingType.All : ListingType.Subscribed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,22 +2,27 @@ import { Component } from 'inferno';
|
||||||
import { Link } from 'inferno-router';
|
import { Link } from 'inferno-router';
|
||||||
import { Subscription } from "rxjs";
|
import { Subscription } from "rxjs";
|
||||||
import { retryWhen, delay, take } from 'rxjs/operators';
|
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 { WebSocketService, UserService } from '../services';
|
||||||
import { PostListings } from './post-listings';
|
import { PostListings } from './post-listings';
|
||||||
import { msgOp, repoUrl, mdToHtml } from '../utils';
|
import { msgOp, repoUrl, mdToHtml } from '../utils';
|
||||||
|
|
||||||
interface State {
|
|
||||||
|
interface MainProps {
|
||||||
|
type: ListingType;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MainState {
|
||||||
subscribedCommunities: Array<CommunityUser>;
|
subscribedCommunities: Array<CommunityUser>;
|
||||||
trendingCommunities: Array<Community>;
|
trendingCommunities: Array<Community>;
|
||||||
site: GetSiteResponse;
|
site: GetSiteResponse;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Main extends Component<any, State> {
|
export class Main extends Component<MainProps, MainState> {
|
||||||
|
|
||||||
private subscription: Subscription;
|
private subscription: Subscription;
|
||||||
private emptyState: State = {
|
private emptyState: MainState = {
|
||||||
subscribedCommunities: [],
|
subscribedCommunities: [],
|
||||||
trendingCommunities: [],
|
trendingCommunities: [],
|
||||||
site: {
|
site: {
|
||||||
|
@ -83,7 +88,7 @@ export class Main extends Component<any, State> {
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12 col-md-8">
|
<div class="col-12 col-md-8">
|
||||||
<PostListings />
|
<PostListings type={this.props.type} />
|
||||||
</div>
|
</div>
|
||||||
<div class="col-12 col-md-4">
|
<div class="col-12 col-md-4">
|
||||||
{this.state.loading ?
|
{this.state.loading ?
|
||||||
|
|
|
@ -71,7 +71,7 @@ export class Navbar extends Component<any, NavbarState> {
|
||||||
{
|
{
|
||||||
<li className="nav-item">
|
<li className="nav-item">
|
||||||
<Link class="nav-link" to="/inbox">🖂
|
<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>
|
</Link>
|
||||||
</li>
|
</li>
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import { PostListing } from './post-listing';
|
||||||
import { msgOp, fetchLimit } from '../utils';
|
import { msgOp, fetchLimit } from '../utils';
|
||||||
|
|
||||||
interface PostListingsProps {
|
interface PostListingsProps {
|
||||||
|
type?: ListingType;
|
||||||
communityId?: number;
|
communityId?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,19 +28,19 @@ export class PostListings extends Component<PostListingsProps, PostListingsState
|
||||||
moderators: [],
|
moderators: [],
|
||||||
posts: [],
|
posts: [],
|
||||||
sortType: SortType.Hot,
|
sortType: SortType.Hot,
|
||||||
type_: this.props.communityId
|
type_: (this.props.type !== undefined) ? this.props.type :
|
||||||
? ListingType.Community
|
this.props.communityId
|
||||||
: UserService.Instance.user
|
? ListingType.Community
|
||||||
? ListingType.Subscribed
|
: UserService.Instance.user
|
||||||
: ListingType.All,
|
? ListingType.Subscribed
|
||||||
page: 1,
|
: ListingType.All,
|
||||||
loading: true
|
page: 1,
|
||||||
|
loading: true
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(props: any, context: any) {
|
constructor(props: any, context: any) {
|
||||||
super(props, context);
|
super(props, context);
|
||||||
|
|
||||||
|
|
||||||
this.state = this.emptyState;
|
this.state = this.emptyState;
|
||||||
|
|
||||||
this.subscription = WebSocketService.Instance.subject
|
this.subscription = WebSocketService.Instance.subject
|
||||||
|
@ -147,6 +148,11 @@ export class PostListings extends Component<PostListingsProps, PostListingsState
|
||||||
handleTypeChange(i: PostListings, event: any) {
|
handleTypeChange(i: PostListings, event: any) {
|
||||||
i.state.type_ = Number(event.target.value);
|
i.state.type_ = Number(event.target.value);
|
||||||
i.state.page = 1;
|
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.setState(i.state);
|
||||||
i.refetch();
|
i.refetch();
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ class Index extends Component<any, any> {
|
||||||
<Navbar />
|
<Navbar />
|
||||||
<div class="mt-3 p-0">
|
<div class="mt-3 p-0">
|
||||||
<Switch>
|
<Switch>
|
||||||
|
<Route exact path="/all" component={Home} />
|
||||||
<Route exact path="/" component={Home} />
|
<Route exact path="/" component={Home} />
|
||||||
<Route path={`/login`} component={Login} />
|
<Route path={`/login`} component={Login} />
|
||||||
<Route path={`/create_post`} component={CreatePost} />
|
<Route path={`/create_post`} component={CreatePost} />
|
||||||
|
|
Loading…
Reference in a new issue