userProfile.js 의 코드 중 리뷰작성 코드
document.addEventListener('DOMContentLoaded', () => {
// 리뷰 버튼 이벤트 등록
document.getElementById('reviewEnter').addEventListener('click', () => {
const comment = document.getElementById('comment').value.trim(); // 댓글 내용
const rating = document.getElementById('rating').value; // 별점
// 입력값 검증
if (!comment) {
alert('댓글을 입력해주세요!');
return;
}
// 리뷰 데이터를 서버로 보내거나 클라이언트에서 처리
const reviewData = {
nickname: '사용자: ', // 추후 로그인 시스템으로 사용자 닉네임 연동
comment: comment,
rating: rating,
};
// 서버에 데이터 전송 (예: socket.io, API 요청 등)
// socket.emit("newReview", reviewData); // 서버 전송
// 서버가 없다면 클라이언트에 직접 추가
addReviewToList(reviewData);
// 입력 필드 초기화
document.getElementById('comment').value = '';
document.getElementById('rating').value = '★';
});
// 리뷰 리스트에 리뷰 추가하는 함수
function addReviewToList(reviewData) {
const reviewList = document.querySelector('.review-list');
const reviewItem = document.createElement('div');
reviewItem.classList.add('review-item');
// 닉네임
const nicknameSpan = document.createElement('span');
nicknameSpan.classList.add('nickname');
nicknameSpan.textContent = reviewData.nickname;
// 댓글
const commentSpan = document.createElement('span');
commentSpan.classList.add('comment');
commentSpan.textContent = reviewData.comment;
// 별점
const ratingSpan = document.createElement('span');
ratingSpan.classList.add('rating');
ratingSpan.textContent = reviewData.rating;
// 조합
reviewItem.appendChild(nicknameSpan);
reviewItem.appendChild(commentSpan);
reviewItem.appendChild(ratingSpan);
reviewList.appendChild(reviewItem);
}
});
프론트엔드의 profile 에서 duoreview 기능을 쓰려고 할때에 필요한 기능을 추가했다. 홈페이지의 프로필에서 리뷰를 작성하면 닉네임과 댓글 그리고 별점이 추가되는 걸 볼 수 있다.
오전에는 스탠다드반에서 응용계층에 대해 배웠으며 오후에는 위의 기능을 추가하는 코드 작성을 완료했다.
팀원들과 프로젝트를 만드는데에 시간을 쏟는 1주일이 될 것이다. 그렇기에 내가 맡은 바를 잘 행하여 마무리 지어야겠다.