로그인 여부 확인
const { isAuthenticated } = useAuthContext(); //로그인 여부 체크
if (isAuthenticated) {
...코드
} else {
setAlertMessage('로그인 후 이용 가능합니다.');
setAlertOpen(true);
}
emotion code에 따라 좋아요 여부 등록
const emotionCd = mbtiStore.mbti.myEmotionCd?.code === 400101 ? 400102 : 400101;
if (mbtiStore.mbti.myEmotionCd?.code === 400101) {
await mbtiStore.removeLike(mbtiStore.mbti.mbtiSid);
} else {
await mbtiStore.addLike(mbtiStore.mbti.mbtiSid, emotionCd);
}
mbtiStore.get(Number(id)).then(() =>
setContent(mbtiStore.mbti)
);
const handleLike = async () => {
if (isAuthenticated) {
const emotionCd = mbtiStore.mbti.myEmotionCd?.code === 400101 ? 400102 : 400101;
if (mbtiStore.mbti.myEmotionCd?.code === 400101) {
await mbtiStore.removeLike(mbtiStore.mbti.mbtiSid);
} else {
await mbtiStore.addLike(mbtiStore.mbti.mbtiSid, emotionCd);
}
mbtiStore.get(Number(id)).then(() =>
setContent(mbtiStore.mbti)
);
} else {
setAlertMessage('로그인 후 이용 가능합니다.');
setAlertOpen(true);
}
};
<Box
id="mbtiLike"
sx={{
...likeStyle,
background: mbtiStore.mbti.myEmotionCd?.code === 400101 ? '' : '#FAFAFA',
textAlign: 'center',
cursor: 'pointer',
border: mbtiStore.mbti.myEmotionCd?.code === 400101 ? '1px solid #eeeeee' : '',
}}
onClick={handleLike}
>
{mbtiStore.mbti.myEmotionCd?.code === 400101 ? (
<>
<Iconify icon={'ph:heart-straight-fill'} width={25} color={theme.palette.primary.main}/>
<Typography variant={'Kor_12_r'} sx={{ color: theme.palette.primary.main }}>
{numberComma(content.likeCnt || 0)}
</Typography>
</>
) : (
<>
<Iconify icon={'ph:heart-straight-bold'} width={25} color={'#9DA0A5'} />
<Typography variant={'Kor_12_r'} sx={{ color: '#9DA0A5' }}>
{numberComma(content.likeCnt)}
</Typography>
</>
)}
</Box>