import { WebSocketService } from '../services';
import { PostListings } from './post-listings';
import { Sidebar } from './sidebar';
-import { msgOp, routeSortTypeToEnum, fetchLimit } from '../utils';
+import { msgOp, routeSortTypeToEnum, fetchLimit, postRefetchSeconds } from '../utils';
import { T, i18n } from 'inferno-i18next';
interface State {
export class Community extends Component<any, State> {
private subscription: Subscription;
+ private postFetcher: any;
private emptyState: State = {
community: {
id: null,
WebSocketService.Instance.getCommunityByName(this.state.communityName);
}
+ this.keepFetchingPosts();
}
componentWillUnmount() {
this.subscription.unsubscribe();
+ clearInterval(this.postFetcher);
}
// Necessary for back button for some reason
i.setState(i.state);
i.updateUrl();
i.fetchPosts();
+ window.scrollTo(0,0);
}
prevPage(i: Community) {
i.setState(i.state);
i.updateUrl();
i.fetchPosts();
+ window.scrollTo(0,0);
}
handleSortChange(i: Community, event: any) {
i.setState(i.state);
i.updateUrl();
i.fetchPosts();
+ window.scrollTo(0,0);
}
updateUrl() {
this.props.history.push(`/c/${this.state.community.name}/sort/${sortStr}/page/${this.state.page}`);
}
+ keepFetchingPosts() {
+ this.fetchPosts();
+ this.postFetcher = setInterval(() => this.fetchPosts(), postRefetchSeconds);
+ }
+
fetchPosts() {
let getPostsForm: GetPostsForm = {
page: this.state.page,
let res: GetPostsResponse = msg;
this.state.posts = res.posts;
this.state.loading = false;
- window.scrollTo(0,0);
this.setState(this.state);
} else if (op == UserOperation.CreatePostLike) {
let res: CreatePostLikeResponse = msg;
import { WebSocketService, UserService } from '../services';
import { PostListings } from './post-listings';
import { SiteForm } from './site-form';
-import { msgOp, repoUrl, mdToHtml, fetchLimit, routeSortTypeToEnum, routeListingTypeToEnum } from '../utils';
+import { msgOp, repoUrl, mdToHtml, fetchLimit, routeSortTypeToEnum, routeListingTypeToEnum, postRefetchSeconds } from '../utils';
import { i18n } from '../i18next';
import { T } from 'inferno-i18next';
export class Main extends Component<any, MainState> {
private subscription: Subscription;
+ private postFetcher: any;
private emptyState: MainState = {
subscribedCommunities: [],
trendingCommunities: [],
WebSocketService.Instance.listCommunities(listCommunitiesForm);
- this.fetchPosts();
+ this.keepFetchingPosts();
}
componentWillUnmount() {
this.subscription.unsubscribe();
+ clearInterval(this.postFetcher);
}
// Necessary for back button for some reason
i.setState(i.state);
i.updateUrl();
i.fetchPosts();
+ window.scrollTo(0,0);
}
prevPage(i: Main) {
i.setState(i.state);
i.updateUrl();
i.fetchPosts();
+ window.scrollTo(0,0);
}
handleSortChange(i: Main, event: any) {
i.setState(i.state);
i.updateUrl();
i.fetchPosts();
+ window.scrollTo(0,0);
}
handleTypeChange(i: Main, event: any) {
i.setState(i.state);
i.updateUrl();
i.fetchPosts();
+ window.scrollTo(0,0);
+ }
+
+ keepFetchingPosts() {
+ this.fetchPosts();
+ this.postFetcher = setInterval(() => this.fetchPosts(), postRefetchSeconds);
}
fetchPosts() {
let res: GetPostsResponse = msg;
this.state.posts = res.posts;
this.state.loading = false;
- window.scrollTo(0,0);
this.setState(this.state);
} else if (op == UserOperation.CreatePostLike) {
let res: CreatePostLikeResponse = msg;
export const repoUrl = 'https://github.com/dessalines/lemmy';
export const markdownHelpUrl = 'https://commonmark.org/help/';
+export const postRefetchSeconds: number = 60*1000;
export const fetchLimit: number = 20;
export const mentionDropdownFetchLimit = 6;