File tree 4 files changed +61
-1
lines changed
components/pages/main/Feed/FeedHeader
4 files changed +61
-1
lines changed Original file line number Diff line number Diff line change 3
3
import { useEffect , useState } from 'react' ;
4
4
import usePostBoard from '@/hooks/mutations/usePostBoard' ;
5
5
import useImageUpload from '@/hooks/common/useImageUpload' ;
6
+ import Image from 'next/image' ;
6
7
import Avatar from '../../../../ui/Avatar' ;
7
8
import Button from '../../../../ui/Button' ;
8
9
import FlexBox from '../../../../ui/FlexBox' ;
@@ -52,6 +53,17 @@ export default function Upload({
52
53
) : null }
53
54
</ div >
54
55
</ FlexBox >
56
+ { imagePreview && (
57
+ < div className = "relative w-full m-5 h-60 " >
58
+ < Image
59
+ fill
60
+ priority
61
+ alt = "image"
62
+ src = { imagePreview }
63
+ className = "rounded-[10px] object-contain"
64
+ />
65
+ </ div >
66
+ ) }
55
67
< FlexBox justify = "end" className = "gap-[10px] w-full" >
56
68
< label
57
69
htmlFor = "image"
Original file line number Diff line number Diff line change
1
+ import { postImageBoard } from '@/service/board' ;
2
+ // import Toast from '@/utils/notification';
3
+ import { useMutation , useQueryClient } from '@tanstack/react-query' ;
4
+
5
+ export default function usePostImageBoard (
6
+ boardId : number ,
7
+ postImageUrl : string [ ] ,
8
+ ) {
9
+ const queryClient = useQueryClient ( ) ;
10
+ const { mutate, isLoading, isSuccess } = useMutation ( {
11
+ mutationFn : ( ) => postImageBoard ( boardId , { files : postImageUrl } ) ,
12
+ onSuccess : ( ) => {
13
+ // Toast.success('게시글이 성공적으로 업로드 되었습니다.');
14
+ queryClient . invalidateQueries ( [ 'boardList' ] ) ;
15
+ } ,
16
+ onError : ( ) => {
17
+ // Toast.error(
18
+ // '게시글을 업로드하지 못했습니다. 잠시후 다시 시도해주세요.🥲',
19
+ // );
20
+ } ,
21
+ } ) ;
22
+ return { mutate, isLoading, isSuccess } ;
23
+ }
Original file line number Diff line number Diff line change 1
1
import { AuthError } from '@/lib/error' ;
2
- import { CommentList , PostBoardType , PostCommentType } from '@/types/types' ;
2
+ import {
3
+ CommentList ,
4
+ PostBoardType ,
5
+ PostCommentType ,
6
+ PostImageType ,
7
+ } from '@/types/types' ;
3
8
4
9
export async function postBoard ( postBoardData : PostBoardType ) {
5
10
const url = `endpoint/api/board/register` ;
@@ -15,6 +20,22 @@ export async function postBoard(postBoardData: PostBoardType) {
15
20
return response . json ( ) ;
16
21
}
17
22
23
+ export async function postImageBoard (
24
+ boardId : number ,
25
+ postImageData : PostImageType ,
26
+ ) {
27
+ const url = `endpoint/api/file/upload?boardId=${ boardId } ` ;
28
+ const response = await fetch ( url , {
29
+ method : 'POST' ,
30
+ credentials : 'include' ,
31
+ headers : {
32
+ 'Content-Type' : 'application/json' ,
33
+ } ,
34
+ body : JSON . stringify ( postImageData ) ,
35
+ } ) ;
36
+ return response . json ( ) ;
37
+ }
38
+
18
39
export async function getBoardList ( pageParam : number ) {
19
40
const url = `/endpoint/api/board/list?pageSize=5&pageNumber=${ pageParam } ` ;
20
41
try {
Original file line number Diff line number Diff line change @@ -96,6 +96,10 @@ export interface PostBoardType {
96
96
content : string ;
97
97
}
98
98
99
+ export interface PostImageType {
100
+ files : string [ ] ;
101
+ }
102
+
99
103
export interface PostCommentType {
100
104
boardId : number ;
101
105
parentId : number ;
You can’t perform that action at this time.
0 commit comments