2019-09-11 18:30:59 +02:00
|
|
|
import * as React from 'react';
|
|
|
|
|
|
|
|
|
|
import NewPost from './NewPost';
|
|
|
|
|
import SearchFilter from './SearchFilter';
|
|
|
|
|
import PostStatusFilter from './PostStatusFilter';
|
|
|
|
|
import PostList from './PostList';
|
2022-06-08 10:20:36 +02:00
|
|
|
import Sidebar from '../common/Sidebar';
|
2019-09-11 18:30:59 +02:00
|
|
|
|
|
|
|
|
import IBoard from '../../interfaces/IBoard';
|
2023-02-05 11:55:38 +01:00
|
|
|
import ITenantSetting from '../../interfaces/ITenantSetting';
|
2019-09-11 18:30:59 +02:00
|
|
|
|
|
|
|
|
import { PostsState } from '../../reducers/postsReducer';
|
|
|
|
|
import { PostStatusesState } from '../../reducers/postStatusesReducer';
|
2024-01-26 17:43:24 +01:00
|
|
|
import SortByFilter from './SortByFilter';
|
|
|
|
|
import { SortByFilterValues } from '../../actions/changeFilters';
|
2019-09-11 18:30:59 +02:00
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
|
board: IBoard;
|
|
|
|
|
isLoggedIn: boolean;
|
2023-02-05 11:55:38 +01:00
|
|
|
isPowerUser: boolean;
|
|
|
|
|
tenantSetting: ITenantSetting;
|
2019-09-11 18:30:59 +02:00
|
|
|
authenticityToken: string;
|
|
|
|
|
posts: PostsState;
|
|
|
|
|
postStatuses: PostStatusesState;
|
|
|
|
|
|
|
|
|
|
requestPosts(
|
|
|
|
|
boardId: number,
|
|
|
|
|
page?: number,
|
|
|
|
|
searchQuery?: string,
|
2024-01-25 14:50:39 +01:00
|
|
|
postStatusIds?: Array<number>,
|
2024-01-26 17:43:24 +01:00
|
|
|
sortBy?: SortByFilterValues,
|
2019-09-11 18:30:59 +02:00
|
|
|
): void;
|
|
|
|
|
requestPostStatuses(): void;
|
|
|
|
|
handleSearchFilterChange(searchQuery: string): void;
|
|
|
|
|
handlePostStatusFilterChange(postStatusId: number): void;
|
2024-01-26 17:43:24 +01:00
|
|
|
handleSortByFilterChange(sortBy: SortByFilterValues): void;
|
2019-09-11 18:30:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class BoardP extends React.Component<Props> {
|
|
|
|
|
searchFilterTimeoutId: ReturnType<typeof setTimeout>;
|
|
|
|
|
|
|
|
|
|
componentDidMount() {
|
2024-01-26 17:43:24 +01:00
|
|
|
this.props.requestPosts(this.props.board.id, 1, '', null, this.props.posts.filters.sortBy);
|
2019-09-11 18:30:59 +02:00
|
|
|
this.props.requestPostStatuses();
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-26 11:00:32 +02:00
|
|
|
componentDidUpdate(prevProps: Props) {
|
2019-09-11 18:30:59 +02:00
|
|
|
const { searchQuery } = this.props.posts.filters;
|
|
|
|
|
const prevSearchQuery = prevProps.posts.filters.searchQuery;
|
|
|
|
|
|
2024-01-25 14:50:39 +01:00
|
|
|
const { postStatusIds } = this.props.posts.filters;
|
|
|
|
|
const prevPostStatusIds = prevProps.posts.filters.postStatusIds;
|
2019-09-11 18:30:59 +02:00
|
|
|
|
2024-01-26 17:43:24 +01:00
|
|
|
const { sortBy } = this.props.posts.filters;
|
|
|
|
|
const prevSortBy = prevProps.posts.filters.sortBy;
|
|
|
|
|
|
2019-09-11 18:30:59 +02:00
|
|
|
// search filter changed
|
|
|
|
|
if (searchQuery !== prevSearchQuery) {
|
|
|
|
|
if (this.searchFilterTimeoutId) clearInterval(this.searchFilterTimeoutId);
|
|
|
|
|
|
|
|
|
|
this.searchFilterTimeoutId = setTimeout(() => (
|
2024-01-25 14:50:39 +01:00
|
|
|
this.props.requestPosts(this.props.board.id, 1, searchQuery, postStatusIds)
|
2019-09-11 18:30:59 +02:00
|
|
|
), 500);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// post status filter changed
|
2024-01-25 14:50:39 +01:00
|
|
|
if (postStatusIds.length !== prevPostStatusIds.length) {
|
|
|
|
|
this.props.requestPosts(this.props.board.id, 1, searchQuery, postStatusIds);
|
2019-09-11 18:30:59 +02:00
|
|
|
}
|
2024-01-26 17:43:24 +01:00
|
|
|
|
|
|
|
|
// sort by filter changed
|
|
|
|
|
if (sortBy !== prevSortBy) {
|
|
|
|
|
this.props.requestPosts(this.props.board.id, 1, searchQuery, postStatusIds, sortBy);
|
|
|
|
|
}
|
2019-09-11 18:30:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
const {
|
|
|
|
|
board,
|
|
|
|
|
isLoggedIn,
|
2023-02-05 11:55:38 +01:00
|
|
|
isPowerUser,
|
|
|
|
|
tenantSetting,
|
2019-09-11 18:30:59 +02:00
|
|
|
authenticityToken,
|
|
|
|
|
posts,
|
|
|
|
|
postStatuses,
|
|
|
|
|
|
|
|
|
|
requestPosts,
|
|
|
|
|
handleSearchFilterChange,
|
|
|
|
|
handlePostStatusFilterChange,
|
2024-01-26 17:43:24 +01:00
|
|
|
handleSortByFilterChange,
|
2019-09-11 18:30:59 +02:00
|
|
|
} = this.props;
|
2019-09-14 12:42:30 +02:00
|
|
|
const { filters } = posts;
|
2019-09-11 18:30:59 +02:00
|
|
|
|
|
|
|
|
return (
|
2019-09-16 12:22:30 +02:00
|
|
|
<div className="boardContainer">
|
2022-06-08 10:20:36 +02:00
|
|
|
<Sidebar>
|
2019-09-11 18:30:59 +02:00
|
|
|
<NewPost
|
|
|
|
|
board={board}
|
|
|
|
|
isLoggedIn={isLoggedIn}
|
|
|
|
|
authenticityToken={authenticityToken}
|
|
|
|
|
/>
|
|
|
|
|
<SearchFilter
|
2019-09-14 12:42:30 +02:00
|
|
|
searchQuery={filters.searchQuery}
|
2019-09-11 18:30:59 +02:00
|
|
|
handleChange={handleSearchFilterChange}
|
|
|
|
|
/>
|
2024-01-26 17:43:24 +01:00
|
|
|
{
|
|
|
|
|
isPowerUser &&
|
|
|
|
|
<SortByFilter
|
|
|
|
|
sortBy={filters.sortBy}
|
|
|
|
|
handleChange={sortBy => handleSortByFilterChange(sortBy)}
|
|
|
|
|
/>
|
|
|
|
|
}
|
2019-09-11 18:30:59 +02:00
|
|
|
<PostStatusFilter
|
|
|
|
|
postStatuses={postStatuses.items}
|
|
|
|
|
areLoading={postStatuses.areLoading}
|
|
|
|
|
error={postStatuses.error}
|
|
|
|
|
|
2024-01-25 14:50:39 +01:00
|
|
|
currentFilter={filters.postStatusIds}
|
2019-09-11 18:30:59 +02:00
|
|
|
handleFilterClick={handlePostStatusFilterChange}
|
|
|
|
|
/>
|
2022-06-08 10:20:36 +02:00
|
|
|
</Sidebar>
|
2019-09-11 18:30:59 +02:00
|
|
|
|
|
|
|
|
<PostList
|
|
|
|
|
posts={posts.items}
|
2023-02-05 11:55:38 +01:00
|
|
|
showLikeCount={isPowerUser || tenantSetting.show_vote_count}
|
|
|
|
|
showLikeButtons={tenantSetting.show_vote_button_in_board}
|
2019-09-11 18:30:59 +02:00
|
|
|
postStatuses={postStatuses.items}
|
|
|
|
|
areLoading={posts.areLoading}
|
|
|
|
|
error={posts.error}
|
2019-09-27 16:57:23 +02:00
|
|
|
|
|
|
|
|
hasMore={posts.haveMore}
|
2019-09-14 12:42:30 +02:00
|
|
|
handleLoadMore={() =>
|
2019-09-14 12:50:16 +02:00
|
|
|
posts.areLoading ?
|
|
|
|
|
null
|
|
|
|
|
:
|
2024-01-25 14:50:39 +01:00
|
|
|
requestPosts(board.id, posts.page + 1, filters.searchQuery, filters.postStatusIds)
|
2019-09-14 12:42:30 +02:00
|
|
|
}
|
2019-09-27 16:57:23 +02:00
|
|
|
|
|
|
|
|
isLoggedIn={isLoggedIn}
|
|
|
|
|
authenticityToken={authenticityToken}
|
2019-09-11 18:30:59 +02:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default BoardP;
|