작성
·
177
0
https://www.youtube.com/watch?v=x7H_mIa5rTE
제로초님 유튜브 강의 영상에서
프론트에 좋아요 좋아요 취소 버튼 만들려고 하는데
유튜브 강의영상에는 pug로 나왔있어서
-const like = twit %% twit.Liker.map(l => l.id).includes(req.user.id)
이부분을 새로 리뉴얼된 강의에 맞게 바꿀려고 하는데
{% if not LikerIdList.includes(req.user.id) and twit.User.id !== user.id %}
이런식으로 바꿔서 사용하려고 합니다 그래서
router.use((req, res, next) => {
//res.locals를 통해서 프론트에서 이 변수를 사용할 수 있습니다
res.locals.user = req.user;
// req.user 이 있다는것은 로그인을 했다는 뜻
res.locals.followerCount = req.user ? req.user.Followers.length : 0;
res.locals.followingCount = req.user ? req.user.Followings.length : 0;
res.locals.followerIdList = req.user ? req.user.Followings.map(f => f.id) : [];
res.locals.LikerIdList =
next();
});
이 부분을 바꿔야 할꺼 같은데 res.locals.LikerIdList에 무었을 넣어주면 되나요?
아무리 고민해도 잘 모르겠네요
답변 1
0
res.locals는 전역에서 쓰이는 값이라서 개별 포스트 당 좋아요 누른 사람을 체크하기는 무리가 있습니다. 마찬가지로 twit.Liker 방식으로 가셔야합니다.