diff --git a/webapp/components/post_view/components/post_body_additional_content.jsx b/webapp/components/post_view/components/post_body_additional_content.jsx
index 1300312337..1806811000 100644
--- a/webapp/components/post_view/components/post_body_additional_content.jsx
+++ b/webapp/components/post_view/components/post_body_additional_content.jsx
@@ -23,19 +23,20 @@ export default class PostBodyAdditionalContent extends React.Component {
this.toggleEmbedVisibility = this.toggleEmbedVisibility.bind(this);
this.isLinkToggleable = this.isLinkToggleable.bind(this);
this.handleLinkLoadError = this.handleLinkLoadError.bind(this);
+ this.handleLinkLoaded = this.handleLinkLoaded.bind(this);
this.state = {
embedVisible: props.previewCollapsed.startsWith('false'),
link: Utils.extractFirstLink(props.post.message),
- linkLoadError: false
+ linkLoadError: false,
+ linkLoaded: false
};
}
componentWillReceiveProps(nextProps) {
this.setState({
embedVisible: nextProps.previewCollapsed.startsWith('false'),
- link: Utils.extractFirstLink(nextProps.post.message),
- linkLoadError: false
+ link: Utils.extractFirstLink(nextProps.post.message)
});
}
@@ -52,6 +53,9 @@ export default class PostBodyAdditionalContent extends React.Component {
if (nextState.linkLoadError !== this.state.linkLoadError) {
return true;
}
+ if (nextState.linkLoaded !== this.state.linkLoaded) {
+ return true;
+ }
return false;
}
@@ -105,6 +109,12 @@ export default class PostBodyAdditionalContent extends React.Component {
});
}
+ handleLinkLoaded() {
+ this.setState({
+ linkLoaded: true
+ });
+ }
+
generateToggleableEmbed() {
const link = this.state.link;
if (!link) {
@@ -127,6 +137,8 @@ export default class PostBodyAdditionalContent extends React.Component {
channelId={this.props.post.channel_id}
link={link}
onLinkLoadError={this.handleLinkLoadError}
+ onLinkLoaded={this.handleLinkLoaded}
+ childComponentDidUpdateFunction={this.props.childComponentDidUpdateFunction}
/>
);
}
@@ -174,11 +186,13 @@ export default class PostBodyAdditionalContent extends React.Component {
);
- let contents;
- if (prependToggle) {
- contents = [toggle, message];
- } else {
- contents = [message, toggle];
+ const contents = [message];
+ if (this.state.linkLoaded) {
+ if (prependToggle) {
+ contents.unshift(toggle);
+ } else {
+ contents.push(toggle);
+ }
}
if (this.state.embedVisible) {
diff --git a/webapp/components/post_view/components/post_image.jsx b/webapp/components/post_view/components/post_image.jsx
index 2bdc5efc02..1268c9df27 100644
--- a/webapp/components/post_view/components/post_image.jsx
+++ b/webapp/components/post_view/components/post_image.jsx
@@ -32,6 +32,9 @@ export default class PostImageEmbed extends React.Component {
}
componentDidUpdate(prevProps) {
+ if (this.state.loaded && this.props.childComponentDidUpdateFunction) {
+ this.props.childComponentDidUpdateFunction();
+ }
if (!this.state.loaded && prevProps.link !== this.props.link) {
this.loadImg(this.props.link);
}
@@ -46,8 +49,12 @@ export default class PostImageEmbed extends React.Component {
handleLoadComplete() {
this.setState({
- loaded: true
+ loaded: true,
+ errored: false
});
+ if (this.props.onLinkLoaded) {
+ this.props.onLinkLoaded();
+ }
}
handleLoadError() {
@@ -61,29 +68,26 @@ export default class PostImageEmbed extends React.Component {
}
render() {
- if (this.state.errored) {
+ if (this.state.errored || !this.state.loaded) {
return null;
}
- if (!this.state.loaded) {
- return (
-
- );
- }
-
return (
-
+