-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[뉴스 뷰어 페이지 2단계] 곽가영 미션 제출합니다. #8
base: gykwak03
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -186,13 +186,14 @@ class App { | |
} | ||
}); | ||
}); | ||
this.createCommentSection(sectionElements); | ||
} | ||
this.createCommentSection(sectionElements); | ||
} | ||
|
||
createCommentSection(sectionElements) { | ||
sectionElements.forEach((section) => { | ||
section.addEventListener("click", () => { | ||
console.log(section); | ||
const commentSection = this.createElement("section"); | ||
commentSection.classList.add("comment"); | ||
|
||
|
@@ -229,25 +230,82 @@ class App { | |
|
||
const closeButton = this.createElement("button", "X"); | ||
closeButton.classList.add("X"); | ||
closeButton.addEventListener("click", () => commentSection.remove()); | ||
|
||
commentSection.appendChild(titleElement); | ||
commentSection.appendChild(descriptionElement); | ||
commentSection.appendChild(commentSection2); | ||
commentSection.appendChild(closeButton); | ||
|
||
this.appElement.appendChild(commentSection); | ||
|
||
console.log(section); | ||
this.closeComment(commentSection, closeButton); | ||
this.loadExistingComments(commentSection2); | ||
// this.resetLocalStorage(commentSection2); | ||
}); | ||
}); | ||
} | ||
|
||
loadExistingComments(commentSection2) { | ||
const storedComments = JSON.parse(localStorage.getItem("comments")); | ||
if (storedComments && storedComments.length > 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 코멘트 배열과 해당 배열의 길이를 둘다 검사한 이유가 있으신가요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 앗 두 방법으로 할 수 있다는걸 메모해두다가 저렇게 된 것 같습니다. |
||
storedComments.forEach((commentText) => { | ||
const commentElement = this.createElement("p", commentText); | ||
commentSection2.appendChild(commentElement); | ||
|
||
const deleteButton = this.createElement("button", "삭제"); | ||
commentSection2.appendChild(deleteButton); | ||
deleteButton.addEventListener("click", () => { | ||
this.deleteComment(commentElement, deleteButton); | ||
}); | ||
}); | ||
Comment on lines
+256
to
+259
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 필요 시 event.preventDefault함수를 사용해야 합니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 기능 구현 중에 댓글이 쓰여지는 지 테스트 하다 보니까 댓글이 쌓이게 되어 그런데 이걸 사용자가 접근할 수 있게끔 하는건 아닌 것 같아서 UI상에는 나타내지 않았습니다. |
||
} | ||
} | ||
|
||
deleteComment(commentElement, deleteButton) { | ||
commentElement.remove(); | ||
deleteButton.remove(); | ||
} | ||
Comment on lines
+263
to
+266
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 현재 이 메소드에 localstorage의 내용을 삭제하는 부분이 없어요 혹시 해당 키값을 삭제하고 싶었다면 filter 메소드 사용을 권장드립니다. |
||
|
||
submitComment(commentText, commentSection2) { | ||
const storedComments = JSON.parse(localStorage.getItem("comments")) || []; | ||
this.countPeople = storedComments.length; | ||
Comment on lines
+269
to
+270
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. localstorage정보를 가져오는 기능을 간결하게 작성해주셨네요 |
||
this.countPeople++; | ||
const commentContent = `익명 ${this.countPeople}: ${commentText}`; | ||
const commentElement = this.createElement("p", commentContent); | ||
commentSection2.appendChild(commentElement); | ||
|
||
const deleteButton = this.createElement("button", "삭제"); | ||
commentSection2.appendChild(deleteButton); | ||
deleteButton.addEventListener("click", () => { | ||
this.deleteComment(commentElement, deleteButton); | ||
}); | ||
|
||
// 새 댓글을 배열에 추가 | ||
storedComments.push(commentContent); | ||
// 배열을 다시 로컬 스토리지에 저장 | ||
localStorage.setItem("comments", JSON.stringify(storedComments)); | ||
} | ||
Comment on lines
+283
to
+286
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 현재는 모든 기사가 같은 댓글창을 공유하고 있어요 |
||
|
||
resetLocalStorage(commentSection2) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. commentSection2는 네이밍으로 적절하지 않아보입니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넵 replySection 변수로 모두 수정하겠습니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. resetLocalStorage에서 사용되는 전체 댓글 삭제는 현재 사용되지 않은 것 같습니다. 기능을 제외한 이유가 있으신가요? |
||
const resetButton = this.createElement("button", "전체댓글삭제"); | ||
commentSection2.appendChild(resetButton); | ||
|
||
resetButton.addEventListener("click", () => { | ||
localStorage.removeItem("comments"); | ||
|
||
// "p" 태그를 모두 찾아서 제거 | ||
const commentElements = commentSection2.getElementsByTagName("p"); | ||
Array.from(commentElements).forEach((commentElement) => { | ||
commentElement.remove(); | ||
}); | ||
}); | ||
} | ||
|
||
closeComment(commentSection, closeButton) { | ||
closeButton.addEventListener("click", () => { | ||
if (commentSection.parentNode) { | ||
commentSection.parentNode.removeChild(commentSection); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -167,14 +167,17 @@ background: #CECECE; | |
position: absolute; | ||
width: 400px; | ||
height: auto; | ||
left: 508px; | ||
top: 226px; | ||
left: 150px; /* 수정된 값 */ | ||
top: 250px; /* 수정된 값 */ | ||
Comment on lines
+170
to
+171
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 삭제하겠습니다!! |
||
background: #FFFFFF; | ||
border-radius: 20px; | ||
padding: 20px; | ||
box-sizing: border-box; | ||
border-width: 100px; | ||
border-color: #000000; | ||
} | ||
|
||
|
||
.comment2{ | ||
/* Rectangle 45 */ | ||
|
||
Comment on lines
167
to
183
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 최소한의 css가 되어있지 않으면 사용자가 어플리케이션을 사용할 때 불편함을 느낄 수 있어요
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
class BankAccount { | ||
constructor() { | ||
// 밑줄로 시작하는 네이밍 컨벤션을 통해 private 속성임을 나타냄 | ||
this._balance = 0; | ||
} | ||
|
||
// setter 메서드를 통해 _balance 속성에 접근 | ||
set balance(newBalance) { | ||
if (newBalance >= 0) { | ||
this._balance = newBalance; | ||
} else { | ||
console.log("잘못된 금액입니다."); | ||
} | ||
} | ||
|
||
// getter 메서드를 통해 _balance 속성을 읽음 | ||
get balance() { | ||
return this._balance; | ||
} | ||
} | ||
|
||
const account = new BankAccount(); | ||
|
||
// setter를 통한 값 변경 | ||
account.balance = 1000; | ||
|
||
// getter를 통한 값 읽기 | ||
console.log(account.balance); // 1000 | ||
|
||
// 잘못된 값으로 setter 호출 | ||
account.balance = -500; // "잘못된 금액입니다." 출력 | ||
console.log(account.balance); // 1000 (이전 값 유지) | ||
Comment on lines
+1
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 발표를 위한 코드 단락인가요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 앗 네네 잘못 들어갔네요 삭제하겠습니다. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.log는 삭제해주세요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵!!