diff options
author | Harrison Healey <harrisonmhealey@gmail.com> | 2016-05-05 16:35:03 -0400 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2016-05-05 16:35:03 -0400 |
commit | d2ddf40f56191c1770c3ca93d747a7f1b749f26c (patch) | |
tree | 9cd5d9ac9fc5b9da21fba8df9990c5f927801272 /webapp/components | |
parent | 696ffb4745bec6306f88c5693b8ded89a47f5de7 (diff) | |
download | chat-d2ddf40f56191c1770c3ca93d747a7f1b749f26c.tar.gz chat-d2ddf40f56191c1770c3ca93d747a7f1b749f26c.tar.bz2 chat-d2ddf40f56191c1770c3ca93d747a7f1b749f26c.zip |
PLT-2600/PLT-2770 Added Get Public Link modal and added new API for public file links (#2892)
* Switched public file links to use a GetLinkModal
* Separated getFile and the new getPublicFile api calls
Diffstat (limited to 'webapp/components')
-rw-r--r-- | webapp/components/get_public_link_modal.jsx | 80 | ||||
-rw-r--r-- | webapp/components/needs_team.jsx | 2 | ||||
-rw-r--r-- | webapp/components/view_image.jsx | 28 | ||||
-rw-r--r-- | webapp/components/view_image_popover_bar.jsx | 4 |
4 files changed, 91 insertions, 23 deletions
diff --git a/webapp/components/get_public_link_modal.jsx b/webapp/components/get_public_link_modal.jsx new file mode 100644 index 000000000..7f83651cd --- /dev/null +++ b/webapp/components/get_public_link_modal.jsx @@ -0,0 +1,80 @@ +// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +import React from 'react'; + +import * as AsyncClient from 'utils/async_client.jsx'; +import Constants from 'utils/constants.jsx'; +import ModalStore from 'stores/modal_store.jsx'; +import PureRenderMixin from 'react-addons-pure-render-mixin'; +import * as Utils from 'utils/utils.jsx'; + +import GetLinkModal from './get_link_modal.jsx'; + +export default class GetPublicLinkModal extends React.Component { + constructor(props) { + super(props); + + this.handlePublicLink = this.handlePublicLink.bind(this); + this.handleToggle = this.handleToggle.bind(this); + this.hide = this.hide.bind(this); + + this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this); + + this.state = { + show: false, + channelId: '', + userId: '', + filename: '', + link: '' + }; + } + + componentDidMount() { + ModalStore.addModalListener(Constants.ActionTypes.TOGGLE_GET_PUBLIC_LINK_MODAL, this.handleToggle); + } + + componentDidUpdate(prevProps, prevState) { + if (this.state.show && !prevState.show) { + AsyncClient.getPublicLink(this.state.channelId, this.state.userId, this.state.filename, this.handlePublicLink); + } + } + + componentWillUnmount() { + ModalStore.removeModalListener(Constants.ActionTypes.TOGGLE_GET_PUBLIC_LINK_MODAL, this.handleToggle); + } + + handlePublicLink(link) { + this.setState({ + link + }); + } + + handleToggle(value, args) { + this.setState({ + show: value, + channelId: args.channelId, + userId: args.userId, + filename: args.filename, + link: '' + }); + } + + hide() { + this.setState({ + show: false + }); + } + + render() { + return ( + <GetLinkModal + show={this.state.show} + onHide={this.hide} + title={Utils.localizeMessage('get_public_link_modal.title', 'Copy Public Link')} + helpText={Utils.localizeMessage('get_public_link_modal.help', 'The link below allows anyone to see this file without being registered on this server.')} + link={this.state.link} + /> + ); + } +} diff --git a/webapp/components/needs_team.jsx b/webapp/components/needs_team.jsx index 92c6fc0ce..c2f450f98 100644 --- a/webapp/components/needs_team.jsx +++ b/webapp/components/needs_team.jsx @@ -24,6 +24,7 @@ import Navbar from 'components/navbar.jsx'; // Modals import GetPostLinkModal from 'components/get_post_link_modal.jsx'; +import GetPublicLinkModal from 'components/get_public_link_modal.jsx'; import GetTeamInviteLinkModal from 'components/get_team_invite_link_modal.jsx'; import EditPostModal from 'components/edit_post_modal.jsx'; import DeletePostModal from 'components/delete_post_modal.jsx'; @@ -125,6 +126,7 @@ export default class NeedsTeam extends React.Component { {content} <GetPostLinkModal/> + <GetPublicLinkModal/> <GetTeamInviteLinkModal/> <InviteMemberModal/> <ImportThemeModal/> diff --git a/webapp/components/view_image.jsx b/webapp/components/view_image.jsx index bd4aeaa41..b88df19d4 100644 --- a/webapp/components/view_image.jsx +++ b/webapp/components/view_image.jsx @@ -3,7 +3,7 @@ import $ from 'jquery'; import * as AsyncClient from 'utils/async_client.jsx'; -import Client from 'utils/web_client.jsx'; +import * as GlobalActions from 'action_creators/global_actions.jsx'; import * as Utils from 'utils/utils.jsx'; import AudioVideoPreview from './audio_video_preview.jsx'; import Constants from 'utils/constants.jsx'; @@ -43,7 +43,7 @@ class ViewImageModal extends React.Component { this.onFileStoreChange = this.onFileStoreChange.bind(this); - this.getPublicLink = this.getPublicLink.bind(this); + this.handleGetPublicLink = this.handleGetPublicLink.bind(this); this.onMouseEnterImage = this.onMouseEnterImage.bind(this); this.onMouseLeaveImage = this.onMouseLeaveImage.bind(this); @@ -194,24 +194,10 @@ class ViewImageModal extends React.Component { } } - getPublicLink() { - var data = {}; - data.channel_id = this.props.channelId; - data.user_id = this.props.userId; - data.filename = this.props.filenames[this.state.imgId]; - Client.getPublicLink( - data, - (serverData) => { - if (Utils.isMobile()) { - window.location.href = serverData.public_link; - } else { - window.open(serverData.public_link); - } - }, - () => { - //Do Nothing on error - } - ); + handleGetPublicLink() { + this.props.onModalDismissed(); + + GlobalActions.showGetPublicLinkModal(this.props.channelId, this.props.userId, this.props.filenames[this.state.imgId]); } onMouseEnterImage() { @@ -349,7 +335,7 @@ class ViewImageModal extends React.Component { totalFiles={this.props.filenames.length} filename={name} fileURL={fileUrl} - getPublicLink={this.getPublicLink} + onGetPublicLink={this.handleGetPublicLink} /> </div> </div> diff --git a/webapp/components/view_image_popover_bar.jsx b/webapp/components/view_image_popover_bar.jsx index 55299ef74..5b9b2362f 100644 --- a/webapp/components/view_image_popover_bar.jsx +++ b/webapp/components/view_image_popover_bar.jsx @@ -15,7 +15,7 @@ export default class ViewImagePopoverBar extends React.Component { href='#' className='public-link text' data-title='Public Image' - onClick={this.props.getPublicLink} + onClick={this.props.onGetPublicLink} > <FormattedMessage id='view_image_popover.publicLink' @@ -79,5 +79,5 @@ ViewImagePopoverBar.propTypes = { totalFiles: React.PropTypes.number.isRequired, filename: React.PropTypes.string.isRequired, fileURL: React.PropTypes.string.isRequired, - getPublicLink: React.PropTypes.func.isRequired + onGetPublicLink: React.PropTypes.func.isRequired }; |