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 { FormEvent } from 'react';
|
||||||
|
|
||||||
import NewComment from './NewComment';
|
import NewComment from './NewComment';
|
||||||
|
import Separator from '../shared/Separator';
|
||||||
import { MutedText } from '../shared/CustomTexts';
|
import { MutedText } from '../shared/CustomTexts';
|
||||||
|
|
||||||
import { CommentRepliesState } from '../../reducers/commentRepliesReducer';
|
import { CommentRepliesState } from '../../reducers/commentRepliesReducer';
|
||||||
@@ -22,6 +23,7 @@ interface Props {
|
|||||||
handleSubmitComment(body: string, parentId: number): void;
|
handleSubmitComment(body: string, parentId: number): void;
|
||||||
|
|
||||||
isLoggedIn: boolean;
|
isLoggedIn: boolean;
|
||||||
|
isPowerUser: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Comment = ({
|
const Comment = ({
|
||||||
@@ -38,6 +40,7 @@ const Comment = ({
|
|||||||
handleSubmitComment,
|
handleSubmitComment,
|
||||||
|
|
||||||
isLoggedIn,
|
isLoggedIn,
|
||||||
|
isPowerUser,
|
||||||
}: Props) => (
|
}: Props) => (
|
||||||
<div className="comment">
|
<div className="comment">
|
||||||
<div className="commentHeader">
|
<div className="commentHeader">
|
||||||
@@ -48,7 +51,16 @@ const Comment = ({
|
|||||||
<a className="commentReplyButton" onClick={handleToggleCommentReply}>
|
<a className="commentReplyButton" onClick={handleToggleCommentReply}>
|
||||||
{ reply.isOpen ? 'Cancel' : 'Reply' }
|
{ reply.isOpen ? 'Cancel' : 'Reply' }
|
||||||
</a>
|
</a>
|
||||||
•
|
{
|
||||||
|
isPowerUser ?
|
||||||
|
<React.Fragment>
|
||||||
|
<Separator />
|
||||||
|
<a href={`/admin/comments/${id}`} data-turbolinks="false">Edit</a>
|
||||||
|
</React.Fragment>
|
||||||
|
:
|
||||||
|
null
|
||||||
|
}
|
||||||
|
<Separator />
|
||||||
<MutedText>{friendlyDate(updatedAt)}</MutedText>
|
<MutedText>{friendlyDate(updatedAt)}</MutedText>
|
||||||
</div>
|
</div>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ interface Props {
|
|||||||
handleSubmitComment(body: string, parentId: number): void;
|
handleSubmitComment(body: string, parentId: number): void;
|
||||||
|
|
||||||
isLoggedIn: boolean;
|
isLoggedIn: boolean;
|
||||||
|
isPowerUser: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CommentList = ({
|
const CommentList = ({
|
||||||
@@ -30,6 +31,7 @@ const CommentList = ({
|
|||||||
handleSubmitComment,
|
handleSubmitComment,
|
||||||
|
|
||||||
isLoggedIn,
|
isLoggedIn,
|
||||||
|
isPowerUser,
|
||||||
}: Props) => (
|
}: Props) => (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
{comments.map((comment, i) => {
|
{comments.map((comment, i) => {
|
||||||
@@ -49,6 +51,7 @@ const CommentList = ({
|
|||||||
{...comment}
|
{...comment}
|
||||||
|
|
||||||
isLoggedIn={isLoggedIn}
|
isLoggedIn={isLoggedIn}
|
||||||
|
isPowerUser={isPowerUser}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<CommentList
|
<CommentList
|
||||||
@@ -62,6 +65,7 @@ const CommentList = ({
|
|||||||
handleSubmitComment={handleSubmitComment}
|
handleSubmitComment={handleSubmitComment}
|
||||||
|
|
||||||
isLoggedIn={isLoggedIn}
|
isLoggedIn={isLoggedIn}
|
||||||
|
isPowerUser={isPowerUser}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import { CommentRepliesState } from '../../reducers/commentRepliesReducer';
|
|||||||
interface Props {
|
interface Props {
|
||||||
postId: number;
|
postId: number;
|
||||||
isLoggedIn: boolean;
|
isLoggedIn: boolean;
|
||||||
|
isPowerUser: boolean;
|
||||||
authenticityToken: string;
|
authenticityToken: string;
|
||||||
|
|
||||||
comments: Array<IComment>;
|
comments: Array<IComment>;
|
||||||
@@ -47,6 +48,7 @@ class CommentsP extends React.Component<Props> {
|
|||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
isLoggedIn,
|
isLoggedIn,
|
||||||
|
isPowerUser,
|
||||||
|
|
||||||
comments,
|
comments,
|
||||||
replies,
|
replies,
|
||||||
@@ -92,6 +94,7 @@ class CommentsP extends React.Component<Props> {
|
|||||||
parentId={null}
|
parentId={null}
|
||||||
level={1}
|
level={1}
|
||||||
isLoggedIn={isLoggedIn}
|
isLoggedIn={isLoggedIn}
|
||||||
|
isPowerUser={isPowerUser}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -65,7 +65,13 @@ class PostP extends React.Component<Props> {
|
|||||||
|
|
||||||
<div className="postAndCommentsContainer">
|
<div className="postAndCommentsContainer">
|
||||||
<div className="postContainer">
|
<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 ?
|
isPowerUser && post ?
|
||||||
<div className="postSettings">
|
<div className="postSettings">
|
||||||
@@ -101,6 +107,7 @@ class PostP extends React.Component<Props> {
|
|||||||
<Comments
|
<Comments
|
||||||
postId={this.props.postId}
|
postId={this.props.postId}
|
||||||
isLoggedIn={isLoggedIn}
|
isLoggedIn={isLoggedIn}
|
||||||
|
isPowerUser={isPowerUser}
|
||||||
authenticityToken={authenticityToken}
|
authenticityToken={authenticityToken}
|
||||||
/>
|
/>
|
||||||
</div>
|
</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 {
|
.postSettings {
|
||||||
@extend
|
@extend
|
||||||
.d-flex,
|
.d-flex,
|
||||||
|
|||||||
Reference in New Issue
Block a user