Added unique photos and videos tab to profile

• Added:
- unique photos and videos tab to profile
- mediaType/media_type query string in api/statuses_controller

• Updated:
- /media to redirect to /photos
- AccountGallery, selector to accept mediaType and update on change in componentWillReceiveProps

• Removed:
- Generic "media" tab

• Todo:
- Create index for MediaAttachment.type
This commit is contained in:
mgabdev
2020-06-08 19:38:36 -04:00
parent 1f78bc6879
commit a5e99dd7c3
6 changed files with 70 additions and 25 deletions

View File

@@ -12,12 +12,12 @@ const messages = defineMessages({
none: { id: 'account_gallery.none', defaultMessage: 'No media to show.' },
})
const mapStateToProps = (state, { account }) => {
const mapStateToProps = (state, { account, mediaType }) => {
const accountId = !!account ? account.get('id') : -1
return {
accountId,
attachments: getAccountGallery(state, accountId),
attachments: getAccountGallery(state, accountId, mediaType),
isLoading: state.getIn(['timelines', `account:${accountId}:media`, 'isLoading']),
hasMore: state.getIn(['timelines', `account:${accountId}:media`, 'hasMore']),
}
@@ -36,19 +36,32 @@ class AccountGallery extends ImmutablePureComponent {
isLoading: PropTypes.bool,
hasMore: PropTypes.bool,
intl: PropTypes.object.isRequired,
mediaType: PropTypes.oneOf([
'photo',
'video',
]),
}
static defaultProps = {
mediaType: 'both'
}
componentDidMount() {
const { accountId } = this.props
const { accountId, mediaType } = this.props
if (accountId && accountId !== -1) {
this.props.dispatch(expandAccountMediaTimeline(accountId))
this.props.dispatch(expandAccountMediaTimeline(accountId, { mediaType }))
}
}
componentWillReceiveProps(nextProps) {
if (nextProps.accountId && nextProps.accountId !== this.props.accountId) {
this.props.dispatch(expandAccountMediaTimeline(nextProps.accountId))
if (
(nextProps.accountId && nextProps.accountId !== this.props.accountId) ||
(nextProps.accountId && nextProps.mediaType !== this.props.mediaType)
) {
this.props.dispatch(expandAccountMediaTimeline(nextProps.accountId, {
mediaType: nextProps.mediaType,
}))
}
}
@@ -58,7 +71,7 @@ class AccountGallery extends ImmutablePureComponent {
}
}
handleScroll = e => {
handleScroll = (e) => {
const { scrollTop, scrollHeight, clientHeight } = e.target
const offset = scrollHeight - scrollTop - clientHeight
@@ -67,13 +80,16 @@ class AccountGallery extends ImmutablePureComponent {
}
}
handleLoadMore = maxId => {
handleLoadMore = (maxId) => {
if (this.props.accountId && this.props.accountId !== -1) {
this.props.dispatch(expandAccountMediaTimeline(this.props.accountId, { maxId }))
this.props.dispatch(expandAccountMediaTimeline(this.props.accountId, {
maxId,
mediaType: this.props.mediaType,
}))
}
}
handleLoadOlder = e => {
handleLoadOlder = (e) => {
e.preventDefault()
this.handleScrollToBottom()
}