@@ -16,7 +16,7 @@ import FormControl from '@material-ui/core/FormControl'
1616import Button from '@material-ui/core/Button'
1717import TextField from '@material-ui/core/TextField'
1818import Paper from '@material-ui/core/Paper'
19- import InputAdornment from '@material-ui/core/InputAdornment '
19+ import IconButton from '@material-ui/core/IconButton '
2020
2121import listStyle from './CollectionList.css'
2222import style from './Collection.css'
@@ -26,9 +26,12 @@ export default class CollectionList extends Component {
2626 constructor ( props ) {
2727 super ( props )
2828 this . state = {
29- filteredUsers : [ ] ,
30- filtered : false
29+ checkedTweets : [ ] ,
30+ findUser : '' ,
31+ findingUser : false ,
32+ lastUserLookup : ''
3133 }
34+ this . randomTweet = Math . floor ( Math . random ( ) * ( 98 ) )
3235 }
3336
3437 componentDidMount ( ) {
@@ -47,26 +50,42 @@ export default class CollectionList extends Component {
4750 tick ( ) {
4851 this . props . getSearch ( this . props . searchId )
4952 this . props . getFoundInSearches ( )
50- if ( ! this . state . filtered && this . props . search . userCount ) {
53+
54+ const foundTweets = this . props . user . foundInSearches [ this . props . searchId ] || [ ]
55+ if ( this . state . checkedTweets . length === 0 && foundTweets . length > 0 ) {
5156 this . setState ( {
52- filteredUsers : [ ... Array ( this . props . search . userCount ) . keys ( ) ]
57+ checkedTweets : foundTweets . map ( ( ) => false )
5358 } )
5459 }
5560 }
5661
57- filterUser ( term ) {
58- if ( term === '' ) {
62+ handleFindUserInput ( user ) {
63+ const findingUser = user === '' ? false : this . state . findingUser
64+ this . setState ( {
65+ findUser : user ,
66+ findingUser
67+ } )
68+ }
69+
70+ findUser ( ) {
71+ if ( this . state . findUser !== '' ) {
5972 this . setState ( {
60- filteredUsers : [ ...Array ( this . props . search . userCount ) . keys ( ) ] ,
61- filtered : true
62- } )
73+ findingUser : true ,
74+ lastUserLookup : this . state . findUser
75+ } )
76+ this . props . getTweetsForUser ( this . props . searchId , this . state . findUser )
6377 }
78+ }
79+
80+ setAllTweets ( checked ) {
6481 this . setState ( {
65- filteredUsers : this . props . search . users . reduce ( ( acc , u , i ) => {
66- if ( u . screenName . includes ( term ) ) { acc . push ( i ) }
67- return acc
68- } , [ ] ) ,
69- filtered : true
82+ checkedTweets : this . state . checkedTweets . map ( ( ) => checked )
83+ } )
84+ }
85+
86+ toggleOneTweet ( i ) {
87+ this . setState ( {
88+ checkedTweets : this . state . checkedTweets . map ( ( v , tIdx ) => { return ( i === tIdx ? ! v : v ) } )
7089 } )
7190 }
7291
@@ -82,8 +101,8 @@ export default class CollectionList extends Component {
82101 ? < a href = { `mailto:${ this . props . search . creator . email } ` } > { this . props . search . creator . email } </ a >
83102 : 'No contact provided.'
84103 let tweets = 'Loading tweets...'
85- if ( this . props . search . tweets . length > 0 ) {
86- tweets = this . props . search . tweets . slice ( 0 , 2 ) . map ( ( t , i ) => {
104+ if ( this . props . search . tweets . length > 0 ) {
105+ tweets = this . props . search . tweets . slice ( this . randomTweet , this . randomTweet + 2 ) . map ( ( t , i ) => {
87106 return < TweetEmbed key = { `t${ i } ` } id = { t . id } />
88107 } )
89108 }
@@ -103,21 +122,19 @@ export default class CollectionList extends Component {
103122 < FormGroup row >
104123 < FormControlLabel
105124 value = "all"
106- control = { < Checkbox color = "primary" /> }
125+ control = { < Checkbox color = "primary"
126+ onChange = { t => this . setAllTweets ( t . target . checked ) }
127+ checked = { this . state . checkedTweets . indexOf ( false ) === - 1 } /> }
107128 label = { `Select all ${ foundTweets . length } tweets` }
108129 />
109130 </ FormGroup >
110131 </ FormControl >
111- < Grid container spacing = { 0 } >
112- < Grid item xs = { 4 } > < Button className = { style . Options } > specify consent</ Button > </ Grid >
113- < Grid item xs = { 4 } > < Button className = { style . Options } > request removal</ Button > </ Grid >
114- < Grid item xs = { 4 } > < Button className = { style . Options } > talk with us</ Button > </ Grid >
115- </ Grid >
132+ < Button size = "small" > < span className = { style . ButtonText } > Specify/Adjust Consent</ span > </ Button >
116133 < hr />
117134 { foundTweets . map ( ( tweetId , i ) => {
118135 return (
119136 < Grid container spacing = { 0 } key = { `ut${ i } ` } >
120- < Grid item xs = { 2 } > < Checkbox color = "primary" /> </ Grid >
137+ < Grid item xs = { 2 } > < Checkbox color = "primary" checked = { this . state . checkedTweets [ i ] || false } onChange = { ( ) => this . toggleOneTweet ( i ) } /> </ Grid >
121138 < Grid item xs = { 10 } > < TweetEmbed id = { tweetId } /> </ Grid >
122139 </ Grid >
123140 )
@@ -128,6 +145,28 @@ export default class CollectionList extends Component {
128145 }
129146 }
130147
148+ let usersInfo = ( < div >
149+ < Typography variant = "body2" > Showing { this . props . search . users . length } of { this . props . search . userCount } users.</ Typography >
150+ { this . props . search . users . map ( ( u , i ) => {
151+ return < img className = { style . UserImg }
152+ src = { u . avatarUrl }
153+ alt = { u . screenName }
154+ title = { u . screenName } key = { `u${ i } ` } />
155+ } ) }
156+ </ div > )
157+
158+ if ( this . state . findingUser ) {
159+ if ( this . props . foundUserTweets > 0 ) {
160+ usersInfo = (
161+ < Typography variant = "body2" >
162+ Found { this . props . foundUserTweets } tweet{ this . props . foundUserTweets > 1 ? 's' : '' } by
163+ < a href = { `https://twitter.com/${ this . state . lastUserLookup } ` } > @{ this . state . lastUserLookup } </ a > .
164+ </ Typography > )
165+ } else {
166+ usersInfo = < Typography variant = "body2" > Could not find user "{ this . state . lastUserLookup } ".</ Typography >
167+ }
168+ }
169+
131170 return (
132171 < >
133172 < Grid container spacing = { 3 } className = { listStyle . Header } >
@@ -154,47 +193,35 @@ export default class CollectionList extends Component {
154193 </ Grid >
155194 </ Grid >
156195
157- < div className = { card . CardHolder } >
158- < Card raised className = { card . Card } >
196+ < div className = { ` ${ card . CardHolder } ${ style . CardHolder } ` } >
197+ < Card raised className = { ` ${ card . Card } ${ style . Card } ` } >
159198 < CardContent >
160199 < div className = { style . CardTitle } >
161200 < FindMe user = { this . props . user } dest = { `/collection/${ this . props . searchId } ` } />
162201 </ div >
163202 { userTweets }
164203 </ CardContent >
165204 </ Card >
166- < Card raised className = { card . Card } >
167- < CardContent className = { card . Scroll } >
205+ < Card raised className = { ` ${ card . Card } ${ style . Card } ` } >
206+ < CardContent >
168207 < div className = { style . CardTitle } >
169- < Paper id = "box" elevation = { 4 } >
170- < TextField name = "usersearch"
171- onChange = { t => this . filterUser ( t . target . value ) }
172- InputProps = { {
173- startAdornment : (
174- < InputAdornment position = "start" >
175- < ion-icon name = "search" > </ ion-icon >
176- </ InputAdornment >
177- ) ,
178- } } />
208+ < Paper id = "box" elevation = { 4 } className = { style . Search } >
209+ < TextField name = "usersearch" className = { style . SearchInput }
210+ onChange = { ( e ) => this . handleFindUserInput ( e . target . value ) } />
211+ < IconButton color = "primary" onClick = { ( ) => this . findUser ( ) } >
212+ < ion-icon name = "search" > </ ion-icon >
213+ </ IconButton >
179214 </ Paper >
180215 </ div >
181- < div >
182- { this . state . filteredUsers . map ( ( i ) => {
183- if ( this . props . search . users [ i ] ) {
184- return < img
185- src = { this . props . search . users [ i ] . avatarUrl }
186- alt = { this . props . search . users [ i ] . screenName }
187- title = { this . props . search . users [ i ] . screenName } key = { `u${ i } ` } />
188- }
189- } ) }
190- </ div >
216+ { usersInfo }
191217 </ CardContent >
192218 </ Card >
193- < Card raised className = { card . Card } >
194- < CardContent className = { card . Scroll } >
219+ < Card raised className = { ` ${ card . Card } ${ style . Card } ` } >
220+ < CardContent >
195221 < Typography variant = "h2" className = { style . CardTitle } >
196222 { tweetCount } tweets (all users)
197223 </ Typography >
224+ < Typography variant = "body2" > Showing 2 random tweets from the collection.</ Typography >
198225 { tweets }
199226 </ CardContent >
200227 </ Card >
@@ -212,4 +239,6 @@ CollectionList.propTypes = {
212239 getTweets : PropTypes . func ,
213240 getUsers : PropTypes . func ,
214241 getFoundInSearches : PropTypes . func ,
242+ getTweetsForUser : PropTypes . func ,
243+ foundUserTweets : PropTypes . bool
215244}
0 commit comments