Skip to content

Commit

Permalink
[Fix] #14 코드 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeiis committed Mar 29, 2024
1 parent 1dec731 commit 2d4afaf
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function BestThreeCodi({ data }: { data?: FEEDDATA_detail }) {
return (
<div className="flex space-x-2 w-full justify-center cursor-pointer">
{data.images.map((image, index) => (
<Link href={`/detail/${data.boardId}`}>
<Link href={`feed/detail/${data.boardId}`}>
<BoxStore boxStyle={BoxStyle.BOX_IMAGE} key={index}>
<Image
src={image.imageUrl}
Expand Down
43 changes: 17 additions & 26 deletions weatherfit_refactoring/src/Components/Molecules/FeedContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,53 +7,48 @@ import { AuthTokenStore } from '@/Store/AuthToken'
import { AuthUserNickStore } from '@/Store/AuthUserNick'
import { FeedData } from '@/Store/FeedData'


interface Props {
DataforFeed: FEEDDATA
}
export default function FeedContent({ DataforFeed }: Props) {
const {feedData, setFeedData} = FeedData()
const date = new Date(DataforFeed.createDate);
const createDate:string = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDay()}`;
const { feedData, setFeedData } = FeedData()
const date = new Date(DataforFeed.createDate)
const createDate: string = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDay()}`
const { accesstoken } = AuthTokenStore()
const { userNick } = AuthUserNickStore()

const likeChecker = ( likelist:LIKE[], nickName:string | null ) => {
if( likelist.some((list) => list.nickName === nickName ) ) {
const likeChecker = (likelist: LIKE[], nickName: string | null) => {
if (likelist.some(list => list.nickName === nickName)) {
return true
} else {
return false
}
}

const isUserLiked:boolean = likeChecker( DataforFeed.likelist, userNick );

const isUserLiked: boolean = likeChecker(DataforFeed.likelist, userNick)

const clickLike = async() => {
const clickLike = async () => {
const sendToLikeAPI = `https://www.jerneithe.site/board/like/${DataforFeed.boardId}`
try {
const res = await fetch(sendToLikeAPI, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + accesstoken,
}
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + accesstoken,
},
})

if (res.ok) {
console.log("좋아요 변경 성공");
console.log('좋아요 변경 성공')
// 성공적으로 처리된 경우 추가적인 작업 수행
} else {
// throw new Error('Network response was not ok.')
console.error("좋아요 변경 실패:", res.status);
console.error('좋아요 변경 실패:', res.status)
// 실패한 경우에 대한 처리
}

} catch (error) {
console.error("좋아요 변경 실패:", error);
console.error('좋아요 변경 실패:', error)
}


}

return (
Expand Down Expand Up @@ -83,7 +78,7 @@ export default function FeedContent({ DataforFeed }: Props) {
</div>
</div>
</div>
<Link href={`/detail/${DataforFeed.boardId}`}>
<Link href={`feed/detail/${DataforFeed.boardId}`}>
<div className=" relative m-auto w-[90%] h-[218px]">
<Image
src={DataforFeed.images.imageUrl}
Expand All @@ -98,11 +93,7 @@ export default function FeedContent({ DataforFeed }: Props) {
<div className="flex">
<div className="relative">
<IconStore
iconStyle={
isUserLiked ?
IconStyle.LIKE :
IconStyle.UNLIKE
}
iconStyle={isUserLiked ? IconStyle.LIKE : IconStyle.UNLIKE}
size={25}
style="relative top-[26%]"
onClickFunction={clickLike}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default function EditHeader(boardId: BOARDID) {

if (response.ok) {
alert('수정이 완료되었습니다.')
window.location.href = `/detail/${boardId}`
window.location.href = `feed/detail/${boardId}`
} else {
alert('수정에 실패했습니다. 다시 시도해주세요.')
}
Expand Down

0 comments on commit 2d4afaf

Please sign in to comment.