mirror of
https://github.com/astuto/astuto.git
synced 2025-12-15 11:17:49 +01:00
Improve Post component
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import * as React from 'react';
|
||||
|
||||
import PostStatusLabel from '../shared/PostStatusLabel';
|
||||
|
||||
import IPostStatus from '../../interfaces/IPostStatus';
|
||||
|
||||
interface Props {
|
||||
@@ -26,15 +28,7 @@ const PostListItem = ({ id, title, description, postStatus}: Props) => (
|
||||
<span className="comment icon"></span>
|
||||
<span>0 comments</span>
|
||||
</div>
|
||||
{
|
||||
postStatus ?
|
||||
<div className="postDetailsStatus">
|
||||
<div className="dot" style={{backgroundColor: postStatus.color}}></div>
|
||||
<span className="postStatusName">{postStatus.name}</span>
|
||||
</div>
|
||||
:
|
||||
null
|
||||
}
|
||||
{ postStatus ? <PostStatusLabel {...postStatus} /> : null }
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import * as React from 'react';
|
||||
|
||||
import PostStatusLabel from '../shared/PostStatusLabel';
|
||||
|
||||
interface Props {
|
||||
name: string;
|
||||
color: string;
|
||||
@@ -19,8 +21,7 @@ const PostStatusListItem = ({
|
||||
<div className={"postStatusListItemContainer " + `postStatus${name.replace(/ /g, '')}`}>
|
||||
<a onClick={handleClick} className="postStatusListItemLink">
|
||||
<div className="postStatusListItem">
|
||||
<div className="dot" style={{backgroundColor: color}}></div>
|
||||
<span className="postStatusName">{name}</span>
|
||||
<PostStatusLabel id={undefined} name={name} color={color} />
|
||||
</div>
|
||||
</a>
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@ import IPost from '../../interfaces/IPost';
|
||||
import IPostStatus from '../../interfaces/IPostStatus';
|
||||
|
||||
import PostStatusSelect from './PostStatusSelect';
|
||||
import PostStatusLabel from '../shared/PostStatusLabel';
|
||||
|
||||
interface Props {
|
||||
postId: number;
|
||||
@@ -39,9 +40,9 @@ class PostP extends React.Component<Props> {
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1>{post.title}</h1>
|
||||
<h2>{post.title}</h2>
|
||||
{
|
||||
isPowerUser ?
|
||||
isPowerUser && post ?
|
||||
<PostStatusSelect
|
||||
postStatuses={postStatuses}
|
||||
selectedPostStatusId={post.postStatusId}
|
||||
@@ -50,7 +51,9 @@ class PostP extends React.Component<Props> {
|
||||
}
|
||||
/>
|
||||
:
|
||||
<span>LLL</span>
|
||||
<PostStatusLabel
|
||||
{...postStatuses.find(postStatus => postStatus.id === post.postStatusId)}
|
||||
/>
|
||||
}
|
||||
|
||||
<p>{post.description}</p>
|
||||
|
||||
@@ -18,7 +18,7 @@ const PostStatusSelect = ({
|
||||
handleChange,
|
||||
}: Props) => (
|
||||
<select
|
||||
value={selectedPostStatusId || ''}
|
||||
value={selectedPostStatusId || 'none'}
|
||||
onChange={
|
||||
(e: FormEvent) => (
|
||||
handleChange(parseInt((e.target as HTMLSelectElement).value))
|
||||
@@ -30,7 +30,7 @@ const PostStatusSelect = ({
|
||||
{postStatus.name}
|
||||
</option>
|
||||
))}
|
||||
<option>None</option>
|
||||
<option value="none">None</option>
|
||||
</select>
|
||||
);
|
||||
|
||||
|
||||
16
app/javascript/components/shared/PostStatusLabel.tsx
Normal file
16
app/javascript/components/shared/PostStatusLabel.tsx
Normal file
@@ -0,0 +1,16 @@
|
||||
import * as React from 'react';
|
||||
|
||||
import IPostStatus from '../../interfaces/IPostStatus';
|
||||
|
||||
const PostStatusLabel = ({
|
||||
id,
|
||||
name,
|
||||
color,
|
||||
}: IPostStatus) => (
|
||||
<div style={{display: 'flex'}}>
|
||||
<div className="dot" style={{backgroundColor: color}}></div>
|
||||
<span className="postStatusName">{name}</span>
|
||||
</div>
|
||||
);
|
||||
|
||||
export default PostStatusLabel;
|
||||
@@ -17,6 +17,8 @@ const mapDispatchToProps = (dispatch) => ({
|
||||
},
|
||||
|
||||
changePostStatus(postId: number, newPostStatusId: number, authenticityToken: string) {
|
||||
if (isNaN(newPostStatusId)) newPostStatusId = null;
|
||||
|
||||
dispatch(changePostStatus(postId, newPostStatusId, authenticityToken));
|
||||
},
|
||||
});
|
||||
|
||||
@@ -9,4 +9,14 @@
|
||||
|
||||
.gravatar {
|
||||
border-radius: 16px;
|
||||
}
|
||||
|
||||
.dot {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
border-radius: 100%;
|
||||
|
||||
margin-top: auto;
|
||||
margin-bottom: auto;
|
||||
margin-right: 4px;
|
||||
}
|
||||
@@ -199,16 +199,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
.dot {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
border-radius: 100%;
|
||||
|
||||
margin-top: auto;
|
||||
margin-bottom: auto;
|
||||
margin-right: 4px;
|
||||
}
|
||||
|
||||
.infoText {
|
||||
display: block;
|
||||
text-align: center;
|
||||
|
||||
@@ -34,12 +34,6 @@
|
||||
border-bottom-width: 1px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.dot {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
border-radius: 100%;
|
||||
}
|
||||
|
||||
.infoText {
|
||||
text-align: center;
|
||||
@@ -47,7 +41,6 @@
|
||||
}
|
||||
|
||||
.columnTitle {
|
||||
margin: 0 8px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user