|
1 | 1 | import React, { Component } from 'react' |
2 | 2 |
|
3 | | -const thumbsImage = require('../images/thumbs.png'); |
4 | | -const commentsImage = require('../images/comments.png'); |
5 | | -const dummyUserImage = require('../images/dummyUser.png'); |
| 3 | +const thumbsImage = require('../images/thumbs.png') |
| 4 | +const commentsImage = require('../images/comments.png') |
| 5 | +const dummyUserImage = require('../images/dummyUser.png') |
6 | 6 |
|
7 | 7 | export class PostCard extends Component { |
8 | | - constructor(props) { |
9 | | - super(props); |
10 | | - } |
| 8 | + getReplacedImage (src) { |
| 9 | + var newSrc = 'https://cdn.hashnode.com/res/hashnode/image/upload/' |
| 10 | + var parts = src.split('/upload/') |
| 11 | + var format = parts[1].substring(parts[1].lastIndexOf('.') + 1) |
| 12 | + var imageNameParts = parts[1].substring(1, src.split('/upload/')[1].length).split('/') |
| 13 | + newSrc += |
| 14 | + imageNameParts[1].split('.')[0] + '/' + imageNameParts[0] + '.' + format |
| 15 | + return newSrc |
| 16 | + } |
11 | 17 |
|
12 | | - getReplacedImage(src) { |
13 | | - var newSrc = 'https://cdn.hashnode.com/res/hashnode/image/upload/'; |
14 | | - var parts = src.split('/upload/'); |
15 | | - var format = parts[1].substring(parts[1].lastIndexOf('.') + 1); |
16 | | - var imageNameParts = parts[1].substring(1, src.split('/upload/')[1].length).split('/'); |
17 | | - newSrc += (imageNameParts[1].split('.')[0] + '/' + imageNameParts[0] + '.' + format); |
18 | | - return newSrc; |
19 | | - } |
| 18 | + loadProfileImage (src) { |
| 19 | + if (!src) { |
| 20 | + return |
| 21 | + } |
| 22 | + if (src.indexOf('//res.cloudinary.com') !== -1 && src.indexOf('/upload/') !== -1) { |
| 23 | + return this.getReplacedImage(src) |
| 24 | + } |
| 25 | + return src |
| 26 | + } |
20 | 27 |
|
21 | | - loadProfileImage(src) { |
22 | | - if (!src) { |
23 | | - return; |
24 | | - } |
25 | | - if (src.indexOf('//res.cloudinary.com') !== -1 && src.indexOf('/upload/') !== -1) { |
26 | | - return this.getReplacedImage(src); |
27 | | - } |
28 | | - return src; |
29 | | - } |
| 28 | + render () { |
| 29 | + const post = this.props.post |
30 | 30 |
|
31 | | - render() { |
32 | | - |
33 | | - const post = this.props.post; |
34 | | - |
35 | | - return ( |
36 | | - <div> |
37 | | - {post.coverImage && <img className="post-cover" src={post.coverImage} width="100%" />} |
38 | | - <div className="post-details"> |
39 | | - <a href={`https://hashnode.com/post/${post.slug}-${post.cuid}?utm_source=chrome_extension&utm_medium=extension`} target="_blank"> |
40 | | - <h3 className="post-title">{post.title}</h3> |
41 | | - <p className="post-desc"> |
42 | | - {post.brief.substring(0, 140)}... |
43 | | - </p> |
44 | | - </a> |
45 | | - <div className="post-footer"> |
46 | | - <a href={`${post.author ? 'https://hashnode.com/@' + post.author.username + '?utm_source=chrome_extension&utm_medium=extension' : ''}`} target="_blank" className="author" |
47 | | - style={{ |
48 | | - backgroundImage: 'url("' + ((post.author && post.author.photo && this.loadProfileImage(post.author.photo)) || dummyUserImage) + '")' |
49 | | - }} |
50 | | - > |
51 | | - {/* <img src={((post.author && post.author.photo && this.loadProfileImage(post.author.photo)) || dummyUserImage)} /> */} |
52 | | - </a> |
53 | | - <div className="post-activity"> |
54 | | - <a href={`https://hashnode.com/post/${post.slug}-${post.cuid}?utm_source=chrome_extension&utm_medium=extension`} target="_blank" className="reactions"> |
55 | | - <img src={thumbsImage} /> |
56 | | - {post.totalReactions} |
57 | | - </a> |
58 | | - <a href={`https://hashnode.com/post/${post.slug}-${post.cuid}?utm_source=chrome_extension&utm_medium=extension`} target="_blank" className="comments"> |
59 | | - <img src={commentsImage} /> |
60 | | - {post.responseCount} |
61 | | - </a> |
62 | | - </div> |
63 | | - </div> |
64 | | - </div> |
65 | | - </div> |
66 | | - ) |
67 | | - } |
| 31 | + return ( |
| 32 | + <div> |
| 33 | + {post.coverImage && ( |
| 34 | + <img className='post-cover' src={post.coverImage} width='100%' /> |
| 35 | + )} |
| 36 | + <div className='post-details'> |
| 37 | + <a |
| 38 | + href={`https://hashnode.com/post/${post.slug}-${ |
| 39 | + post.cuid |
| 40 | + }?utm_source=chrome_extension&utm_medium=extension`} |
| 41 | + target='_blank' |
| 42 | + > |
| 43 | + <h3 className='post-title'>{post.title}</h3> |
| 44 | + <p className='post-desc'>{post.brief.substring(0, 140)}...</p> |
| 45 | + </a> |
| 46 | + <div className='post-footer'> |
| 47 | + <a |
| 48 | + href={`${ |
| 49 | + post.author |
| 50 | + ? 'https://hashnode.com/@' + |
| 51 | + post.author.username + |
| 52 | + '?utm_source=chrome_extension&utm_medium=extension' |
| 53 | + : '' |
| 54 | + }`} |
| 55 | + target='_blank' |
| 56 | + className='author' |
| 57 | + style={{ |
| 58 | + backgroundImage: |
| 59 | + 'url("' + |
| 60 | + ((post.author && |
| 61 | + post.author.photo && |
| 62 | + this.loadProfileImage(post.author.photo)) || |
| 63 | + dummyUserImage) + |
| 64 | + '")' |
| 65 | + }} |
| 66 | + > |
| 67 | + {/* <img src={((post.author && post.author.photo && this.loadProfileImage(post.author.photo)) || dummyUserImage)} /> */} |
| 68 | + </a> |
| 69 | + <div className='post-activity'> |
| 70 | + <a |
| 71 | + href={`https://hashnode.com/post/${post.slug}-${ |
| 72 | + post.cuid |
| 73 | + }?utm_source=chrome_extension&utm_medium=extension`} |
| 74 | + target='_blank' |
| 75 | + className='reactions' |
| 76 | + > |
| 77 | + <img src={thumbsImage} /> |
| 78 | + {post.totalReactions} |
| 79 | + </a> |
| 80 | + <a |
| 81 | + href={`https://hashnode.com/post/${post.slug}-${ |
| 82 | + post.cuid |
| 83 | + }?utm_source=chrome_extension&utm_medium=extension`} |
| 84 | + target='_blank' |
| 85 | + className='comments' |
| 86 | + > |
| 87 | + <img src={commentsImage} /> |
| 88 | + {post.responseCount} |
| 89 | + </a> |
| 90 | + </div> |
| 91 | + </div> |
| 92 | + </div> |
| 93 | + </div> |
| 94 | + ) |
| 95 | + } |
68 | 96 | } |
69 | 97 |
|
70 | 98 | export default PostCard |
0 commit comments