Skip to content

Commit

Permalink
[Fix] 카테고리 ETC 삭제, [Feat] 상세 페이지 좋아요 기능 Feed #7 Detail #14
Browse files Browse the repository at this point in the history
[Fix] 카테고리 ETC 삭제, [Feat] 상세 페이지 좋아요 기능 Feed #7 Detail #14
  • Loading branch information
kr-nius authored Mar 28, 2024
2 parents 5a7e9f4 + 5aef57b commit 393114c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export default function FeedContent({ DataforFeed }: Props) {
console.log("좋아요 변경 성공");
// 성공적으로 처리된 경우 추가적인 작업 수행
} else {
// throw new Error('Network response was not ok.')
console.error("좋아요 변경 실패:", res.status);
// 실패한 경우에 대한 처리
}
Expand Down Expand Up @@ -81,9 +82,6 @@ export default function FeedContent({ DataforFeed }: Props) {
</p>
</div>
</div>
<div>
<IconStore iconStyle={IconStyle.ETC} size={30} />
</div>
</div>
<Link href={`/detail/${DataforFeed.boardId}`}>
<div className=" relative m-auto w-[90%] h-[218px]">
Expand Down
30 changes: 25 additions & 5 deletions weatherfit_refactoring/src/Components/Molecules/LikeAndComment.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
'use client'

import { useStore } from '@/Store/Store'
// import { useStore } from '@/Store/Store'
import IconStore, { IconStyle } from '../Atoms/Icon/IconStore'
import CommentIcon from './CommentIcon'
import { AuthTokenStore } from '@/Store/AuthToken'
import { AuthUserNickStore } from '@/Store/AuthUserNick'

export default function LikeAndComment({ boardId }: { boardId: BOARDID }) {
const { isLiked, toggleLikeState } = useStore()
export default function LikeAndComment({
boardId,
likelist
}: {
boardId: BOARDID;
likelist: LIKE[];
}) {
// const { isLiked, toggleLikeState } = useStore()
const { accesstoken } = AuthTokenStore()
const { userNick } = AuthUserNickStore()

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

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


const toggleLike = async () => {
try {
Expand All @@ -23,7 +42,8 @@ export default function LikeAndComment({ boardId }: { boardId: BOARDID }) {
if (!response.ok) {
throw new Error('Network response was not ok.')
}
toggleLikeState()
// toggleLikeState()
// 이 부분 만나서 이야기해봐용
} catch (error) {
console.error('좋아요 실패:', error)
}
Expand All @@ -33,7 +53,7 @@ export default function LikeAndComment({ boardId }: { boardId: BOARDID }) {
<div className="flex">
<div onClick={toggleLike} style={{ cursor: 'pointer' }}>
<IconStore
iconStyle={isLiked ? IconStyle.LIKE : IconStyle.UNLIKE}
iconStyle={isUserLiked ? IconStyle.LIKE : IconStyle.UNLIKE}
size={25}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import DetailProfile from '../Molecules/DetailProfile'
import DetailEtc from '../Molecules/DetailEtc'
import NotFound from '@/app/not-found'


export default async function DetailOrganism({
boardId,
}: {
Expand Down Expand Up @@ -46,7 +47,7 @@ export default async function DetailOrganism({
<DetailEtc boardId={boardId} nickName={fetchBoardData.nickName} />
</div>
<DetailImage images={fetchBoardData.images} />
<LikeAndComment boardId={boardId} />
<LikeAndComment boardId={boardId} likelist={fetchBoardData.likelist} />
<DetailContent
nickName={fetchBoardData.nickName}
content={fetchBoardData.content}
Expand Down

0 comments on commit 393114c

Please sign in to comment.