mirror of
https://github.com/astuto/astuto.git
synced 2025-12-15 11:17:49 +01:00
Add edit link to posts and comments
This commit is contained in:
@@ -2,6 +2,7 @@ import * as React from 'react';
|
||||
import { FormEvent } from 'react';
|
||||
|
||||
import NewComment from './NewComment';
|
||||
import Separator from '../shared/Separator';
|
||||
import { MutedText } from '../shared/CustomTexts';
|
||||
|
||||
import { CommentRepliesState } from '../../reducers/commentRepliesReducer';
|
||||
@@ -22,6 +23,7 @@ interface Props {
|
||||
handleSubmitComment(body: string, parentId: number): void;
|
||||
|
||||
isLoggedIn: boolean;
|
||||
isPowerUser: boolean;
|
||||
}
|
||||
|
||||
const Comment = ({
|
||||
@@ -38,6 +40,7 @@ const Comment = ({
|
||||
handleSubmitComment,
|
||||
|
||||
isLoggedIn,
|
||||
isPowerUser,
|
||||
}: Props) => (
|
||||
<div className="comment">
|
||||
<div className="commentHeader">
|
||||
@@ -48,7 +51,16 @@ const Comment = ({
|
||||
<a className="commentReplyButton" onClick={handleToggleCommentReply}>
|
||||
{ reply.isOpen ? 'Cancel' : 'Reply' }
|
||||
</a>
|
||||
•
|
||||
{
|
||||
isPowerUser ?
|
||||
<React.Fragment>
|
||||
<Separator />
|
||||
<a href={`/admin/comments/${id}`} data-turbolinks="false">Edit</a>
|
||||
</React.Fragment>
|
||||
:
|
||||
null
|
||||
}
|
||||
<Separator />
|
||||
<MutedText>{friendlyDate(updatedAt)}</MutedText>
|
||||
</div>
|
||||
{
|
||||
|
||||
@@ -17,6 +17,7 @@ interface Props {
|
||||
handleSubmitComment(body: string, parentId: number): void;
|
||||
|
||||
isLoggedIn: boolean;
|
||||
isPowerUser: boolean;
|
||||
}
|
||||
|
||||
const CommentList = ({
|
||||
@@ -30,6 +31,7 @@ const CommentList = ({
|
||||
handleSubmitComment,
|
||||
|
||||
isLoggedIn,
|
||||
isPowerUser,
|
||||
}: Props) => (
|
||||
<React.Fragment>
|
||||
{comments.map((comment, i) => {
|
||||
@@ -49,6 +51,7 @@ const CommentList = ({
|
||||
{...comment}
|
||||
|
||||
isLoggedIn={isLoggedIn}
|
||||
isPowerUser={isPowerUser}
|
||||
/>
|
||||
|
||||
<CommentList
|
||||
@@ -62,6 +65,7 @@ const CommentList = ({
|
||||
handleSubmitComment={handleSubmitComment}
|
||||
|
||||
isLoggedIn={isLoggedIn}
|
||||
isPowerUser={isPowerUser}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -12,6 +12,7 @@ import { CommentRepliesState } from '../../reducers/commentRepliesReducer';
|
||||
interface Props {
|
||||
postId: number;
|
||||
isLoggedIn: boolean;
|
||||
isPowerUser: boolean;
|
||||
authenticityToken: string;
|
||||
|
||||
comments: Array<IComment>;
|
||||
@@ -47,6 +48,7 @@ class CommentsP extends React.Component<Props> {
|
||||
render() {
|
||||
const {
|
||||
isLoggedIn,
|
||||
isPowerUser,
|
||||
|
||||
comments,
|
||||
replies,
|
||||
@@ -92,6 +94,7 @@ class CommentsP extends React.Component<Props> {
|
||||
parentId={null}
|
||||
level={1}
|
||||
isLoggedIn={isLoggedIn}
|
||||
isPowerUser={isPowerUser}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -65,7 +65,13 @@ class PostP extends React.Component<Props> {
|
||||
|
||||
<div className="postAndCommentsContainer">
|
||||
<div className="postContainer">
|
||||
<h2>{post.title}</h2>
|
||||
<div className="postHeader">
|
||||
<h2>{post.title}</h2>
|
||||
{
|
||||
isPowerUser && post ?
|
||||
<a href={`/admin/posts/${post.id}`} data-turbolinks="false">Edit</a> : null
|
||||
}
|
||||
</div>
|
||||
{
|
||||
isPowerUser && post ?
|
||||
<div className="postSettings">
|
||||
@@ -101,6 +107,7 @@ class PostP extends React.Component<Props> {
|
||||
<Comments
|
||||
postId={this.props.postId}
|
||||
isLoggedIn={isLoggedIn}
|
||||
isPowerUser={isPowerUser}
|
||||
authenticityToken={authenticityToken}
|
||||
/>
|
||||
</div>
|
||||
|
||||
5
app/javascript/components/shared/Separator.tsx
Normal file
5
app/javascript/components/shared/Separator.tsx
Normal file
@@ -0,0 +1,5 @@
|
||||
import * as React from 'react';
|
||||
|
||||
const Separator = () => <span> • </span>
|
||||
|
||||
export default Separator;
|
||||
@@ -26,6 +26,18 @@
|
||||
}
|
||||
}
|
||||
|
||||
.postHeader {
|
||||
@extend
|
||||
.d-flex;
|
||||
|
||||
a {
|
||||
@extend
|
||||
.ml-1;
|
||||
|
||||
line-height: 1em;
|
||||
}
|
||||
}
|
||||
|
||||
.postSettings {
|
||||
@extend
|
||||
.d-flex,
|
||||
|
||||
Reference in New Issue
Block a user