2022-01-20 13:28:49 -08:00
import PropTypes from 'prop-types' ;
import React from 'react' ;
import ImmutablePropTypes from 'react-immutable-proptypes' ;
import { injectIntl , FormattedMessage , defineMessages } from 'react-intl' ;
import { connect } from 'react-redux' ;
import IconButton from 'soapbox/components/icon_button' ;
import LoadingIndicator from 'soapbox/components/loading_indicator' ;
import ScrollableList from 'soapbox/components/scrollable_list' ;
2022-01-21 14:40:39 -08:00
import Account from 'soapbox/features/birthdays/account' ;
2022-01-20 13:28:49 -08:00
const messages = defineMessages ( {
close : { id : 'lightbox.close' , defaultMessage : 'Close' } ,
} ) ;
const mapStateToProps = ( state ) => {
const me = state . get ( 'me' ) ;
return {
accountIds : state . getIn ( [ 'user_lists' , 'birthday_reminders' , me ] ) ,
} ;
} ;
export default @ connect ( mapStateToProps )
@ injectIntl
class BirthdaysModal extends React . PureComponent {
static contextTypes = {
router : PropTypes . object ,
} ;
static propTypes = {
onClose : PropTypes . func . isRequired ,
intl : PropTypes . object . isRequired ,
accountIds : ImmutablePropTypes . orderedSet ,
} ;
componentDidMount ( ) {
this . unlistenHistory = this . context . router . history . listen ( ( _ , action ) => {
if ( action === 'PUSH' ) {
this . onClickClose ( null , true ) ;
}
} ) ;
}
componentWillUnmount ( ) {
if ( this . unlistenHistory ) {
this . unlistenHistory ( ) ;
}
}
onClickClose = ( _ , noPop ) => {
this . props . onClose ( 'BIRTHDAYS' , noPop ) ;
} ;
render ( ) {
const { intl , accountIds } = this . props ;
let body ;
if ( ! accountIds ) {
body = < LoadingIndicator / > ;
} else {
const emptyMessage = < FormattedMessage id = 'status.reblogs.empty' defaultMessage = 'No one has reposted this post yet. When someone does, they will show up here.' / > ;
body = (
< ScrollableList
scrollKey = 'reblogs'
emptyMessage = { emptyMessage }
>
{ accountIds . map ( id =>
2022-01-21 14:40:39 -08:00
< Account key = { id } accountId = { id } withNote = { false } / > ,
2022-01-20 13:28:49 -08:00
) }
< / S c r o l l a b l e L i s t >
) ;
}
return (
< div className = 'modal-root__modal reactions-modal' >
< div className = 'compose-modal__header' >
< h3 className = 'compose-modal__header__title' >
< FormattedMessage id = 'column.birthdays' defaultMessage = 'Birthdays' / >
< / h 3 >
< IconButton
className = 'compose-modal__close'
title = { intl . formatMessage ( messages . close ) }
src = { require ( '@tabler/icons/icons/x.svg' ) }
onClick = { this . onClickClose } size = { 20 }
/ >
< / d i v >
{ body }
< / d i v >
) ;
}
}