diff options
author | Thibaut Girka <thib@sitedethib.com> | 2018-05-17 16:45:19 +0200 |
---|---|---|
committer | Thibaut Girka <thib@sitedethib.com> | 2018-05-17 18:37:00 +0200 |
commit | dd1d98f9cf405104ef106ee5f376bd09815dac42 (patch) | |
tree | 6d8a797aad14e7640ca2ffaa6395aa8f322895e8 /app/javascript/flavours/glitch/containers/cards_container.js | |
parent | 4bf43e6f3e93643d989a2872763b41505fab2206 (diff) |
[Glitch] Show card modal on public pages
Port 16fee0335f2b10b0ce54f71965d2f2acc0e24942 to glitch-soc
Diffstat (limited to 'app/javascript/flavours/glitch/containers/cards_container.js')
-rw-r--r-- | app/javascript/flavours/glitch/containers/cards_container.js | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/app/javascript/flavours/glitch/containers/cards_container.js b/app/javascript/flavours/glitch/containers/cards_container.js new file mode 100644 index 000000000..1cf980f65 --- /dev/null +++ b/app/javascript/flavours/glitch/containers/cards_container.js @@ -0,0 +1,59 @@ +import React, { Fragment } from 'react'; +import ReactDOM from 'react-dom'; +import PropTypes from 'prop-types'; +import { IntlProvider, addLocaleData } from 'react-intl'; +import { getLocale } from '../locales'; +import Card from 'flavours/glitch/features/status/components/card'; +import ModalRoot from 'flavours/glitch/components/modal_root'; +import MediaModal from 'flavours/glitch/features/ui/components/media_modal'; +import { fromJS } from 'immutable'; + +const { localeData, messages } = getLocale(); +addLocaleData(localeData); + +export default class CardsContainer extends React.PureComponent { + + static propTypes = { + locale: PropTypes.string, + cards: PropTypes.object.isRequired, + }; + + state = { + media: null, + }; + + handleOpenCard = (media) => { + document.body.classList.add('card-standalone__body'); + this.setState({ media }); + } + + handleCloseCard = () => { + document.body.classList.remove('card-standalone__body'); + this.setState({ media: null }); + } + + render () { + const { locale, cards } = this.props; + + return ( + <IntlProvider locale={locale} messages={messages}> + <Fragment> + {[].map.call(cards, container => { + const { card, ...props } = JSON.parse(container.getAttribute('data-props')); + + return ReactDOM.createPortal( + <Card card={fromJS(card)} onOpenMedia={this.handleOpenCard} {...props} />, + container, + ); + })} + <ModalRoot onClose={this.handleCloseCard}> + {this.state.media && ( + <MediaModal media={this.state.media} index={0} onClose={this.handleCloseCard} /> + )} + </ModalRoot> + </Fragment> + </IntlProvider> + ); + } + +} |