-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #561 from lsc58461/part3-이정윤-week20
[이정윤] week20
- Loading branch information
Showing
30 changed files
with
345 additions
and
261 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
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
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,48 @@ | ||
import Image from "next/image"; | ||
|
||
import styles from "./CardItem.module.css"; | ||
|
||
import starOnImg from "@/assets/images/star-on.svg"; | ||
import starOffImg from "@/assets/images/star-off.svg"; | ||
import { useMutation, useQueryClient } from "@tanstack/react-query"; | ||
import fetcher from "@/lib/axios"; | ||
import { UserFolders } from "@/@types/folder.types"; | ||
|
||
interface FolderPageCardItemProps { | ||
isFavorite: boolean; | ||
linkId: number; | ||
} | ||
|
||
function CardFavoriteButton({ isFavorite, linkId }: FolderPageCardItemProps) { | ||
const queryClient = useQueryClient(); | ||
|
||
const toggleFavoriteMutation = useMutation({ | ||
mutationFn: async () => { | ||
const response = await fetcher<UserFolders[]>({ | ||
url: `/links/${linkId}`, | ||
method: "put", | ||
data: { favorite: !isFavorite }, | ||
}); | ||
return response.data; | ||
}, | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ queryKey: ["links"] }); | ||
queryClient.invalidateQueries({ queryKey: ["links", "all"] }); | ||
}, | ||
onError: (error) => { | ||
const errorResponse = (error as any).response; | ||
window.alert(errorResponse?.data.message); | ||
}, | ||
}); | ||
|
||
const handleButtonClick = () => { | ||
toggleFavoriteMutation.mutate(); | ||
}; | ||
return ( | ||
<button className={styles.bookmarkButton} onClick={handleButtonClick}> | ||
<Image src={isFavorite ? starOnImg : starOffImg} alt="즐겨찾기 이미지" /> | ||
</button> | ||
); | ||
} | ||
|
||
export default CardFavoriteButton; |
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
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
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
Empty file.
Oops, something went wrong.