Download wp-calypso/client/post-editor/media-modal/gallery/preview-shortcode.jsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.43 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/post-editor/media-modal/gallery/preview-shortcode.jsx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/post-editor/media-modal/gallery/preview-shortcode.jsx
-
curl -L -o preview-shortcode.jsx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/post-editor/media-modal/gallery/preview-shortcode.jsx
1.43 kB
| import clsx from 'clsx'; | |
| import { some } from 'lodash'; | |
| import PropTypes from 'prop-types'; | |
| import { Component } from 'react'; | |
| import GalleryShortcode from 'calypso/components/gallery-shortcode'; | |
| import { generateGalleryShortcode } from 'calypso/lib/media/utils'; | |
| export default class EditorMediaModalGalleryPreviewShortcode extends Component { | |
| static propTypes = { | |
| siteId: PropTypes.number, | |
| settings: PropTypes.object, | |
| }; | |
| state = { | |
| isLoading: true, | |
| shortcode: generateGalleryShortcode( this.props.settings ), | |
| }; | |
| isMounted = false; | |
| static getDerivedStateFromProps( nextProps, prevState ) { | |
| const shortcode = generateGalleryShortcode( nextProps.settings ); | |
| if ( prevState.shortcode === shortcode ) { | |
| return null; | |
| } | |
| return { isLoading: true, shortcode }; | |
| } | |
| componentDidMount() { | |
| this.isMounted = true; | |
| } | |
| componentWillUnmount() { | |
| this.isMounted = false; | |
| } | |
| setLoaded = () => { | |
| if ( ! this.isMounted ) { | |
| return; | |
| } | |
| this.setState( { isLoading: false } ); | |
| }; | |
| render() { | |
| const { siteId, settings } = this.props; | |
| const { isLoading, shortcode } = this.state; | |
| const classes = clsx( 'editor-media-modal-gallery__preview-shortcode', { | |
| 'is-loading': isLoading || some( settings.items, 'transient' ), | |
| } ); | |
| return ( | |
| <div className={ classes }> | |
| <GalleryShortcode siteId={ siteId } onLoad={ this.setLoaded }> | |
| { shortcode } | |
| </GalleryShortcode> | |
| </div> | |
| ); | |
| } | |
| } | |