PLT-3820 Fix preview flickering on Edge and remove previews from DOM when not expanded (#3967)
Этот коммит содержится в:
коммит произвёл
enahum
родитель
12e48ca7b2
Коммит
958ece011b
@@ -21,14 +21,19 @@ export default class PostBodyAdditionalContent extends React.Component {
|
|||||||
this.generateToggleableEmbed = this.generateToggleableEmbed.bind(this);
|
this.generateToggleableEmbed = this.generateToggleableEmbed.bind(this);
|
||||||
this.generateStaticEmbed = this.generateStaticEmbed.bind(this);
|
this.generateStaticEmbed = this.generateStaticEmbed.bind(this);
|
||||||
this.toggleEmbedVisibility = this.toggleEmbedVisibility.bind(this);
|
this.toggleEmbedVisibility = this.toggleEmbedVisibility.bind(this);
|
||||||
|
this.isLinkToggleable = this.isLinkToggleable.bind(this);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
embedVisible: props.previewCollapsed.startsWith('false')
|
embedVisible: props.previewCollapsed.startsWith('false'),
|
||||||
|
link: Utils.extractFirstLink(props.post.message)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
componentWillReceiveProps(nextProps) {
|
||||||
this.setState({embedVisible: nextProps.previewCollapsed.startsWith('false')});
|
this.setState({
|
||||||
|
embedVisible: nextProps.previewCollapsed.startsWith('false'),
|
||||||
|
link: Utils.extractFirstLink(nextProps.post.message)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldComponentUpdate(nextProps, nextState) {
|
shouldComponentUpdate(nextProps, nextState) {
|
||||||
@@ -73,8 +78,37 @@ export default class PostBodyAdditionalContent extends React.Component {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isLinkImage(link) {
|
||||||
|
for (let i = 0; i < Constants.IMAGE_TYPES.length; i++) {
|
||||||
|
const imageType = Constants.IMAGE_TYPES[i];
|
||||||
|
const suffix = link.substring(link.length - (imageType.length + 1));
|
||||||
|
if (suffix === '.' + imageType || suffix === '=' + imageType) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
isLinkToggleable() {
|
||||||
|
const link = this.state.link;
|
||||||
|
if (!link) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (YoutubeVideo.isYoutubeLink(link)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.isLinkImage(link)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
generateToggleableEmbed() {
|
generateToggleableEmbed() {
|
||||||
const link = Utils.extractFirstLink(this.props.post.message);
|
const link = this.state.link;
|
||||||
if (!link) {
|
if (!link) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -89,17 +123,13 @@ export default class PostBodyAdditionalContent extends React.Component {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < Constants.IMAGE_TYPES.length; i++) {
|
if (this.isLinkImage(link)) {
|
||||||
const imageType = Constants.IMAGE_TYPES[i];
|
return (
|
||||||
const suffix = link.substring(link.length - (imageType.length + 1));
|
<PostImage
|
||||||
if (suffix === '.' + imageType || suffix === '=' + imageType) {
|
channelId={this.props.post.channel_id}
|
||||||
return (
|
link={link}
|
||||||
<PostImage
|
/>
|
||||||
channelId={this.props.post.channel_id}
|
);
|
||||||
link={link}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -143,9 +173,7 @@ export default class PostBodyAdditionalContent extends React.Component {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const toggleableEmbed = this.generateToggleableEmbed();
|
if (this.isLinkToggleable()) {
|
||||||
|
|
||||||
if (toggleableEmbed) {
|
|
||||||
let messageWithToggle = [];
|
let messageWithToggle = [];
|
||||||
|
|
||||||
// if message has only one line and starts with a link place toggle in this only line
|
// if message has only one line and starts with a link place toggle in this only line
|
||||||
@@ -166,15 +194,21 @@ export default class PostBodyAdditionalContent extends React.Component {
|
|||||||
messageWithToggle.unshift(this.props.message);
|
messageWithToggle.unshift(this.props.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let toggleableEmbed;
|
||||||
|
if (this.state.embedVisible) {
|
||||||
|
toggleableEmbed = (
|
||||||
|
<div
|
||||||
|
className='post__embed-container'
|
||||||
|
>
|
||||||
|
{this.generateToggleableEmbed()}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{messageWithToggle}
|
{messageWithToggle}
|
||||||
<div
|
|
||||||
className='post__embed-container'
|
|
||||||
hidden={!this.state.embedVisible}
|
|
||||||
>
|
|
||||||
{toggleableEmbed}
|
{toggleableEmbed}
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user