diff --git a/src/app/(learn)/educations/[id]/page.tsx b/src/app/(learn)/educations/[id]/page.tsx index 90bacf3..ada1cb4 100644 --- a/src/app/(learn)/educations/[id]/page.tsx +++ b/src/app/(learn)/educations/[id]/page.tsx @@ -5,25 +5,56 @@ import EducationContent from '@/components/molecules/Education/EducationContent' import ContentsEditBtn from '@/components/molecules/manage/ContentsEditBtn'; import ContentsDeleteBtn from '@/components/molecules/manage/ContentsDeleteBtn'; import ManageBtns from '@/components/molecules/manage/ManageBtns'; -import { TEducation } from '@/components/molecules/Education/EducationList'; -import { useEffect, useState } from 'react'; -import { getEducationIdApi } from '@/api/education/educationDetailApi'; - -import { testApi, testApiEditor } from '@/api/testApi'; import useEduDetail from '@/hooks/useEduDetail'; import { deleteEduApi, patchEduApi } from '@/api/eduApi'; +import { postEducationBookmarkApi, deleteEducationBookmarkApi } from '@/api/bookmarkApi'; +import WithLoginModal from '@/components/templates/login/WithLoginModal'; +import { useEffect, useState } from 'react'; const Education = ({ params }: { params: { id: number } }) => { const { eduData } = useEduDetail(params.id); + const [isLiked, setIsLiked] = useState(false); + const [showModal, setShowModal] = useState(false); + + useEffect(() => { + if (eduData) { + setIsLiked(eduData.bookmarked); + } + //eslint-disable-next-line react-hooks/exhaustive-deps + }, [eduData]); + + const onHeartClick = async (id: number, isLiked: boolean | undefined) => { + try { + let apiResult; + if (isLiked) { + apiResult = await deleteEducationBookmarkApi(id, 'EDU_CONTENT'); + } else { + apiResult = await postEducationBookmarkApi(id, 'EDU_CONTENT'); + } + if (apiResult !== undefined) { + setIsLiked(!isLiked); + } else { + setShowModal(true); + } + } catch (error) { + console.error('Error fetching bankBookmark:', error); + } + }; - const onHeartClick = async (id: number, bookmarked: boolean, contentType: 'EDU_CONTENT') => {}; return eduData ? ( -
{
+ event.stopPropagation();
+ onHeartClick();
+ }}
>
- {bookmarked ?
{
event.stopPropagation();
onHeartClick(i.id, i.bookmarked);
}}
>
{i.bookmarked ?