1
+ /* eslint-disable react/prop-types */
1
2
import { connect } from 'dva' ;
2
3
import React , { PureComponent } from 'react' ;
3
4
import ReactWordcloud from 'react-wordcloud' ;
4
- import { Button , Divider , Form , Grid , Header , Icon , Image , Input , Menu , Popup , Radio , Transition } from 'semantic-ui-react' ;
5
+ import {
6
+ Button ,
7
+ Divider ,
8
+ Form ,
9
+ Grid ,
10
+ Header ,
11
+ Icon ,
12
+ Image ,
13
+ Input ,
14
+ Menu ,
15
+ Popup ,
16
+ Radio ,
17
+ Transition ,
18
+ } from 'semantic-ui-react' ;
5
19
import genColor from '../../utils/genColor' ;
6
20
import Calendar from '../Calendar' ;
7
21
import './HomePage.css' ;
8
22
9
23
@connect ( ( { artwork } ) => ( {
10
- artwork
24
+ artwork,
11
25
} ) )
12
- export default class HomePage extends PureComponent {
13
-
14
- domRef
26
+ class HomePage extends PureComponent {
27
+ domRef ;
15
28
constructor ( props ) {
16
- super ( props )
17
- this . fpMoveTo = props . fpMoveTo
18
- this . domRef = React . createRef ( )
29
+ super ( props ) ;
30
+ this . fpMoveTo = props . fpMoveTo ;
31
+ this . domRef = React . createRef ( ) ;
19
32
this . engineCollection = [
20
33
{
21
34
key : 'google' ,
22
35
name : 'Google' ,
23
36
baseString : 'https://www.google.com/search?q=' ,
24
- iconName : 'google'
37
+ iconName : 'google' ,
25
38
} ,
26
39
{
27
40
key : 'bing' ,
28
41
name : 'Bing' ,
29
42
baseString : 'https://www.bing.com/search?q=' ,
30
- iconName : 'microsoft'
43
+ iconName : 'microsoft' ,
31
44
} ,
32
45
{
33
46
key : 'duckduckgo' ,
34
47
name : 'DuckDuckGo' ,
35
48
baseString : 'https://duckduckgo.com/?q=' ,
36
- iconName : 'privacy'
49
+ iconName : 'privacy' ,
37
50
} ,
38
51
{
39
52
key : 'baidu' ,
40
53
name : 'Baidu' ,
41
54
baseString : 'https://www.baidu.com/s?wd=' ,
42
- iconName : 'dont'
43
- }
44
- ]
55
+ iconName : 'dont' ,
56
+ } ,
57
+ ] ;
45
58
this . state = {
46
59
engine : this . engineCollection [ 0 ] ,
47
60
query : null ,
48
61
isLogoVisible : true ,
49
62
searchInNewWindow : false ,
50
63
isArrowVisible : false ,
51
64
artwork : { } ,
52
-
53
- }
54
- this . handleMenuItemClick = this . handleMenuItemClick . bind ( this )
55
- this . handleFormSubmit = this . handleFormSubmit . bind ( this )
56
- this . handleInputChange = this . handleInputChange . bind ( this )
57
- this . handleRadioClick = this . handleRadioClick . bind ( this )
58
-
65
+ } ;
66
+ this . handleMenuItemClick = this . handleMenuItemClick . bind ( this ) ;
67
+ this . handleFormSubmit = this . handleFormSubmit . bind ( this ) ;
68
+ this . handleInputChange = this . handleInputChange . bind ( this ) ;
69
+ this . handleRadioClick = this . handleRadioClick . bind ( this ) ;
59
70
}
60
71
61
72
componentDidMount ( ) {
62
- this . props . dispatch ( { type : 'artwork/getData' } )
73
+ this . props . dispatch ( { type : 'artwork/getData' } ) ;
63
74
}
64
75
65
76
move = ( ) => {
66
77
// console.log("123")
67
78
if ( ! this . state . isArrowVisible ) {
68
- this . setState ( { isArrowVisible : true } , this . arrowDisappear )
79
+ this . setState ( { isArrowVisible : true } , this . arrowDisappear ) ;
69
80
}
70
- }
81
+ } ;
71
82
72
- timer
83
+ timer ;
73
84
arrowDisappear = ( ) => {
74
85
if ( this . timer ) {
75
- clearTimeout ( this . timer )
86
+ clearTimeout ( this . timer ) ;
76
87
}
77
88
this . timer = setTimeout ( ( ) => {
78
- this . setState ( { isArrowVisible : false } )
79
- this . timer = null
80
- } , 2000 )
81
- }
89
+ this . setState ( { isArrowVisible : false } ) ;
90
+ this . timer = null ;
91
+ } , 2000 ) ;
92
+ } ;
82
93
83
94
handleMenuItemClick ( e , d ) {
84
- this . setState ( { isLogoVisible : false } )
85
- const engineName = d . content . toLowerCase ( )
86
- const engineObject = this . engineCollection . find (
87
- ( i ) => i . key == engineName
88
- )
89
- console . log ( engineObject )
95
+ this . setState ( { isLogoVisible : false } ) ;
96
+ const engineName = d . content . toLowerCase ( ) ;
97
+ const engineObject = this . engineCollection . find ( i => i . key == engineName ) ;
98
+ console . log ( engineObject ) ;
90
99
this . setState ( {
91
- engine : engineObject
92
- } )
100
+ engine : engineObject ,
101
+ } ) ;
93
102
setTimeout ( ( ) => {
94
103
this . setState ( {
95
- isLogoVisible : true
96
- } )
97
- console . log ( this . state . isLogoVisible )
98
- console . log ( engineObject )
99
- } , 100 )
104
+ isLogoVisible : true ,
105
+ } ) ;
106
+ console . log ( this . state . isLogoVisible ) ;
107
+ console . log ( engineObject ) ;
108
+ } , 100 ) ;
100
109
}
101
110
111
+ handleColorShuffle = ( ) => {
112
+ localStorage [ 'colorOffset' ] = localStorage [ 'colorOffset' ] + 1 ;
113
+ } ;
114
+
102
115
handleFormSubmit ( e ) {
103
- const s = this . state
104
- const address = s . engine . baseString + s . query
116
+ const s = this . state ;
117
+ const address = s . engine . baseString + s . query ;
105
118
if ( s . query == null ) {
106
119
//todo: made this look nicer (and more politer lol)
107
- alert ( 'FILL THE DAMNED SEARCH BOX FIRST!' )
108
- return 0
120
+ alert ( 'FILL THE DAMNED SEARCH BOX FIRST!' ) ;
121
+ return 0 ;
109
122
}
110
123
if ( s . searchInNewWindow ) {
111
- window . open ( address , "_blank" )
112
- }
113
- else {
114
- e . currentTarget . reset ( )
115
- window . open ( address , "_self" )
124
+ window . open ( address , '_blank' ) ;
125
+ } else {
126
+ e . currentTarget . reset ( ) ;
127
+ window . open ( address , '_self' ) ;
116
128
}
117
129
}
118
130
119
131
handleInputChange ( e ) {
120
- const queryString = e . target . value
132
+ const queryString = e . target . value ;
121
133
this . setState ( {
122
- query : queryString
123
- } )
134
+ query : queryString ,
135
+ } ) ;
124
136
}
125
137
126
138
handleRadioClick ( ) {
127
- this . setState ( ( prevState ) => ( {
128
- searchInNewWindow : ! prevState . searchInNewWindow
129
- } ) )
130
- console . log ( " state:" + this . state . searchInNewWindow )
139
+ this . setState ( prevState => ( {
140
+ searchInNewWindow : ! prevState . searchInNewWindow ,
141
+ } ) ) ;
142
+ console . log ( ' state:' + this . state . searchInNewWindow ) ;
131
143
}
132
144
133
145
render ( ) {
134
- const s = this . state
135
- console . log ( this . props . artwork )
136
- console . log ( s . engine . key )
146
+ const s = this . state ;
147
+ console . log ( this . props . artwork ) ;
148
+ console . log ( s . engine . key ) ;
137
149
return (
138
150
< div onMouseMove = { this . move } className = "section" >
139
151
< div className = "home page wrapper" >
@@ -145,20 +157,26 @@ export default class HomePage extends PureComponent {
145
157
< Grid centered fluid >
146
158
< Grid . Row >
147
159
< Grid . Column textAlign = "center" >
148
- < Transition visible = { s . isLogoVisible } duration = { 200 } animation = "pulse" >
160
+ < Transition
161
+ visible = { s . isLogoVisible }
162
+ duration = { 200 }
163
+ animation = "pulse"
164
+ >
149
165
< Image >
150
- < Icon name = { s . engine . iconName } size = "massive" color = { genColor ( ) } />
166
+ < Icon
167
+ name = { s . engine . iconName }
168
+ size = "massive"
169
+ color = { genColor ( ) }
170
+ />
151
171
</ Image >
152
172
</ Transition >
153
173
</ Grid . Column >
154
174
</ Grid . Row >
155
175
< Grid . Row >
156
176
< Grid . Column width = { 8 } >
157
- < Form
158
- onSubmit = { this . handleFormSubmit }
159
- >
177
+ < Form onSubmit = { this . handleFormSubmit } >
160
178
< Input
161
- placeholder = ' All engines, one Pano.'
179
+ placeholder = " All engines, one Pano."
162
180
type = "input"
163
181
action = "Search"
164
182
fluid
@@ -180,43 +198,55 @@ export default class HomePage extends PureComponent {
180
198
radioClick = { this . handleRadioClick }
181
199
engine = { s . engine . key }
182
200
newWindow = { s . searchInNewWindow }
201
+ shuffleColor = { this . handleColorshuffle }
183
202
/>
184
203
</ div >
185
204
</ div >
186
- < Transition
187
- visible = { s . isArrowVisible }
188
- duration = { 100 }
189
- >
190
- < div style = { { position : 'fixed' , bottom : 25 , width : "50%" , left : "25%" , textAlign : "center" } } >
191
- < Button circular icon = 'angle double down' onClick = {
192
- ( ) => {
193
- this . setState ( { isArrowVisible : false } , ( ) => this . fpMoveTo ( 2 ) )
205
+ < Transition visible = { s . isArrowVisible } duration = { 100 } >
206
+ < div
207
+ style = { {
208
+ position : 'fixed' ,
209
+ bottom : 25 ,
210
+ width : '50%' ,
211
+ left : '25%' ,
212
+ textAlign : 'center' ,
213
+ } }
214
+ >
215
+ < Button
216
+ circular
217
+ icon = "angle double down"
218
+ onClick = { ( ) => {
219
+ this . setState ( { isArrowVisible : false } , ( ) =>
220
+ this . fpMoveTo ( 2 ) ,
221
+ ) ;
194
222
} }
195
223
/>
196
224
</ div >
197
225
</ Transition >
198
226
</ div >
199
- )
227
+ ) ;
200
228
}
201
229
}
202
230
203
231
function Footer ( props ) {
204
- const p = props
232
+ const p = props ;
205
233
return (
206
234
< >
207
- < Popup className = "footer-icon"
208
- trigger = { < Button circular color = 'green' icon = 'wechat' /> }
235
+ < Popup
236
+ className = "footer-icon"
237
+ trigger = { < Button circular color = "green" icon = "wechat" /> }
209
238
>
210
- < Image src = ' https://s3.ax1x.com/2020/11/22/D3WBZQ.jpg' />
239
+ < Image src = " https://s3.ax1x.com/2020/11/22/D3WBZQ.jpg" />
211
240
</ Popup >
212
- < Popup className = "footer-icon"
213
- trigger = { < Button circular color = 'twitter' icon = 'twitter' /> }
241
+ < Popup
242
+ className = "footer-icon"
243
+ trigger = { < Button circular color = "twitter" icon = "twitter" /> }
214
244
>
215
245
< Header > Pending.</ Header >
216
246
</ Popup >
217
247
< span className = "custom-divider" > |</ span >
218
248
< Popup
219
- trigger = { < Button circular icon = ' setting' className = "footer-icon" /> }
249
+ trigger = { < Button circular icon = " setting" className = "footer-icon" /> }
220
250
position = "top left"
221
251
flowing
222
252
hoverable
@@ -246,34 +276,40 @@ function Footer(props) {
246
276
< Divider />
247
277
< Menu . Item fitted >
248
278
< Radio
249
- label = ' Search in new tab'
279
+ label = " Search in new tab"
250
280
slider
251
281
checked = { p . newWindow }
252
282
onClick = { p . radioClick }
253
283
/>
254
284
</ Menu . Item >
285
+ < Menu . Item fitted >
286
+ < Button label = "shuffle accent color" onClick = { p . shuffleColor } />
287
+ </ Menu . Item >
255
288
</ Menu >
256
289
</ Popup >
257
290
</ >
258
- )
291
+ ) ;
259
292
}
260
293
261
294
class Wordcloud extends PureComponent {
262
295
render ( ) {
263
- return ( < ReactWordcloud
264
- words = { this . props . data }
265
- size = { [ 100 , 800 ] }
266
- options = { {
267
- fontSizes : [ 20 , 30 ] ,
268
- rotations : 90 ,
269
- rotationAngles : [ - 90 , 0 ]
270
- } }
271
- callbacks = { {
272
- onWordMouseOver : null ,
273
- getWordTooltip : word => '' ,
274
- getWordColor : word => '#999' ,
275
- }
276
- }
277
- /> )
296
+ return (
297
+ < ReactWordcloud
298
+ words = { this . props . data }
299
+ size = { [ 100 , 800 ] }
300
+ options = { {
301
+ fontSizes : [ 20 , 30 ] ,
302
+ rotations : 90 ,
303
+ rotationAngles : [ - 90 , 0 ] ,
304
+ } }
305
+ callbacks = { {
306
+ onWordMouseOver : null ,
307
+ getWordTooltip : word => '' ,
308
+ getWordColor : word => '#999' ,
309
+ } }
310
+ />
311
+ ) ;
278
312
}
279
- }
313
+ }
314
+
315
+ export default HomePage ;
0 commit comments