--- /dev/null
+import { Component, linkEvent } from 'inferno';
+import * as moment from 'moment';
+
+interface MomentTimeProps {
+ data: {
+ published: string;
+ updated?: string;
+ }
+}
+
+export class MomentTime extends Component<MomentTimeProps, any> {
+
+ constructor(props, context) {
+ super(props, context);
+ }
+
+ render() {
+ if (this.props.data.updated) {
+ return (
+ <span className="font-italics">modified {moment.utc(this.props.data.updated).fromNow()}</span>
+ )
+ } else {
+ return (
+ <span>{moment.utc(this.props.data.published).fromNow()}</span>
+ )
+ }
+ }
+}
import { UserOperation, Community, Post as PostI, PostResponse, Comment, CommentForm as CommentFormI, CommentResponse } from '../interfaces';
import { WebSocketService, UserService } from '../services';
import { msgOp } from '../utils';
+import { MomentTime } from './moment-time';
interface CommentNodeI {
comment: Comment;
postHeader() {
let title = this.state.post.url
- ? <h5><a href={this.state.post.url}>{this.state.post.name}</a></h5>
+ ? <h5>
+ <a href={this.state.post.url}>{this.state.post.name}</a>
+ <small><a className="ml-2 text-muted font-italic" href={this.state.post.url}>{(new URL(this.state.post.url)).hostname}</a></small>
+ </h5>
: <h5>{this.state.post.name}</h5>;
return (
<div>
- {title}
- via {this.state.post.attributed_to} X hours ago
- {this.state.post.body}
- </div>
+ <div>{title}</div>
+ <div>via {this.state.post.attributed_to} <MomentTime data={this.state.post} /></div>
+ <div>{this.state.post.body}</div>
+ </div>
)
}
<div class="sticky-top">
<h4>New Comments</h4>
{this.state.comments.map(comment =>
- <CommentNodes nodes={[{comment: comment}]} />
+ <CommentNodes nodes={[{comment: comment}]} noIndent />
)}
</div>
)
interface CommentNodesProps {
nodes: Array<CommentNodeI>;
+ noIndent?: boolean;
}
export class CommentNodes extends Component<CommentNodesProps, CommentNodesState> {
return (
<div className="comments">
{this.props.nodes.map(node =>
- <div className={`comment ${node.comment.parent_id ? 'ml-4' : ''}`}>
+ <div className={`comment ${node.comment.parent_id && !this.props.noIndent ? 'ml-4' : ''}`}>
<div className="float-left small text-center">
<div className="pointer upvote">▲</div>
<div>20</div>
</li>
<li className="list-inline-item">
<span>(
- <span className="text-info"> +1300</span>
+ <span className="text-info">+1300</span>
<span> | </span>
<span className="text-danger">-29</span>
- <span> ) points</span>
+ <span>) </span>
</span>
</li>
<li className="list-inline-item">
- <span>X hours ago</span>
+ <span><MomentTime data={node.comment} /></span>
</li>
</ul>
<p className="mb-0">{node.comment.content}</p>
<title>rust-reddit-fediverse</title>
<link rel="stylesheet" href="https://bootswatch.com/4/darkly/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/balloon-css/0.5.0/balloon.min.css">
+ <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,400i,700,800" rel="stylesheet">
</head>
<body>