@@ -2,24 +2,25 @@ import React from 'react';
22import { connect } from 'react-redux' ;
33import ImmutablePropTypes from 'react-immutable-proptypes' ;
44import PropTypes from 'prop-types' ;
5- import { fetchAccount } from '../.. /actions/accounts' ;
5+ import { fetchAccount } from 'mastodon /actions/accounts' ;
66import { expandAccountMediaTimeline } from '../../actions/timelines' ;
7- import LoadingIndicator from '../.. /components/loading_indicator' ;
7+ import LoadingIndicator from 'mastodon /components/loading_indicator' ;
88import Column from '../ui/components/column' ;
9- import ColumnBackButton from '../.. /components/column_back_button' ;
9+ import ColumnBackButton from 'mastodon /components/column_back_button' ;
1010import ImmutablePureComponent from 'react-immutable-pure-component' ;
11- import { getAccountGallery } from '../.. /selectors' ;
11+ import { getAccountGallery } from 'mastodon /selectors' ;
1212import MediaItem from './components/media_item' ;
1313import HeaderContainer from '../account_timeline/containers/header_container' ;
1414import { ScrollContainer } from 'react-router-scroll-4' ;
15- import LoadMore from '../.. /components/load_more' ;
15+ import LoadMore from 'mastodon /components/load_more' ;
1616import MissingIndicator from 'mastodon/components/missing_indicator' ;
17+ import { openModal } from 'mastodon/actions/modal' ;
1718
1819const mapStateToProps = ( state , props ) => ( {
1920 isAccount : ! ! state . getIn ( [ 'accounts' , props . params . accountId ] ) ,
20- medias : getAccountGallery ( state , props . params . accountId ) ,
21+ attachments : getAccountGallery ( state , props . params . accountId ) ,
2122 isLoading : state . getIn ( [ 'timelines' , `account:${ props . params . accountId } :media` , 'isLoading' ] ) ,
22- hasMore : state . getIn ( [ 'timelines' , `account:${ props . params . accountId } :media` , 'hasMore' ] ) ,
23+ hasMore : state . getIn ( [ 'timelines' , `account:${ props . params . accountId } :media` , 'hasMore' ] ) ,
2324} ) ;
2425
2526class LoadMoreMedia extends ImmutablePureComponent {
@@ -51,12 +52,16 @@ class AccountGallery extends ImmutablePureComponent {
5152 static propTypes = {
5253 params : PropTypes . object . isRequired ,
5354 dispatch : PropTypes . func . isRequired ,
54- medias : ImmutablePropTypes . list . isRequired ,
55+ attachments : ImmutablePropTypes . list . isRequired ,
5556 isLoading : PropTypes . bool ,
5657 hasMore : PropTypes . bool ,
5758 isAccount : PropTypes . bool ,
5859 } ;
5960
61+ state = {
62+ width : 323 ,
63+ } ;
64+
6065 componentDidMount ( ) {
6166 this . props . dispatch ( fetchAccount ( this . props . params . accountId ) ) ;
6267 this . props . dispatch ( expandAccountMediaTimeline ( this . props . params . accountId ) ) ;
@@ -71,11 +76,11 @@ class AccountGallery extends ImmutablePureComponent {
7176
7277 handleScrollToBottom = ( ) => {
7378 if ( this . props . hasMore ) {
74- this . handleLoadMore ( this . props . medias . size > 0 ? this . props . medias . last ( ) . getIn ( [ 'status' , 'id' ] ) : undefined ) ;
79+ this . handleLoadMore ( this . props . attachments . size > 0 ? this . props . attachments . last ( ) . getIn ( [ 'status' , 'id' ] ) : undefined ) ;
7580 }
7681 }
7782
78- handleScroll = ( e ) => {
83+ handleScroll = e => {
7984 const { scrollTop, scrollHeight, clientHeight } = e . target ;
8085 const offset = scrollHeight - scrollTop - clientHeight ;
8186
@@ -88,13 +93,31 @@ class AccountGallery extends ImmutablePureComponent {
8893 this . props . dispatch ( expandAccountMediaTimeline ( this . props . params . accountId , { maxId } ) ) ;
8994 } ;
9095
91- handleLoadOlder = ( e ) => {
96+ handleLoadOlder = e => {
9297 e . preventDefault ( ) ;
9398 this . handleScrollToBottom ( ) ;
9499 }
95100
101+ handleOpenMedia = attachment => {
102+ if ( attachment . get ( 'type' ) === 'video' ) {
103+ this . props . dispatch ( openModal ( 'VIDEO' , { media : attachment } ) ) ;
104+ } else {
105+ const media = attachment . getIn ( [ 'status' , 'media_attachments' ] ) ;
106+ const index = media . findIndex ( x => x . get ( 'id' ) === attachment . get ( 'id' ) ) ;
107+
108+ this . props . dispatch ( openModal ( 'MEDIA' , { media, index } ) ) ;
109+ }
110+ }
111+
112+ handleRef = c => {
113+ if ( c ) {
114+ this . setState ( { width : c . offsetWidth } ) ;
115+ }
116+ }
117+
96118 render ( ) {
97- const { medias, shouldUpdateScroll, isLoading, hasMore, isAccount } = this . props ;
119+ const { attachments, shouldUpdateScroll, isLoading, hasMore, isAccount } = this . props ;
120+ const { width } = this . state ;
98121
99122 if ( ! isAccount ) {
100123 return (
@@ -104,17 +127,17 @@ class AccountGallery extends ImmutablePureComponent {
104127 ) ;
105128 }
106129
107- let loadOlder = null ;
108-
109- if ( ! medias && isLoading ) {
130+ if ( ! attachments && isLoading ) {
110131 return (
111132 < Column >
112133 < LoadingIndicator />
113134 </ Column >
114135 ) ;
115136 }
116137
117- if ( hasMore && ! ( isLoading && medias . size === 0 ) ) {
138+ let loadOlder = null ;
139+
140+ if ( hasMore && ! ( isLoading && attachments . size === 0 ) ) {
118141 loadOlder = < LoadMore visible = { ! isLoading } onClick = { this . handleLoadOlder } /> ;
119142 }
120143
@@ -126,23 +149,17 @@ class AccountGallery extends ImmutablePureComponent {
126149 < div className = 'scrollable scrollable--flex' onScroll = { this . handleScroll } >
127150 < HeaderContainer accountId = { this . props . params . accountId } />
128151
129- < div role = 'feed' className = 'account-gallery__container' >
130- { medias . map ( ( media , index ) => media === null ? (
131- < LoadMoreMedia
132- key = { 'more:' + medias . getIn ( index + 1 , 'id' ) }
133- maxId = { index > 0 ? medias . getIn ( index - 1 , 'id' ) : null }
134- onLoadMore = { this . handleLoadMore }
135- />
152+ < div role = 'feed' className = 'account-gallery__container' ref = { this . handleRef } >
153+ { attachments . map ( ( attachment , index ) => attachment === null ? (
154+ < LoadMoreMedia key = { 'more:' + attachments . getIn ( index + 1 , 'id' ) } maxId = { index > 0 ? attachments . getIn ( index - 1 , 'id' ) : null } onLoadMore = { this . handleLoadMore } />
136155 ) : (
137- < MediaItem
138- key = { media . get ( 'id' ) }
139- media = { media }
140- />
156+ < MediaItem key = { attachment . get ( 'id' ) } attachment = { attachment } displayWidth = { width } onOpenMedia = { this . handleOpenMedia } />
141157 ) ) }
158+
142159 { loadOlder }
143160 </ div >
144161
145- { isLoading && medias . size === 0 && (
162+ { isLoading && attachments . size === 0 && (
146163 < div className = 'scrollable__append' >
147164 < LoadingIndicator />
148165 </ div >
0 commit comments