Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display embed and text for short posts #790

Merged
merged 3 commits into from
Oct 13, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/Story/StoryHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const isPostWithEmbedBeforeFirstHalf = tagPositions => postWithAnEmbed(tagPositi

export {
getPositions,
postWithAnEmbed,
isPostStartsWithAPicture,
isPostStartsWithAnEmbed,
isPostWithPictureBeforeFirstHalf,
Expand Down
21 changes: 12 additions & 9 deletions src/components/Story/StoryPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { jsonParse } from '../../helpers/formatter';
import { image } from '../../vendor/steemitLinks';
import {
getPositions,
postWithAnEmbed,
isPostStartsWithAPicture,
isPostStartsWithAnEmbed,
isPostWithPictureBeforeFirstHalf,
Expand Down Expand Up @@ -37,7 +38,9 @@ const StoryPreview = ({ post }) => {
embeds[0] = {
type: 'video',
provider_name: 'DTube',
embed: `<video controls="true" autoplay="true" src="https://ipfs.io/ipfs/${video.content.videohash}" poster="https://ipfs.io/ipfs/${video.info.snaphash}"><track kind="captions" /></video>`,
embed: `<video controls="true" autoplay="true" src="https://ipfs.io/ipfs/${video.content
.videohash}" poster="https://ipfs.io/ipfs/${video.info
.snaphash}"><track kind="captions" /></video>`,
thumbnail: getProxyImageURL(`https://ipfs.io/ipfs/${video.info.snaphash}`, 'preview'),
};
}
Expand All @@ -47,10 +50,11 @@ const StoryPreview = ({ post }) => {

embed: () => embeds && embeds[0] && <PostFeedEmbed key="embed" embed={embeds[0]} />,

image: () =>
(<div key={imagePath} className="Story__content__img-container">
image: () => (
<div key={imagePath} className="Story__content__img-container">
<img alt="post" src={imagePath} />
</div>),
</div>
),
};

const htmlBody = getHtml(post.body, {}, 'text');
Expand All @@ -60,6 +64,9 @@ const StoryPreview = ({ post }) => {
if (hasVideo) {
bodyData.push(preview.embed());
bodyData.push(preview.text());
} else if (htmlBody.length <= 1500 && postWithAnEmbed(tagPositions, 100)) {
bodyData.push(preview.embed());
bodyData.push(preview.text());
} else if (isPostStartsWithAPicture(tagPositions)) {
bodyData.push(preview.image());
bodyData.push(preview.text());
Expand All @@ -76,11 +83,7 @@ const StoryPreview = ({ post }) => {
bodyData.push(preview.text());
}

return (
<div>
{bodyData}
</div>
);
return <div>{bodyData}</div>;
};

StoryPreview.propTypes = {
Expand Down
16 changes: 8 additions & 8 deletions src/stories/__snapshots__/stories.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2651,14 +2651,6 @@ exports[`Storyshots Story Inline story with embed 1`] = `
onClick={[Function]}
>
<div>
<div
className="Story__content__body"
dangerouslySetInnerHTML={
Object {
"__html": "Lots of good stuff for STEEM as he talks about Community Tokens / User Issued Tokens &amp; B2B Solutions, the Linear Reward Curve and many …",
}
}
/>
<div
className="PostFeedEmbed"
onClick={[Function]}
Expand All @@ -2677,6 +2669,14 @@ exports[`Storyshots Story Inline story with embed 1`] = `
src="https://i.ytimg.com/vi/YxFzGoDoLwU/hqdefault.jpg"
/>
</div>
<div
className="Story__content__body"
dangerouslySetInnerHTML={
Object {
"__html": "Lots of good stuff for STEEM as he talks about Community Tokens / User Issued Tokens &amp; B2B Solutions, the Linear Reward Curve and many …",
}
}
/>
</div>
</a>
</div>
Expand Down