@@ -6,19 +6,31 @@ import {default as Fade} from 'react-fade'
6
6
import axios from 'axios' ;
7
7
8
8
import JumbotronB from './JumbotronB' ;
9
+ import $ from 'jquery' ;
10
+
9
11
10
12
const fadeDuration = 0.3 ;
11
13
12
14
class BodyComponent extends Component {
13
15
constructor ( props ) {
14
16
super ( props ) ;
15
-
17
+
16
18
this . toggle = this . toggle . bind ( this ) ;
19
+
17
20
this . state = {
18
21
activeTab : '1' ,
19
- rows : [ ]
22
+ rows : [ ] ,
23
+ pageNo : 0
24
+ , loadingState : false
20
25
} ;
21
26
}
27
+
28
+ componentWillUnmount ( ) {
29
+ $ ( window ) . unbind ( ) ;
30
+ this . setState ( {
31
+ rows : [ ]
32
+ } )
33
+ }
22
34
23
35
toggle ( tab ) {
24
36
if ( this . state . activeTab !== tab ) {
@@ -27,21 +39,58 @@ class BodyComponent extends Component {
27
39
} ) ;
28
40
}
29
41
if ( tab == 2 ) {
30
- axios . get ( `http://localhost:3001/api/home/hash/${ tab } ` )
31
- . then ( ( responseData ) => {
32
- setTimeout ( ( ) => {
33
- this . setState ( {
34
- rows :responseData . data
35
- } )
36
- } , 1500 ) ;
37
- } )
38
- . catch ( ( err ) => {
39
- console . log ( err ) ;
42
+ $ ( window ) . scroll ( ( ) => {
43
+ if ( $ ( document ) . height ( ) - $ ( window ) . height ( ) - $ ( window ) . scrollTop ( ) < 250 ) {
44
+ if ( ! this . state . loadingState && this . state . rows . length < 40 ) {
45
+
46
+ axios . post ( `http://localhost:3001/api/home/hash` , {
47
+ 'pageNo' : this . state . pageNo
48
+ } )
49
+ . then ( ( rows ) => {
50
+ console . log ( rows ) ;
51
+ return rows
52
+ } )
53
+ . then ( ( rows ) => {
54
+ this . setState ( {
55
+ pageNo : this . state . pageNo + 1
56
+ , rows : rows . data
57
+ } )
58
+ } )
59
+ . catch ( ( err ) => {
60
+ console . log ( err ) ;
61
+ } ) ;
62
+ this . setState ( {
63
+ loadingState : true
64
+ } ) ;
65
+ }
66
+ } else {
67
+ if ( this . state . loadingState ) {
68
+ this . setState ( {
69
+ loadingState : false
70
+ } ) ;
71
+ }
72
+ }
40
73
} ) ;
41
74
}
42
- }
75
+ }
76
+
43
77
44
78
render ( ) {
79
+ const mapToComponents = ( data ) => {
80
+ return data . map ( ( contact , i ) => {
81
+ return (
82
+ < Col sm = "3" key = { i } style = { { marginBottom :"3%" } } >
83
+ < Card body >
84
+ < CardTitle > { this . state . rows [ i ] . title } </ CardTitle >
85
+ < hr />
86
+ < CardText > { this . state . rows [ i ] . contents } </ CardText >
87
+ < font style = { { color :"blue" , fontSize :"18" } } > #베스트UGC</ font >
88
+ < font style = { { fontSize :"15" } } > { this . state . rows [ i ] . created_at } </ font >
89
+ </ Card >
90
+ </ Col >
91
+ )
92
+ } )
93
+ }
45
94
return (
46
95
< div >
47
96
@@ -97,83 +146,34 @@ class BodyComponent extends Component {
97
146
{
98
147
this . state . rows . length !== 0
99
148
?
100
- < div >
101
- < Fade
102
- duration = { fadeDuration }
149
+ < Fade duration = { fadeDuration } >
150
+ < Row style = { { marginTop :"5%" } } >
151
+ { mapToComponents ( this . state . rows ) }
152
+ </ Row >
153
+ </ Fade >
154
+ :
155
+ < center
156
+ style = { { marginTop :"10%" } }
103
157
>
104
- < Row style = { { marginTop :"5%" } } >
105
- < Col sm = "3" >
106
- < Card body >
107
- < CardTitle > { this . state . rows [ 0 ] . title } </ CardTitle >
108
- < CardText > { this . state . rows [ 0 ] . contents } </ CardText >
109
- < font style = { { color :"blue" , fontSize :"18" } } > #{ this . state . rows [ 0 ] . hash_string } </ font >
110
- < font style = { { fontSize :"15" } } > { this . state . rows [ 0 ] . created_at } </ font >
111
- < Button > 읽어 보기</ Button >
112
- </ Card >
113
- </ Col >
114
- < Col sm = "3" >
115
- < Card body >
116
- < CardTitle > Special Title Treatment</ CardTitle >
117
- < CardText > With supporting text below as a natural lead-in to additional content.</ CardText >
118
- < Button > Go somewhere</ Button >
119
- </ Card >
120
- </ Col >
121
- < Col sm = "3" >
122
- < Card body >
123
- < CardTitle > Special Title Treatment</ CardTitle >
124
- < CardText > With supporting text below as a natural lead-in to additional content.</ CardText >
125
- < Button > Go somewhere</ Button >
126
- </ Card >
127
- </ Col >
128
- < Col sm = "3" >
129
- < Card body >
130
- < CardTitle > Special Title Treatment</ CardTitle >
131
- < CardText > With supporting text below as a natural lead-in to additional content.</ CardText >
132
- < Button > Go somewhere</ Button >
133
- </ Card >
134
- </ Col >
135
- </ Row >
136
- < Row style = { { marginTop :"5%" } } >
137
- < Col sm = "3" >
138
- < Card body >
139
- < CardTitle > Special Title Treatment</ CardTitle >
140
- < CardText > With supporting text below as a natural lead-in to additional content.</ CardText >
141
- < Button > Go somewhere</ Button >
142
- </ Card >
143
- </ Col >
144
- < Col sm = "3" >
145
- < Card body >
146
- < CardTitle > Special Title Treatment</ CardTitle >
147
- < CardText > With supporting text below as a natural lead-in to additional content.</ CardText >
148
- < Button > Go somewhere</ Button >
149
- </ Card >
150
- </ Col >
151
- < Col sm = "3" >
152
- < Card body >
153
- < CardTitle > Special Title Treatment</ CardTitle >
154
- < CardText > With supporting text below as a natural lead-in to additional content.</ CardText >
155
- < Button > Go somewhere</ Button >
156
- </ Card >
157
- </ Col >
158
- < Col sm = "3" >
159
- < Card body >
160
- < CardTitle > Special Title Treatment</ CardTitle >
161
- < CardText > With supporting text below as a natural lead-in to additional content.</ CardText >
162
- < Button > Go somewhere</ Button >
163
- </ Card >
164
- </ Col >
165
- </ Row >
166
- </ Fade >
167
- </ div >
168
- :
169
- < center
170
- style = { { marginTop :"10%" } }
171
- >
172
- < HashLoader
173
- color = { '#7F7F7F' }
174
- loading = { true }
175
- />
176
- </ center >
158
+ < HashLoader
159
+ color = { '#7F7F7F' }
160
+ loading = { true }
161
+ />
162
+ </ center >
163
+ }
164
+ {
165
+ this . state . rows . length < 37
166
+ ?
167
+ < center
168
+ style = { { marginTop :"10%" } }
169
+ >
170
+ < HashLoader
171
+ color = { '#7F7F7F' }
172
+ loading = { true }
173
+ />
174
+ </ center >
175
+ :
176
+ ''
177
177
}
178
178
</ TabPane >
179
179
< TabPane tabId = "3" >
0 commit comments