-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 수영장 즐겨찾기 api 연결 * feat: invalidateQueries 처리 * design: 검색 결과 없을 시 띄워주는 글 색깔 수정
- Loading branch information
Showing
9 changed files
with
85 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
|
||
import { fetchData } from '@/apis/fetch-data'; | ||
|
||
export async function PUT(request: NextRequest) { | ||
const body = (await request.json()) as Promise<{ poolId: number }>; | ||
const data = await fetchData<string>(`/pool/favorite`, 'PUT', body); | ||
|
||
return NextResponse.json(data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
|
||
async function toggleFavorite(poolId: number) { | ||
const res = await fetch(`/api/pool/favorite`, { | ||
method: 'PUT', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ poolId }), | ||
}); | ||
|
||
return res.json(); | ||
} | ||
|
||
export function useToggleFavorite() { | ||
const queryClient = useQueryClient(); | ||
return useMutation({ | ||
mutationFn: toggleFavorite, | ||
onSuccess: () => { | ||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
queryClient.invalidateQueries({ | ||
queryKey: ['useSearchPoolInitial'], | ||
}); | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters