mirror of
https://github.com/astuto/astuto.git
synced 2025-12-15 11:17:49 +01:00
General improvements to postlist and post
This commit is contained in:
@@ -92,7 +92,7 @@ class NewPost extends React.Component<Props, State> {
|
||||
}
|
||||
|
||||
try {
|
||||
let res = await fetch('/posts', {
|
||||
const res = await fetch('/posts', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
@@ -107,18 +107,22 @@ class NewPost extends React.Component<Props, State> {
|
||||
},
|
||||
}),
|
||||
});
|
||||
const json = await res.json();
|
||||
this.setState({isLoading: false});
|
||||
|
||||
if (res.status === 204) {
|
||||
if (res.status === 201) {
|
||||
this.setState({
|
||||
success: 'Your post has been published!',
|
||||
success: 'Post published! You will be redirected soon...',
|
||||
|
||||
title: '',
|
||||
description: '',
|
||||
});
|
||||
|
||||
setTimeout(() => (
|
||||
window.location.href = `/posts/${json.id}`
|
||||
), 1000);
|
||||
} else {
|
||||
let data = await res.json();
|
||||
this.setState({error: data.error});
|
||||
this.setState({error: json.error});
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
|
||||
@@ -50,6 +50,7 @@ const PostList = ({
|
||||
title={post.title}
|
||||
description={post.description}
|
||||
postStatus={postStatuses.find(postStatus => postStatus.id === post.postStatusId)}
|
||||
commentsCount={post.commentsCount}
|
||||
|
||||
key={i}
|
||||
/>
|
||||
|
||||
@@ -11,16 +11,17 @@ interface Props {
|
||||
title: string;
|
||||
description?: string;
|
||||
postStatus: IPostStatus;
|
||||
commentsCount: number;
|
||||
}
|
||||
|
||||
const PostListItem = ({ id, title, description, postStatus}: Props) => (
|
||||
const PostListItem = ({ id, title, description, postStatus, commentsCount }: Props) => (
|
||||
<a href={`/posts/${id}`} className="postLink">
|
||||
<div className="postListItem">
|
||||
<span className="postTitle">{title}</span>
|
||||
<DescriptionText limit={120}>{description}</DescriptionText>
|
||||
|
||||
<div className="postDetails">
|
||||
<CommentsNumber number={0} />
|
||||
<CommentsNumber number={commentsCount} />
|
||||
{ postStatus ? <PostStatusLabel {...postStatus} /> : null }
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -31,6 +31,7 @@ const NewComment = ({
|
||||
value={body}
|
||||
onChange={handleChange}
|
||||
placeholder="Leave a comment"
|
||||
autoFocus
|
||||
className="newCommentBody"
|
||||
/>
|
||||
<Button
|
||||
|
||||
@@ -5,8 +5,7 @@ const friendlyDate = date => {
|
||||
var secondsPast = (now.getTime() - timeStamp.getTime()) / 1000;
|
||||
|
||||
if (secondsPast < 60) {
|
||||
secondsPast = parseInt(secondsPast);
|
||||
return secondsPast + ' ' + (secondsPast === 1 ? 'second' : 'seconds') + ' ago';
|
||||
return 'just now';
|
||||
} else if (secondsPast < 3600) {
|
||||
let minutesPast = parseInt(secondsPast / 60);
|
||||
return minutesPast + ' ' + (minutesPast === 1 ? 'minute' : 'minutes') + ' ago';
|
||||
|
||||
@@ -4,6 +4,7 @@ interface IPost {
|
||||
description?: string;
|
||||
boardId: number;
|
||||
postStatusId?: number;
|
||||
commentsCount: number;
|
||||
userId: number;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ interface IPostJSON {
|
||||
description?: string;
|
||||
board_id: number;
|
||||
post_status_id?: number;
|
||||
comments_count: number;
|
||||
user_id: number;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
@@ -100,7 +100,6 @@ const commentsReducer = (
|
||||
};
|
||||
|
||||
case COMMENT_SUBMIT_SUCCESS:
|
||||
console.log(action.comment);
|
||||
return {
|
||||
...state,
|
||||
items: [commentReducer(undefined, commentRequestSuccess(action.comment)), ...state.items],
|
||||
|
||||
@@ -14,6 +14,7 @@ const initialState: IPost = {
|
||||
description: null,
|
||||
boardId: 0,
|
||||
postStatusId: null,
|
||||
commentsCount: 0,
|
||||
userId: 0,
|
||||
createdAt: '',
|
||||
};
|
||||
@@ -30,6 +31,7 @@ const postReducer = (
|
||||
description: action.post.description,
|
||||
boardId: action.post.board_id,
|
||||
postStatusId: action.post.post_status_id,
|
||||
commentsCount: action.post.comments_count,
|
||||
userId: action.post.user_id,
|
||||
createdAt: action.post.created_at,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user