@@ -16,7 +16,7 @@ import FormControl from '@material-ui/core/FormControl'
16
16
import Button from '@material-ui/core/Button'
17
17
import TextField from '@material-ui/core/TextField'
18
18
import Paper from '@material-ui/core/Paper'
19
- import InputAdornment from '@material-ui/core/InputAdornment '
19
+ import IconButton from '@material-ui/core/IconButton '
20
20
21
21
import listStyle from './CollectionList.css'
22
22
import style from './Collection.css'
@@ -26,9 +26,12 @@ export default class CollectionList extends Component {
26
26
constructor ( props ) {
27
27
super ( props )
28
28
this . state = {
29
- filteredUsers : [ ] ,
30
- filtered : false
29
+ checkedTweets : [ ] ,
30
+ findUser : '' ,
31
+ findingUser : false ,
32
+ lastUserLookup : ''
31
33
}
34
+ this . randomTweet = Math . floor ( Math . random ( ) * ( 98 ) )
32
35
}
33
36
34
37
componentDidMount ( ) {
@@ -47,26 +50,42 @@ export default class CollectionList extends Component {
47
50
tick ( ) {
48
51
this . props . getSearch ( this . props . searchId )
49
52
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 ) {
51
56
this . setState ( {
52
- filteredUsers : [ ... Array ( this . props . search . userCount ) . keys ( ) ]
57
+ checkedTweets : foundTweets . map ( ( ) => false )
53
58
} )
54
59
}
55
60
}
56
61
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 !== '' ) {
59
72
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 )
63
77
}
78
+ }
79
+
80
+ setAllTweets ( checked ) {
64
81
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 ) } )
70
89
} )
71
90
}
72
91
@@ -82,8 +101,8 @@ export default class CollectionList extends Component {
82
101
? < a href = { `mailto:${ this . props . search . creator . email } ` } > { this . props . search . creator . email } </ a >
83
102
: 'No contact provided.'
84
103
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 ) => {
87
106
return < TweetEmbed key = { `t${ i } ` } id = { t . id } />
88
107
} )
89
108
}
@@ -103,21 +122,19 @@ export default class CollectionList extends Component {
103
122
< FormGroup row >
104
123
< FormControlLabel
105
124
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 } /> }
107
128
label = { `Select all ${ foundTweets . length } tweets` }
108
129
/>
109
130
</ FormGroup >
110
131
</ 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 >
116
133
< hr />
117
134
{ foundTweets . map ( ( tweetId , i ) => {
118
135
return (
119
136
< 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 >
121
138
< Grid item xs = { 10 } > < TweetEmbed id = { tweetId } /> </ Grid >
122
139
</ Grid >
123
140
)
@@ -128,6 +145,28 @@ export default class CollectionList extends Component {
128
145
}
129
146
}
130
147
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
+
131
170
return (
132
171
< >
133
172
< Grid container spacing = { 3 } className = { listStyle . Header } >
@@ -154,47 +193,35 @@ export default class CollectionList extends Component {
154
193
</ Grid >
155
194
</ Grid >
156
195
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 } ` } >
159
198
< CardContent >
160
199
< div className = { style . CardTitle } >
161
200
< FindMe user = { this . props . user } dest = { `/collection/${ this . props . searchId } ` } />
162
201
</ div >
163
202
{ userTweets }
164
203
</ CardContent >
165
204
</ Card >
166
- < Card raised className = { card . Card } >
167
- < CardContent className = { card . Scroll } >
205
+ < Card raised className = { ` ${ card . Card } ${ style . Card } ` } >
206
+ < CardContent >
168
207
< 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 >
179
214
</ Paper >
180
215
</ 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 }
191
217
</ CardContent >
192
218
</ Card >
193
- < Card raised className = { card . Card } >
194
- < CardContent className = { card . Scroll } >
219
+ < Card raised className = { ` ${ card . Card } ${ style . Card } ` } >
220
+ < CardContent >
195
221
< Typography variant = "h2" className = { style . CardTitle } >
196
222
{ tweetCount } tweets (all users)
197
223
</ Typography >
224
+ < Typography variant = "body2" > Showing 2 random tweets from the collection.</ Typography >
198
225
{ tweets }
199
226
</ CardContent >
200
227
</ Card >
@@ -212,4 +239,6 @@ CollectionList.propTypes = {
212
239
getTweets : PropTypes . func ,
213
240
getUsers : PropTypes . func ,
214
241
getFoundInSearches : PropTypes . func ,
242
+ getTweetsForUser : PropTypes . func ,
243
+ foundUserTweets : PropTypes . bool
215
244
}
0 commit comments