1
1
import MainLayout from "@/components/templates/layout/MainLayout" ;
2
+ import { useAuth } from "@/contexts/AuthContext" ;
3
+ import { IUser } from "@/interfaces" ;
4
+ import { setArticleData } from "@/store/features/shared_data" ;
5
+ import { useAppDispatch } from "@/store/hooks" ;
6
+ import { getRequest , postRequest } from "@/utils/axios" ;
2
7
import { useRouter } from "next/navigation" ;
8
+ import { useEffect , useState } from "react" ;
3
9
10
+ interface Article {
11
+ cur_step : number ;
12
+ id : number ;
13
+ image : string ;
14
+ title : string ;
15
+ content : string ;
16
+ category : string ;
17
+ price : number ;
18
+ nonfree : number ;
19
+ created_by : IUser ;
20
+ created_at : string ;
21
+ has_bought : boolean ;
22
+ }
4
23
5
24
const TopPage = ( ) => {
6
25
const router = useRouter ( ) ;
@@ -18,6 +37,13 @@ const TopPage = () => {
18
37
"中部・近畿" ,
19
38
"中国・四国・九州"
20
39
] ;
40
+ const [ popular_articles , setPopularArticles ] = useState < Article [ ] | null > ( null )
41
+ const [ follower_articles , setFollowerArticles ] = useState < Article [ ] | null > ( null )
42
+ const [ categoryA_articles , setCategoryArticles ] = useState < Article [ ] | null > ( null )
43
+ const [ category , setCategory ] = useState ( '' )
44
+ const { user , isAuthenticated } = useAuth ( )
45
+ const dispatch = useAppDispatch ( ) ;
46
+
21
47
const articles = [
22
48
{
23
49
title : "記事タイトル記事タイトル記事タイトル" ,
@@ -43,9 +69,25 @@ const TopPage = () => {
43
69
price : "¥1,980" ,
44
70
image : "/images/image3.jpeg" , // Replace with actual image URLs
45
71
} ,
46
- ] ;
72
+ ] ;
73
+ const goToArticle = ( id :number ) => {
74
+ router . push ( `/members/articles/${ id } ` )
75
+ }
76
+ useEffect ( ( ) => {
77
+ ( async ( ) => {
78
+ const formData = new FormData ( ) ;
79
+ formData . append ( 'category' , category )
80
+ const res = await postRequest ( '/article/popular' , formData )
81
+ setPopularArticles ( res . data )
82
+ const res1 = await postRequest ( '/article/follow_article' , formData )
83
+ setFollowerArticles ( res1 . data )
84
+ console . log ( "****voldin" , res1 . data )
85
+ const res2 = await getRequest ( '/article/category_article' )
86
+ setCategoryArticles ( res2 . data )
87
+ } ) ( )
88
+ } , [ ] )
47
89
const popular_clicked = ( ) => {
48
- router . push ( '/nologin /popular' )
90
+ router . push ( '/common /popular' )
49
91
}
50
92
return (
51
93
< MainLayout >
@@ -59,6 +101,7 @@ const TopPage = () => {
59
101
< button
60
102
key = { index }
61
103
className = "px-6 py-3 border border-gray-300 rounded-full text-sm text-gray-700 hover:bg-gray-100"
104
+ onClick = { ( ) => setCategory ( category ) }
62
105
>
63
106
{ category }
64
107
</ button >
@@ -76,97 +119,102 @@ const TopPage = () => {
76
119
77
120
{ /* Article Grid */ }
78
121
< div className = "grid grid-cols-4 gap-6" >
79
- { articles . map ( ( article , index ) => (
122
+ { popular_articles && popular_articles . map ( ( article , index ) => (
80
123
< div
81
124
key = { index }
82
- className = "p-4"
125
+ className = "p-4 cursor-pointer"
126
+ onClick = { ( ) => goToArticle ( article . id ) }
83
127
>
84
128
{ /* Article Image */ }
85
129
< img
86
- src = { article . image }
87
- alt = { article . title }
130
+ src = { process . env . NEXT_PUBLIC_BACKEND_URL + article . image }
88
131
className = "w-full h-[150px] object-cover rounded-md mb-4"
89
132
/>
90
133
91
134
{ /* Article Details */ }
92
- < h3 className = "text-sm font-bold text-gray-800 mb-2" >
135
+ < h3 className = "text-sm font-bold text-gray-800 mb-2 overflow-hidden whitespace-nowrap text-ellipsis " >
93
136
{ article . title }
94
137
</ h3 >
95
138
< div className = "flex items-center mb-2" >
96
139
< div className = "w-6 h-6 bg-gray-300 rounded-full mr-2" > </ div >
97
- < span className = "text-sm text-gray-500" > { article . creator } </ span >
140
+ < span className = "text-sm text-gray-500" > { article . created_by . user_info . name } </ span >
98
141
</ div >
99
- < p className = "text-sm font-bold text-gray-800 float-right" > { article . price } </ p >
142
+ < p className = "text-sm font-bold text-gray-800 float-right" > ¥ { article . price } </ p >
100
143
</ div >
101
144
) ) }
102
145
</ div >
103
146
</ section >
104
- < section className = "max-w-[1440px] mx-auto px-[94px] py-8" >
105
- { /* Header */ }
106
- < div className = "flex justify-between items-center mb-6" >
107
- < h2 className = "text-xl font-bold" > フォロー中のクリエイターの記事</ h2 >
108
- < a href = "#" className = "text-sm text-gray-500 hover:underline" >
109
- もっと見る
110
- </ a >
111
- </ div >
147
+ {
148
+ isAuthenticated && < >
149
+ < section className = "max-w-[1440px] mx-auto px-[94px] py-8" >
150
+ { /* Header */ }
151
+ < div className = "flex justify-between items-center mb-6" >
152
+ < h2 className = "text-xl font-bold" > フォロー中のクリエイターの記事</ h2 >
153
+ < a href = "#" className = "text-sm text-gray-500 hover:underline" >
154
+ もっと見る
155
+ </ a >
156
+ </ div >
112
157
113
- { /* Article Grid */ }
114
- < div className = "grid grid-cols-4 gap-6" >
115
- { articles . map ( ( article , index ) => (
116
- < div
117
- key = { index }
118
- className = "p-4"
119
- >
120
- { /* Article Image */ }
121
- < img
122
- src = { article . image }
123
- alt = { article . title }
124
- className = "w-full h-[150px] object-cover rounded-md mb-4"
125
- />
158
+ { /* Article Grid */ }
159
+ < div className = "grid grid-cols-4 gap-6" >
160
+ { follower_articles && follower_articles . map ( ( article , index ) => (
161
+ < div
162
+ key = { index }
163
+ className = "p-4 cursor-pointer"
164
+ onClick = { ( ) => goToArticle ( article . id ) }
165
+ >
166
+ { /* Article Image */ }
167
+ < img
168
+ src = { process . env . NEXT_PUBLIC_BACKEND_URL + article . image }
169
+ alt = { article . title }
170
+ className = "w-full h-[150px] object-cover rounded-md mb-4"
171
+ />
126
172
127
- { /* Article Details */ }
128
- < h3 className = "text-sm font-bold text-gray-800 mb-2" >
129
- { article . title }
130
- </ h3 >
131
- < div className = "flex items-center mb-2" >
132
- < div className = "w-6 h-6 bg-gray-300 rounded-full mr-2" > </ div >
133
- < span className = "text-sm text-gray-500" > { article . creator } </ span >
173
+ { /* Article Details */ }
174
+ < h3 className = "text-sm font-bold text-gray-800 mb-2 overflow-hidden whitespace-nowrap text-ellipsis" >
175
+ { article . title }
176
+ </ h3 >
177
+ < div className = "flex items-center mb-2" >
178
+ < div className = "w-6 h-6 bg-gray-300 rounded-full mr-2" > </ div >
179
+ < span className = "text-sm text-gray-500" > { article . created_by . user_info . name } </ span >
180
+ </ div >
181
+ < p className = "text-sm font-bold text-gray-800 float-right" > { article . price } </ p >
134
182
</ div >
135
- < p className = "text-sm font-bold text-gray-800 float-right" > { article . price } </ p >
183
+ ) ) }
136
184
</ div >
137
- ) ) }
138
- </ div >
139
- </ section >
185
+ </ section >
186
+ </ >
187
+ }
188
+
140
189
< section className = "max-w-[1440px] mx-auto px-[94px] py-8" >
141
190
{ /* Header */ }
142
191
< div className = "flex justify-between items-center mb-6" >
143
- < h2 className = "text-xl font-bold" > カテゴリーAの記事 </ h2 >
192
+ < h2 className = "text-xl font-bold" > ゲームの記事 </ h2 >
144
193
< a href = "#" className = "text-sm text-gray-500 hover:underline" >
145
194
もっと見る
146
195
</ a >
147
196
</ div >
148
197
149
198
{ /* Article Grid */ }
150
199
< div className = "grid grid-cols-4 gap-6" >
151
- { articles . map ( ( article , index ) => (
200
+ { categoryA_articles && categoryA_articles . map ( ( article , index ) => (
152
201
< div
153
202
key = { index }
154
203
className = "p-4"
155
204
>
156
205
{ /* Article Image */ }
157
206
< img
158
- src = { article . image }
159
- alt = { article . title }
160
- className = "w-full h-[150px] object-cover rounded-md mb-4"
207
+ src = { process . env . NEXT_PUBLIC_BACKEND_URL + article . image }
208
+ className = "w-full h-[150px] object-cover rounded-md mb-4"
161
209
/>
162
210
163
211
{ /* Article Details */ }
164
- < h3 className = "text-sm font-bold text-gray-800 mb-2" >
212
+ < h3 className = "text-sm font-bold text-gray-800 mb-2 overflow-hidden whitespace-nowrap text-ellipsis " >
165
213
{ article . title }
166
214
</ h3 >
167
215
< div className = "flex items-center mb-2" >
168
216
< div className = "w-6 h-6 bg-gray-300 rounded-full mr-2" > </ div >
169
- < span className = "text-sm text-gray-500" > { article . creator } </ span >
217
+ < span className = "text-sm text-gray-500" > { article . created_by . user_info . name } </ span >
170
218
</ div >
171
219
< p className = "text-sm font-bold text-gray-800 float-right" > { article . price } </ p >
172
220
</ div >
0 commit comments