File tree 3 files changed +27
-11
lines changed
components/pages/main/Feed
3 files changed +27
-11
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,8 @@ export default function BoardsList({
31
31
< FeedBoardCard
32
32
userId = { board . userName }
33
33
content = { board . title }
34
- imgs = { [ board . image [ 0 ] , board . image [ 1 ] , board . image [ 2 ] ] }
34
+ // TODO: 이미지 연결
35
+ imgs = { [ ] }
35
36
setShowModal = { setShowModal }
36
37
comments = { board . comments }
37
38
/>
Original file line number Diff line number Diff line change @@ -18,25 +18,34 @@ export default function Upload() {
18
18
setPostText ( event . target . value ) ;
19
19
} ;
20
20
21
- const onUploadBoard = async ( data : string ) => {
21
+ // 데이터 전송을 위한 함수
22
+ const onUploadBoard = async ( ) => {
23
+ if ( ! postText || isOverMaxChar ) {
24
+ return ; // Don't proceed if postText is empty or over the character limit.
25
+ }
26
+
22
27
setIsLoading ( true ) ;
23
28
try {
24
29
const response = await postBoard ( {
25
30
title : 'title' ,
26
- content : data ,
31
+ content : postText ,
27
32
} ) ;
33
+ console . log ( response ) ;
34
+ if ( response . ok ) {
35
+ Toast . success ( '게시물이 성공적으로 업로드되었습니다.' ) ;
36
+ setPostText ( '' ) ;
37
+ } else {
38
+ Toast . error ( '업로드에 실패했습니다. 잠시 후 다시 시도해주세요.' ) ;
39
+ }
28
40
} catch ( error ) {
29
- Toast . error ( '잠시 후 다시 시도해주세요.' ) ;
41
+ Toast . error ( '오류가 발생했습니다. 잠시 후 다시 시도해주세요.' ) ;
30
42
} finally {
31
43
setIsLoading ( false ) ;
32
44
}
33
45
} ;
34
46
35
47
return (
36
- < form
37
- onSubmit = { onUploadBoard }
38
- className = "flex flex-col bg-primary-50 p-5 border-[1px] border-primary-300 rounded-[10px] w-full"
39
- >
48
+ < form className = "flex flex-col bg-primary-50 p-5 border-[1px] border-primary-300 rounded-[10px] w-full" >
40
49
< FlexBox justify = "between" className = "w-full gap-[24px]" >
41
50
< Avatar
42
51
size = "xxl"
@@ -73,7 +82,7 @@ export default function Upload() {
73
82
size = "lg"
74
83
disabled = { isOverMaxChar }
75
84
className = "w-40"
76
- onClickAction = { ( ) => Toast . success ( '성공' ) }
85
+ onClickAction = { ( ) => onUploadBoard ( ) }
77
86
>
78
87
업로드
79
88
</ Button >
Original file line number Diff line number Diff line change @@ -15,14 +15,20 @@ export async function postBoard(postBoardData: PostBoardType) {
15
15
const url = `/endpoint/api/board/register` ;
16
16
const formData = new FormData ( ) ;
17
17
const { title, content } = postBoardData ;
18
- formData . append ( title , content ) ;
18
+ formData . append ( 'title' , title ) ;
19
+ formData . append ( 'content' , content ) ;
19
20
20
21
const response = await fetch ( url , {
21
22
method : 'POST' ,
22
23
credentials : 'include' ,
24
+ headers : {
25
+ 'Content-Type' : 'multipart/form-data' ,
26
+ } ,
23
27
body : formData ,
24
28
} ) ;
25
- return response . json ( ) ;
29
+ // return response.json();
30
+ const data = await response . json ( ) ;
31
+ console . log ( data ) ;
26
32
}
27
33
28
34
export default async function getBoardList ( {
You can’t perform that action at this time.
0 commit comments