Improve Roadmap and Board components

This commit is contained in:
riggraz
2019-09-06 14:36:26 +02:00
parent 5b8b36afd9
commit 25d7d9a5af
8 changed files with 52 additions and 28 deletions

View File

@@ -102,10 +102,16 @@ class NewPost extends React.Component<Props, State> {
}); });
this.setState({isLoading: false}); this.setState({isLoading: false});
if (res.status === 204) this.setState({success: 'Your post has been published!'}); if (res.status === 204) {
else { this.setState({
success: 'Your post has been published!',
title: '',
description: '',
});
} else {
let data = await res.json(); let data = await res.json();
this.setState({error: data.message}); this.setState({error: data.error});
} }
} catch (e) { } catch (e) {

View File

@@ -28,15 +28,20 @@ const PostList = ({ posts, areLoading, error, handleLoadMore, page, hasMore }: P
loader={<Spinner key={0} />} loader={<Spinner key={0} />}
useWindow={true} useWindow={true}
> >
{posts.map((post, i) => ( {
<PostListItem posts.length > 0 ?
title={post.title} posts.map((post, i) => (
description={post.description} <PostListItem
postStatus={post.postStatus} title={post.title}
description={post.description}
postStatus={post.postStatus}
key={i} key={i}
/> />
))} ))
:
!areLoading ? <span className="infoText text-muted">There are no posts.</span> : null
}
</InfiniteScroll> </InfiniteScroll>
</div> </div>
); );

View File

@@ -9,7 +9,7 @@ const SearchFilter = ({ searchQuery, handleChange }: Props) => (
<div className="box sidebar-box"> <div className="box sidebar-box">
<label htmlFor="searchPostInput" className="smallTitle">Search:</label> <label htmlFor="searchPostInput" className="smallTitle">Search:</label>
<input <input
type="text" type="search"
onChange={e => handleChange(e.target.value)} onChange={e => handleChange(e.target.value)}
id="searchPostInput" id="searchPostInput"
className="form-control" className="form-control"

View File

@@ -9,8 +9,6 @@ import IBoard from '../../interfaces/IBoard';
import IPost from '../../interfaces/IPost'; import IPost from '../../interfaces/IPost';
import IPostStatus from '../../interfaces/IPostStatus'; import IPostStatus from '../../interfaces/IPostStatus';
import debounce from '../../helpers/debounce.js';
import '../../stylesheets/components/Board.scss'; import '../../stylesheets/components/Board.scss';
interface Props { interface Props {
@@ -40,6 +38,8 @@ interface State {
} }
class Board extends React.Component<Props, State> { class Board extends React.Component<Props, State> {
searchFilterTimeoutId: number;
constructor(props) { constructor(props) {
super(props); super(props);
@@ -145,11 +145,13 @@ class Board extends React.Component<Props, State> {
} }
setSearchFilter(searchQuery: string) { setSearchFilter(searchQuery: string) {
debounce(() => ( if (this.searchFilterTimeoutId) clearInterval(this.searchFilterTimeoutId);
this.searchFilterTimeoutId = setTimeout(() => (
this.setState({ this.setState({
filters: { ...this.state.filters, searchQuery }, filters: { ...this.state.filters, searchQuery },
}, this.requestPosts) }, this.requestPosts)
), 1000)(); ), 500);
} }
setPostStatusFilter(postStatusId: number) { setPostStatusFilter(postStatusId: number) {

View File

@@ -12,14 +12,19 @@ interface Props {
const PostList = ({ posts, boards }: Props) => ( const PostList = ({ posts, boards }: Props) => (
<div className="postList"> <div className="postList">
{posts.map((post, i) => ( {
<PostListItem posts.length > 0 ?
title={post.title} posts.map((post, i) => (
boardName={boards.find(board => board.id === post.board_id).name} <PostListItem
title={post.title}
boardName={boards.find(board => board.id === post.board_id).name}
key={i} key={i}
/> />
))} ))
:
<span className="infoText text-muted">There are no posts that have this status.</span>
}
</div> </div>
); );

View File

@@ -1,4 +0,0 @@
// https://toughcompetent.com/blog/es5-es6-debounce-react-events-on-inputs/
function debounce(a,b,c){var d,e;return function(){function h(){d=null,c||(e=a.apply(f,g))}var f=this,g=arguments;return clearTimeout(d),d=setTimeout(h,b),c&&!d&&(e=a.apply(f,g)),e}}
export default debounce;

View File

@@ -39,7 +39,6 @@
justify-content: space-between; justify-content: space-between;
align-items: flex-start; align-items: flex-start;
flex-wrap: nowrap; flex-wrap: nowrap;
.sidebar { .sidebar {
.sidebar-box { .sidebar-box {
@@ -208,4 +207,10 @@
margin-top: auto; margin-top: auto;
margin-bottom: auto; margin-bottom: auto;
margin-right: 4px; margin-right: 4px;
}
.infoText {
display: block;
text-align: center;
font-style: italic;
} }

View File

@@ -40,6 +40,11 @@
height: 16px; height: 16px;
border-radius: 100%; border-radius: 100%;
} }
.infoText {
text-align: center;
font-style: italic;
}
.columnTitle { .columnTitle {
margin: 0 8px; margin: 0 8px;