From c7e00d4c4e86d98e7030511e24ef4e466634aa71 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Mon, 26 Dec 2022 01:25:11 +0000 Subject: [PATCH] flavors: glitch: add quote indicator component --- .../compose/components/quote_indicator.js | 82 +++++++++++++++++++ .../containers/quote_indicator_container.js | 27 ++++++ 2 files changed, 109 insertions(+) create mode 100644 app/javascript/flavours/glitch/features/compose/components/quote_indicator.js create mode 100644 app/javascript/flavours/glitch/features/compose/containers/quote_indicator_container.js diff --git a/app/javascript/flavours/glitch/features/compose/components/quote_indicator.js b/app/javascript/flavours/glitch/features/compose/components/quote_indicator.js new file mode 100644 index 0000000000..a3eeee1350 --- /dev/null +++ b/app/javascript/flavours/glitch/features/compose/components/quote_indicator.js @@ -0,0 +1,82 @@ +// Package imports. +import PropTypes from 'prop-types'; +import React from 'react'; +import ImmutablePropTypes from 'react-immutable-proptypes'; +import { defineMessages, injectIntl } from 'react-intl'; +import ImmutablePureComponent from 'react-immutable-pure-component'; + +// Components. +import AccountContainer from 'flavours/glitch/containers/account_container'; +import IconButton from 'flavours/glitch/components/icon_button'; +import AttachmentList from 'flavours/glitch/components/attachment_list'; + +// Messages. +const messages = defineMessages({ + cancel: { + defaultMessage: 'Cancel', + id: 'quote_indicator.cancel', + }, +}); + + +export default @injectIntl +class QuoteIndicator extends ImmutablePureComponent { + + static propTypes = { + status: ImmutablePropTypes.map, + intl: PropTypes.object.isRequired, + onCancel: PropTypes.func, + }; + + handleClick = () => { + const { onCancel } = this.props; + if (onCancel) { + onCancel(); + } + } + + // Rendering. + render () { + const { status, intl } = this.props; + + if (!status) { + return null; + } + + const account = status.get('account'); + const content = status.get('content'); + const attachments = status.get('media_attachments'); + + // The result. + return ( +
+
+ + {account && ( + + )} +
+
+ {attachments.size > 0 && ( + + )} +
+ ); + } + +} diff --git a/app/javascript/flavours/glitch/features/compose/containers/quote_indicator_container.js b/app/javascript/flavours/glitch/features/compose/containers/quote_indicator_container.js new file mode 100644 index 0000000000..9421d69dd8 --- /dev/null +++ b/app/javascript/flavours/glitch/features/compose/containers/quote_indicator_container.js @@ -0,0 +1,27 @@ +import { connect } from 'react-redux'; +import { cancelQuoteCompose } from 'flavours/glitch/actions/compose'; +import QuoteIndicator from '../components/quote_indicator'; + +const makeMapStateToProps = () => { + const mapStateToProps = state => { + const statusId = state.getIn(['compose', 'quote_id']); + const editing = false; + + return { + status: state.getIn(['statuses', statusId]), + editing, + }; + }; + + return mapStateToProps; +}; + +const mapDispatchToProps = dispatch => ({ + + onCancel () { + dispatch(cancelQuoteCompose()); + }, + +}); + +export default connect(makeMapStateToProps, mapDispatchToProps)(QuoteIndicator);