mirror of
https://github.com/astuto/astuto.git
synced 2025-12-15 11:17:49 +01:00
Add post updates
This commit is contained in:
@@ -7,6 +7,7 @@ class CommentsController < ApplicationController
|
||||
:id,
|
||||
:body,
|
||||
:parent_id,
|
||||
:is_post_update,
|
||||
:updated_at,
|
||||
'users.full_name as user_full_name',
|
||||
'users.email as user_email',
|
||||
|
||||
@@ -15,11 +15,14 @@ import { MutedText } from '../shared/CustomTexts';
|
||||
|
||||
import friendlyDate from '../../helpers/friendlyDate';
|
||||
import { LikesState } from '../../reducers/likesReducer';
|
||||
import { CommentsState } from '../../reducers/commentsReducer';
|
||||
import PostUpdateList from './PostUpdateList';
|
||||
|
||||
interface Props {
|
||||
postId: number;
|
||||
post: IPost;
|
||||
likes: LikesState;
|
||||
comments: CommentsState;
|
||||
boards: Array<IBoard>;
|
||||
postStatuses: Array<IPostStatus>;
|
||||
isLoggedIn: boolean;
|
||||
@@ -51,6 +54,7 @@ class PostP extends React.Component<Props> {
|
||||
const {
|
||||
post,
|
||||
likes,
|
||||
comments,
|
||||
boards,
|
||||
postStatuses,
|
||||
|
||||
@@ -66,6 +70,12 @@ class PostP extends React.Component<Props> {
|
||||
return (
|
||||
<div className="pageContainer">
|
||||
<div className="sidebar">
|
||||
<PostUpdateList
|
||||
postUpdates={comments.items.filter(comment => comment.isPostUpdate === true)}
|
||||
areLoading={comments.areLoading}
|
||||
error={comments.error}
|
||||
/>
|
||||
|
||||
<LikeList
|
||||
likes={likes.items}
|
||||
areLoading={likes.areLoading}
|
||||
|
||||
46
app/javascript/components/Post/PostUpdateList.tsx
Normal file
46
app/javascript/components/Post/PostUpdateList.tsx
Normal file
@@ -0,0 +1,46 @@
|
||||
import * as React from 'react';
|
||||
import Gravatar from 'react-gravatar';
|
||||
|
||||
import { TitleText, DangerText, CenteredMutedText, MutedText } from '../shared/CustomTexts';
|
||||
import Spinner from '../shared/Spinner';
|
||||
|
||||
import IComment from '../../interfaces/IComment';
|
||||
|
||||
import friendlyDate from '../../helpers/friendlyDate';
|
||||
|
||||
interface Props {
|
||||
postUpdates: Array<IComment>;
|
||||
areLoading: boolean;
|
||||
error: string;
|
||||
}
|
||||
|
||||
const PostUpdateList = ({
|
||||
postUpdates,
|
||||
areLoading,
|
||||
error,
|
||||
}: Props) => (
|
||||
<div className="postUpdateListContainer">
|
||||
<TitleText>Post updates:</TitleText>
|
||||
{ areLoading ? <Spinner /> : null }
|
||||
{ error ? <DangerText>{error}</DangerText> : null }
|
||||
<div className="postUpdateList">
|
||||
{ postUpdates.length === 0 ? <CenteredMutedText>There are not post updates yet.</CenteredMutedText> : null }
|
||||
{
|
||||
postUpdates.map((postUpdate, i) => (
|
||||
<div className="postUpdateListItem" key={i}>
|
||||
<div className="postUpdateListItemHeader">
|
||||
<Gravatar email={postUpdate.userEmail} size={28} className="gravatar" />
|
||||
<span>{postUpdate.userFullName}</span>
|
||||
</div>
|
||||
|
||||
<p className="postUpdateListItemBody">{postUpdate.body}</p>
|
||||
|
||||
<MutedText>{friendlyDate(postUpdate.updatedAt)}</MutedText>
|
||||
</div>
|
||||
))
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
export default PostUpdateList;
|
||||
@@ -12,6 +12,7 @@ import PostP from '../components/Post/PostP';
|
||||
const mapStateToProps = (state: State) => ({
|
||||
post: state.currentPost.item,
|
||||
likes: state.currentPost.likes,
|
||||
comments: state.currentPost.comments,
|
||||
});
|
||||
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
|
||||
@@ -2,6 +2,7 @@ interface IComment {
|
||||
id: number;
|
||||
body: string;
|
||||
parentId: number;
|
||||
isPostUpdate: boolean;
|
||||
userFullName: string;
|
||||
userEmail: string;
|
||||
updatedAt: string;
|
||||
|
||||
@@ -2,6 +2,7 @@ interface ICommentJSON {
|
||||
id: number;
|
||||
body: string;
|
||||
parent_id: number;
|
||||
is_post_update: boolean;
|
||||
user_full_name: string;
|
||||
user_email: string;
|
||||
updated_at: string;
|
||||
|
||||
@@ -9,6 +9,7 @@ const initialState: IComment = {
|
||||
id: 0,
|
||||
body: '',
|
||||
parentId: null,
|
||||
isPostUpdate: false,
|
||||
userFullName: '<Unknown user>',
|
||||
userEmail: 'example@example.com',
|
||||
updatedAt: undefined,
|
||||
@@ -24,6 +25,7 @@ const commentReducer = (
|
||||
id: action.comment.id,
|
||||
body: action.comment.body,
|
||||
parentId: action.comment.parent_id,
|
||||
isPostUpdate: action.comment.is_post_update,
|
||||
userFullName: action.comment.user_full_name,
|
||||
userEmail: action.comment.user_email,
|
||||
updatedAt: action.comment.updated_at,
|
||||
|
||||
@@ -13,6 +13,43 @@
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
.postUpdateListContainer {
|
||||
@extend .sidebarCard;
|
||||
|
||||
.postUpdateList {
|
||||
@extend .w-100;
|
||||
|
||||
max-height: 250px;
|
||||
overflow-y: scroll;
|
||||
|
||||
.postUpdateListItem {
|
||||
@extend
|
||||
.d-flex,
|
||||
.flex-column,
|
||||
.p-2,
|
||||
.my-1;
|
||||
|
||||
.postUpdateListItemHeader {
|
||||
@extend .d-flex;
|
||||
|
||||
span {
|
||||
@extend
|
||||
.ml-2;
|
||||
|
||||
font-weight: 600;
|
||||
vertical-align: middle;
|
||||
}
|
||||
}
|
||||
|
||||
.postUpdateListItemBody {
|
||||
@extend .m-0;
|
||||
|
||||
font-size: 15px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.likeListContainer {
|
||||
@extend .sidebarCard;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user