diff --git a/apps/publish/src/js/components/blog.js b/apps/publish/src/js/components/blog.js
new file mode 100644
index 000000000..5af775b36
--- /dev/null
+++ b/apps/publish/src/js/components/blog.js
@@ -0,0 +1,91 @@
+import React, { Component } from 'react';
+import classnames from 'classnames';
+import { PostPreview } from '/components/post-preview';
+
+
+export class Blog extends Component {
+ constructor(props){
+ super(props)
+ }
+
+
+ buildPosts(){
+ let blogId = this.props.blogId;
+ let ship = this.props.ship;
+ let blog = this.retrieveColl(blogId, ship);
+
+ console.log("buildposts", blog);
+
+ let pinProps = blog.order.pin.map((post) => {
+ return this.buildPostPreviewProps(post, blogId, ship, true);
+ });
+
+ let unpinProps = blog.order.unpin.map((post) => {
+ return this.buildPostPreviewProps(post, blogId, ship, false);
+ });
+
+ return pinProps.concat(unpinProps);
+ }
+
+ buildPostPreviewProps(post, coll, who, pinned){
+ let pos = this.retrievePost(post, coll, who);
+ let col = this.retrieveColl(coll, who);
+ let com = this.retrieveComments(post, coll, who);
+
+ return {
+ postTitle: pos.info.title,
+ postName: post,
+ postSnippet: "body snippet",
+ numComments: com.length,
+ collectionTitle: col.title,
+ collectionName: coll,
+ author: who,
+ date: pos.info["date-created"],
+ pinned: pinned,
+ }
+
+ }
+
+ retrievePost(post, coll, who) {
+ if (who === window.ship) {
+ return this.props.pubs[coll].posts[post].post;
+ } else {
+ return this.props.subs[who][coll].posts[post].post;
+ }
+ }
+
+ retrieveComments(post, coll, who) {
+ if (who === window.ship) {
+ return this.props.pubs[coll].posts[post].comments;
+ } else {
+ return this.props.subs[who][coll].posts[post].comments;
+ }
+ }
+
+ retrieveColl(coll, who) {
+ if (who === window.ship) {
+ return this.props.pubs[coll];
+ } else {
+ return this.props.subs[who][coll];
+ }
+ }
+
+ render() {
+ let postProps = this.buildPosts();
+
+ let posts = postProps.map((post) => {
+ return (
+
- {comments} -
- -- {this.props.post.collectionTitle} -
-{authorDate}
diff --git a/apps/publish/src/js/components/recent-preview.js b/apps/publish/src/js/components/recent-preview.js new file mode 100644 index 000000000..175b6d58f --- /dev/null +++ b/apps/publish/src/js/components/recent-preview.js @@ -0,0 +1,71 @@ +import React, { Component } from 'react'; +import classnames from 'classnames'; +import { dateToDa } from '/lib/util'; +import moment from 'moment'; +import { Link } from 'react-router-dom'; + + +export class RecentPreview extends Component { + constructor(props) { + super(props); + + moment.updateLocale('en', { + relativeTime: { + past: function(input) { + return input === 'just now' + ? input + : input + ' ago' + }, + s : 'just now', + future : 'in %s', + m : '1m', + mm : '%dm', + h : '1h', + hh : '%dh', + d : '1d', + dd : '%dd', + M : '1 month', + MM : '%d months', + y : '1 year', + yy : '%d years', + } + }); + } + + render() { + let comments = this.props.post.numComments == 1 + ? '1 comment' + : `${this.props.post.numComments} comments` + let date = moment(this.props.post.date).fromNow(); + let authorDate = `~${this.props.post.author} • ${date}` + let collLink = "/~publish/~" + + this.props.post.author + "/" + + this.props.post.collectionName; + let postLink = collLink + "/" + this.props.post.postName; + + return ( ++ {this.props.post.postTitle} +
++ {this.props.post.postSnippet} +
+ ++ {comments} +
+ ++ {this.props.post.collectionTitle} +
+ ++ {authorDate} +
+