diff options
author | atp <pruthvip15@gmail.com> | 2017-08-29 20:17:32 +0530 |
---|---|---|
committer | Harrison Healey <harrisonmhealey@gmail.com> | 2017-08-29 10:47:32 -0400 |
commit | 6a312b2ad4c1c50d082165c968fc5111a1a50d28 (patch) | |
tree | 520742bd05253d9091948ed7189366457e8a9ca8 /webapp/components/post_view | |
parent | 257edc9ea3b25328aa44098e963815c3c3d25312 (diff) | |
download | chat-6a312b2ad4c1c50d082165c968fc5111a1a50d28.tar.gz chat-6a312b2ad4c1c50d082165c968fc5111a1a50d28.tar.bz2 chat-6a312b2ad4c1c50d082165c968fc5111a1a50d28.zip |
PLT-3638: Fix re-opening of collapsed preview on refresh (#7301)
In this change, user action for toggling the preview is stored in the browser localstorage. Hence If there us a preview visibility value is present
in the localstorage, that will be given the preference compared to the overall preview setting.
Diffstat (limited to 'webapp/components/post_view')
-rw-r--r-- | webapp/components/post_view/post_body_additional_content.jsx | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/webapp/components/post_view/post_body_additional_content.jsx b/webapp/components/post_view/post_body_additional_content.jsx index bd7574949..ddc73d554 100644 --- a/webapp/components/post_view/post_body_additional_content.jsx +++ b/webapp/components/post_view/post_body_additional_content.jsx @@ -8,6 +8,7 @@ import YoutubeVideo from 'components/youtube_video'; import Constants from 'utils/constants.jsx'; import * as Utils from 'utils/utils.jsx'; +import BrowserStore from 'stores/browser_store.jsx'; import React from 'react'; import PropTypes from 'prop-types'; @@ -47,7 +48,7 @@ export default class PostBodyAdditionalContent extends React.PureComponent { this.handleLinkLoaded = this.handleLinkLoaded.bind(this); this.state = { - embedVisible: props.previewCollapsed.startsWith('false'), + embedVisible: PostBodyAdditionalContent.isEmbedVisible(props), link: Utils.extractFirstLink(props.post.message), linkLoadError: false, linkLoaded: false @@ -62,7 +63,7 @@ export default class PostBodyAdditionalContent extends React.PureComponent { componentWillReceiveProps(nextProps) { if (nextProps.previewCollapsed !== this.props.previewCollapsed || nextProps.post.message !== this.props.post.message) { this.setState({ - embedVisible: nextProps.previewCollapsed.startsWith('false'), + embedVisible: PostBodyAdditionalContent.isEmbedVisible(nextProps), link: Utils.extractFirstLink(nextProps.post.message) }, () => { // check the availability of the image link @@ -72,6 +73,9 @@ export default class PostBodyAdditionalContent extends React.PureComponent { } toggleEmbedVisibility() { + // save the taggle info in the localstorage + BrowserStore.setItem(`isVisible-${this.props.post.id}`, !this.state.embedVisible); + this.setState((prevState) => { return {embedVisible: !prevState.embedVisible}; }); @@ -260,4 +264,9 @@ export default class PostBodyAdditionalContent extends React.PureComponent { return this.props.message; } + + static isEmbedVisible(props) { + // check first in localstorage, if not present, consider previewCollapsed from the parent component + return BrowserStore.getItem(`isVisible-${props.post.id}`, props.previewCollapsed.startsWith('false')); + } } |