mirror of
https://github.com/astuto/astuto.git
synced 2025-12-15 19:27:52 +01:00
Add post updates
This commit is contained in:
@@ -7,6 +7,7 @@ class CommentsController < ApplicationController
|
|||||||
:id,
|
:id,
|
||||||
:body,
|
:body,
|
||||||
:parent_id,
|
:parent_id,
|
||||||
|
:is_post_update,
|
||||||
:updated_at,
|
:updated_at,
|
||||||
'users.full_name as user_full_name',
|
'users.full_name as user_full_name',
|
||||||
'users.email as user_email',
|
'users.email as user_email',
|
||||||
|
|||||||
@@ -15,11 +15,14 @@ import { MutedText } from '../shared/CustomTexts';
|
|||||||
|
|
||||||
import friendlyDate from '../../helpers/friendlyDate';
|
import friendlyDate from '../../helpers/friendlyDate';
|
||||||
import { LikesState } from '../../reducers/likesReducer';
|
import { LikesState } from '../../reducers/likesReducer';
|
||||||
|
import { CommentsState } from '../../reducers/commentsReducer';
|
||||||
|
import PostUpdateList from './PostUpdateList';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
postId: number;
|
postId: number;
|
||||||
post: IPost;
|
post: IPost;
|
||||||
likes: LikesState;
|
likes: LikesState;
|
||||||
|
comments: CommentsState;
|
||||||
boards: Array<IBoard>;
|
boards: Array<IBoard>;
|
||||||
postStatuses: Array<IPostStatus>;
|
postStatuses: Array<IPostStatus>;
|
||||||
isLoggedIn: boolean;
|
isLoggedIn: boolean;
|
||||||
@@ -51,6 +54,7 @@ class PostP extends React.Component<Props> {
|
|||||||
const {
|
const {
|
||||||
post,
|
post,
|
||||||
likes,
|
likes,
|
||||||
|
comments,
|
||||||
boards,
|
boards,
|
||||||
postStatuses,
|
postStatuses,
|
||||||
|
|
||||||
@@ -66,6 +70,12 @@ class PostP extends React.Component<Props> {
|
|||||||
return (
|
return (
|
||||||
<div className="pageContainer">
|
<div className="pageContainer">
|
||||||
<div className="sidebar">
|
<div className="sidebar">
|
||||||
|
<PostUpdateList
|
||||||
|
postUpdates={comments.items.filter(comment => comment.isPostUpdate === true)}
|
||||||
|
areLoading={comments.areLoading}
|
||||||
|
error={comments.error}
|
||||||
|
/>
|
||||||
|
|
||||||
<LikeList
|
<LikeList
|
||||||
likes={likes.items}
|
likes={likes.items}
|
||||||
areLoading={likes.areLoading}
|
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) => ({
|
const mapStateToProps = (state: State) => ({
|
||||||
post: state.currentPost.item,
|
post: state.currentPost.item,
|
||||||
likes: state.currentPost.likes,
|
likes: state.currentPost.likes,
|
||||||
|
comments: state.currentPost.comments,
|
||||||
});
|
});
|
||||||
|
|
||||||
const mapDispatchToProps = (dispatch) => ({
|
const mapDispatchToProps = (dispatch) => ({
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ interface IComment {
|
|||||||
id: number;
|
id: number;
|
||||||
body: string;
|
body: string;
|
||||||
parentId: number;
|
parentId: number;
|
||||||
|
isPostUpdate: boolean;
|
||||||
userFullName: string;
|
userFullName: string;
|
||||||
userEmail: string;
|
userEmail: string;
|
||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ interface ICommentJSON {
|
|||||||
id: number;
|
id: number;
|
||||||
body: string;
|
body: string;
|
||||||
parent_id: number;
|
parent_id: number;
|
||||||
|
is_post_update: boolean;
|
||||||
user_full_name: string;
|
user_full_name: string;
|
||||||
user_email: string;
|
user_email: string;
|
||||||
updated_at: string;
|
updated_at: string;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ const initialState: IComment = {
|
|||||||
id: 0,
|
id: 0,
|
||||||
body: '',
|
body: '',
|
||||||
parentId: null,
|
parentId: null,
|
||||||
|
isPostUpdate: false,
|
||||||
userFullName: '<Unknown user>',
|
userFullName: '<Unknown user>',
|
||||||
userEmail: 'example@example.com',
|
userEmail: 'example@example.com',
|
||||||
updatedAt: undefined,
|
updatedAt: undefined,
|
||||||
@@ -24,6 +25,7 @@ const commentReducer = (
|
|||||||
id: action.comment.id,
|
id: action.comment.id,
|
||||||
body: action.comment.body,
|
body: action.comment.body,
|
||||||
parentId: action.comment.parent_id,
|
parentId: action.comment.parent_id,
|
||||||
|
isPostUpdate: action.comment.is_post_update,
|
||||||
userFullName: action.comment.user_full_name,
|
userFullName: action.comment.user_full_name,
|
||||||
userEmail: action.comment.user_email,
|
userEmail: action.comment.user_email,
|
||||||
updatedAt: action.comment.updated_at,
|
updatedAt: action.comment.updated_at,
|
||||||
|
|||||||
@@ -13,6 +13,43 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.sidebar {
|
.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 {
|
.likeListContainer {
|
||||||
@extend .sidebarCard;
|
@extend .sidebarCard;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class AddIsPostUpdateToComments < ActiveRecord::Migration[6.0]
|
||||||
|
def change
|
||||||
|
add_column :comments, :is_post_update, :boolean, null: false, default: false
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2019_09_27_094233) do
|
ActiveRecord::Schema.define(version: 2019_10_01_160859) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
@@ -31,6 +31,7 @@ ActiveRecord::Schema.define(version: 2019_09_27_094233) do
|
|||||||
t.bigint "parent_id"
|
t.bigint "parent_id"
|
||||||
t.datetime "created_at", precision: 6, null: false
|
t.datetime "created_at", precision: 6, null: false
|
||||||
t.datetime "updated_at", precision: 6, null: false
|
t.datetime "updated_at", precision: 6, null: false
|
||||||
|
t.boolean "is_post_update", default: false, null: false
|
||||||
t.index ["parent_id"], name: "index_comments_on_parent_id"
|
t.index ["parent_id"], name: "index_comments_on_parent_id"
|
||||||
t.index ["post_id"], name: "index_comments_on_post_id"
|
t.index ["post_id"], name: "index_comments_on_post_id"
|
||||||
t.index ["user_id"], name: "index_comments_on_user_id"
|
t.index ["user_id"], name: "index_comments_on_user_id"
|
||||||
|
|||||||
@@ -4,5 +4,6 @@ FactoryBot.define do
|
|||||||
user
|
user
|
||||||
post
|
post
|
||||||
parent { nil }
|
parent { nil }
|
||||||
|
is_post_update { false }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -41,4 +41,10 @@ RSpec.describe Comment, type: :model do
|
|||||||
|
|
||||||
expect(parent.children.length).to eq(2)
|
expect(parent.children.length).to eq(2)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'has a flag to tell if it is a post update that defaults to false' do
|
||||||
|
comment = Comment.new
|
||||||
|
|
||||||
|
expect(comment.is_post_update).to be_falsy
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user