diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 1828e96a..39423c75 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -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', diff --git a/app/javascript/components/Post/PostP.tsx b/app/javascript/components/Post/PostP.tsx index 7dbf4b19..d4053359 100644 --- a/app/javascript/components/Post/PostP.tsx +++ b/app/javascript/components/Post/PostP.tsx @@ -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; postStatuses: Array; isLoggedIn: boolean; @@ -51,6 +54,7 @@ class PostP extends React.Component { const { post, likes, + comments, boards, postStatuses, @@ -66,6 +70,12 @@ class PostP extends React.Component { return (
+ comment.isPostUpdate === true)} + areLoading={comments.areLoading} + error={comments.error} + /> + ; + areLoading: boolean; + error: string; +} + +const PostUpdateList = ({ + postUpdates, + areLoading, + error, +}: Props) => ( +
+ Post updates: + { areLoading ? : null } + { error ? {error} : null } +
+ { postUpdates.length === 0 ? There are not post updates yet. : null } + { + postUpdates.map((postUpdate, i) => ( +
+
+ + {postUpdate.userFullName} +
+ +

{postUpdate.body}

+ + {friendlyDate(postUpdate.updatedAt)} +
+ )) + } +
+
+); + +export default PostUpdateList; \ No newline at end of file diff --git a/app/javascript/containers/Post.tsx b/app/javascript/containers/Post.tsx index 754d1672..fd344271 100644 --- a/app/javascript/containers/Post.tsx +++ b/app/javascript/containers/Post.tsx @@ -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) => ({ diff --git a/app/javascript/interfaces/IComment.ts b/app/javascript/interfaces/IComment.ts index fa0bdb4f..e36cd7fd 100644 --- a/app/javascript/interfaces/IComment.ts +++ b/app/javascript/interfaces/IComment.ts @@ -2,6 +2,7 @@ interface IComment { id: number; body: string; parentId: number; + isPostUpdate: boolean; userFullName: string; userEmail: string; updatedAt: string; diff --git a/app/javascript/interfaces/json/IComment.ts b/app/javascript/interfaces/json/IComment.ts index 50be0730..2de93cc0 100644 --- a/app/javascript/interfaces/json/IComment.ts +++ b/app/javascript/interfaces/json/IComment.ts @@ -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; diff --git a/app/javascript/reducers/commentReducer.ts b/app/javascript/reducers/commentReducer.ts index 7328bef2..54d14acc 100644 --- a/app/javascript/reducers/commentReducer.ts +++ b/app/javascript/reducers/commentReducer.ts @@ -9,6 +9,7 @@ const initialState: IComment = { id: 0, body: '', parentId: null, + isPostUpdate: false, userFullName: '', 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, diff --git a/app/javascript/stylesheets/components/Post.scss b/app/javascript/stylesheets/components/Post.scss index f5056456..68a79015 100644 --- a/app/javascript/stylesheets/components/Post.scss +++ b/app/javascript/stylesheets/components/Post.scss @@ -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; diff --git a/db/migrate/20191001160859_add_is_post_update_to_comments.rb b/db/migrate/20191001160859_add_is_post_update_to_comments.rb new file mode 100644 index 00000000..679728da --- /dev/null +++ b/db/migrate/20191001160859_add_is_post_update_to_comments.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index bde2c8ff..c16adc13 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # 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 enable_extension "plpgsql" @@ -31,6 +31,7 @@ ActiveRecord::Schema.define(version: 2019_09_27_094233) do t.bigint "parent_id" t.datetime "created_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 ["post_id"], name: "index_comments_on_post_id" t.index ["user_id"], name: "index_comments_on_user_id" diff --git a/spec/factories/comments.rb b/spec/factories/comments.rb index 58909ffd..20d62c03 100644 --- a/spec/factories/comments.rb +++ b/spec/factories/comments.rb @@ -4,5 +4,6 @@ FactoryBot.define do user post parent { nil } + is_post_update { false } end end diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index 8047464b..24dd4263 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -41,4 +41,10 @@ RSpec.describe Comment, type: :model do expect(parent.children.length).to eq(2) 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