Skip to content
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

Week2/assign2 #4

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open

Week2/assign2 #4

wants to merge 19 commits into from

Conversation

SooY2
Copy link
Member

@SooY2 SooY2 commented Oct 27, 2023

✨ 구현 기능 명세

  • 기본 과제
  • 생각 과제
  1. 최초 데이터

    1. 상수로 INIT_BALANCE, HISTORY_LIST 데이터를 가집니다. (상수명은 자유)

      • INIT_BALANCE = 0
      • HISTORY_LIST : 입출금 내역 리스트 (4개)
    2. 최초 실행시 위 상수 데이터들 이용해 렌더링합니다. (즉, html에 직접 박아놓는 하드코딩 ❌)

      → 나의 자산은 INIT_BALANCE로부터 4개의 입출금 내역 리스트를 반영하여 보여줍니다.

  2. 총수입 / 총지출

    1. 마찬가지로 최초에 HISTORY_LIST에 있는 수입 내역과 지출 내역을 계산해서 총수입, 총지출을 보여줍니다.
  3. 수입/지출 필터링

    1. 수입, 지출 선택에 따라 내역 리스트가 필터링됩니다.
  4. 리스트 삭제

    1. 각 리스트의 X 버튼을 누르면 해당 리스트가 삭제됩니다.
    2. 리스트 삭제시 나의 자산에 반영됩니다.
    3. 리스트 삭제시 총 수입 / 총 지출에 반영됩니다.
  5. 리스트 추가

    하단 footer의 + 버튼을 누르면 리스트 추가 모달이 나타납니다.

    1. 수입 지출 버튼
      • default ⇒ 수입
      • 하나를 선택하면 다른 항목은 자동으로 선택이 풀립니다.
    2. 카테고리를 선택
      • 수입을 선택하면 수입 관련된 항목들이, 지출을 선택하면 종류에 지출 관련된 항목들이 나옵니다.
      • 카테고리는 수입, 지출 각각 2개 이상씩 있습니다.
    3. 금액내용 입력 input
    4. 저장하기 버튼
      • 저장하기 버튼 클릭시 입력한 내용들로 이뤄진 리스트가 추가됩니다.
      • 이에 따라 나의 자산(잔액), 총수입, 총지출도 알맞게 변경됩니다.
      • 저장 성공시 alert 메시지를 띄웁니다.
      • 저장하기를 눌러도 모달이 닫히지 않습니다.
    5. 닫기 버튼
      • 클릭하면 모달이 사라집니다.

💎 PR Point

  • js 변수 선언부분

    let  itemContainer;
    let  type='income';
    let  category;
    let  content;
    let  amount;
    let  nowid=3;
    

    foreach돌면서 변수에 값 넣어둘거라 let으로 선언했는데 이러면 메모리공간하나에 값만 계속 바뀌는거 맞나욤??! 아니면 메모리공간도 계속 생기나..

  • list정보 보여주는 함수

    //각 list의 정보 보여주는 함수 (중복해서 쓰여서 따로 뺌)
    
    const  showList  =(list)=>{
    
    itemContainer  =  document.createElement('li');
    
    category  =  document.createElement('span');
    
    category.textContent=list.category;
    
    itemContainer.appendChild(category);
    
      
    
    content  =  document.createElement('span');
    
    content.textContent=list.content;
    
    itemContainer.appendChild(content);
    
      
    
    amount  =  document.createElement('span');
    
    amount.textContent=list.amount;
    
    itemContainer.appendChild(amount);
    
    amount.classList.add(list.type);
    
      
    
    const  button  =  document.createElement('button');
    
    button.textContent  =  'x';
    
    button.classList.add("xbtn");
    
    itemContainer.appendChild(button);
    
    //x버튼 클릭시 이벤트
    
    button.addEventListener('click',()=>{
    
    console.log(list.id,"삭제 버튼");
    
    deleteItem(list.id);
    
    console.log(HISTORY_LIST)
    
    });
   
    listcontent.appendChild(itemContainer);
    }

초기화면 리스트 보여지는거랑 삭제로직 구현하다보니 겹치는 부분이 있어 하나의 함수로 만들었다.

  • 중복부분
    코드를 보면
    HISTORY_LIST.forEach(list=>showList(list)); 이 부분이 함수내에 많이 나타난다. 이것도 하나의 함수로 나타낼 수 있을지...

calculateTotal();`

  • select태그
    slect태그 사용시 모바일화면으로 변환하면 레이아웃이 이상해지던데 저만 그랬나요..ㅠ 다들 어떻게 하셨는지 궁금해요!
    저는 html엔 select태그만, js로 option 추가해주었어요!(수입/지출에 따라)

🥺 소요 시간, 어려웠던 점

  • 4h
  • 이전 과제의 html과 css를 기반으로 하다보니 html과 css를 무작정 작성하지않고 추후에 개발할 나를 위해서라도 클래스명과 태그를 신경써서 작성해야한다는걸 깨달았다... class랑 id명 바꾸고 추가하는데만도 꽤 시간을 썼다.
  • select태그가 모바일화면에선 잘 작동하지 않아 해결해보려하느라 힘들었다.(결국 못했지만...)
  • 시간이 없어서 prpoint자세히 못썼다ㅠㅠㅠ,, 코드에 주석 달았으니 그거라도,, 시험끝나면 이렇게 촉박하게 안할거야🥲
  • 그리고!! 시험기간이라 기간내에 심화까지 못한게 너무너무 아쉽🥺 꼭 심화까지 완성할고야

🌈 구현 결과물

https://www.notion.so/dosopt/2-4f2f881b6ce5414c97ccdfe0d7b54017?pvs=4

Copy link
Member

@nayujin-dev nayujin-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

늦은시간까지 수고많았오 :octocat: 팟팅팟팅!! 코드리뷰 반영하는거 오래걸렸을텐데 벌써 다했네!! 멋지닷 나두 후딱 .. !!

</label>
</div>
<div class="modal-inputItem-container">
<label for="select-category">종류</label>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기 label의 아이디랑 밑에 select 태그의 id가 같아서 그랬던것같은데 아닌가??

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아닐수도 .. 나는 select 태그 내에 옵션내용 이런식으로 넣어줬는데 잘 동작했어!

@@ -0,0 +1,219 @@
const INIT_BALANCE =0;
let HISTORY_LIST=[
{id:0,type:"income",category:"과외비",content:"10월 월급",amount:50000},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수여니 프리티어 설치 안됐나보다 헤헤

button.classList.add("xbtn");
itemContainer.appendChild(button);
//x버튼 클릭시 이벤트
button.addEventListener('click',()=>{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

나는 심화과제하다보니 모달띄우는것때문에 코드가 길어져서 따로 함수로 뺐어!

BALANCE.textContent=balance;
}

window.onload = ()=>{ //최초 실행시 렌더링
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 윈도우 내장함수 ~~ 요건 생각못했다!! 조아조아

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

캡슐화 해서 최초 실행 시 렌더링 되는 함수 모아둔거 좋다 좋당 !


//리스트 삭제
const deleteItem=(deleteid)=>{
HISTORY_LIST = HISTORY_LIST.filter(item => item.id!==deleteid);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오앙 나는 그냥 x 버튼 클릭하면 x버튼의 부모요소(=해당 리스트)를 삭제하도록했는데 수연이 방법도 좋다!!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

내가 한 방법은 리스트에 id 필드가 없어도 된닷!!

HISTORY_LIST.forEach(list=>showList(list));
calculateTotal();

alert("저장이 완료되었습니다!!");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

엇 나 이때까지 window.alert()로 항상 사용했는데 안그래도 됐군 ,, 키키

Copy link

@Yeonseo-Jo Yeonseo-Jo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오앙 .. 심화과제까지 추가로 하느라 넘 수고 많았엉 !!🔥
전체적으로 같은 기능을 하는 함수끼리 묶어보는 연습을 하면 더 더 완벽할것 같습니댜🌟!
담주도 화이팅~!~!

let content;
let amount;
let nowid=3;
// let button;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

주석은 삭제해주깅 !

itemContainer.appendChild(button);
//x버튼 클릭시 이벤트
button.addEventListener('click',()=>{
console.log(list.id,"삭제 버튼");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

console도 꼭 지워주기 !!

Comment on lines +60 to +61
totalExpense=0;
totalIncome=0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

위에서 totalExpense, totalIncome을 0으로 초기화 해줬는데 여기서 한 번 더 0으로 초기화 한 이유가 궁금합니댜!
그리고 상수 값처럼 쓰이는 값이니까 대문자로 표기해주면 더 좋을것 같앙!

Suggested change
totalExpense=0;
totalIncome=0;
let TOTAL_EXPENSE=0;
let TOTAL_INCOME=0;

const showIncome = document.getElementById('incomeCheckbox').checked;
const showExpense = document.getElementById('expenseCheckbox').checked;

console.log(showIncome,showExpense);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

콘솔 지우기 얍!

Comment on lines 14 to 24
<div id="balanceBox">
<p>나의 자산</p>
<h1 id="balance">234234</h1>
<ul>
<li class="income">
<span>+</span>
<span id="totalIncome"></span>
</li>
<li class="expense">
<span>-</span>
<span id="totalExpense"></span>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수연이두 id와 class를 혼합해서 쓰는것 같아!
유진언니 리뷰에도 남겼던건데..!

css 스타일링 할 때, js로 요소를 가져올 때 일정한 규칙 없이 클래스, id를 사용하면 개발 할 때도 어렵고 유지보수 및 가독성 측면에서도 단점이 될 수 있습니댜!

이전에 알려주었던 bem 방식 등을 참고해서,
id, class 중 어떤 것을 사용해야 할지 / 클래스명이나 id 명을 짓는 일정한 규칙 등에 대해 더 고민해보면 좋을것 같아!!

Comment on lines +97 to +103
HISTORY_LIST.filter(list =>{
if(list.type==="income" && showIncome) return true;
if(list.type==="expense" && showExpense) return true;
return false;
}).forEach((list) =>showList(list));

};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filter 메서드 활용해서 showList 함수 써준거 좋당 !!


/*----------------------------- */
//모달 표시하고 닫기
document.addEventListener('DOMContentLoaded', function() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

화살표 함수 : () => {} 형태랑 function 키워드 함수 : function() {} 형태를 혼합해서 같이 사용하고 있는것 같아용!
가독성을 위해 한 형태로 통일해주는건 어떨까?!

/*----------------------------- */
//모달 표시하고 닫기
document.addEventListener('DOMContentLoaded', function() {
const openModalButton = document.querySelector('footer > button');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

querySelector로 요소를 가져올 때 이런식으로 자식 태그 선택자를 사용해도 좋지만!
나는 유지 보수 및 가독성을 위해 조작이 필요한 요소는 직접 클래스명을 부여하는걸 더 선호하는 편이얌 ㅎㅎ
이 부분 한 번 고민해보면 좋을것 같습니댜

Comment on lines +161 to +172
options = [
{ value: '과외비', text: '과외비' },
{ value: '용돈', text: '용돈' },
{ value: '기타', text: '기타' }
];
} else if (type==='expense') {
options = [
{ value: '식비', text: '식비' },
{ value: '교통비', text: '교통비' },
{ value: '기타', text: '기타' }
];
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기 options는 따로 data화 해서 상수로 빼준 다음 가지고 오는 방식으로 해도 좋겠다!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그리구 select 태그가 모바일 화면으로 보면 레이아웃이 이상해진다고 했는데, 그건 모바일 브라우저에서 상속받는 기본 레이아웃 값이 있어서 그런걸수도 있엉!

이런 경우 모바일 화면에도 적용 가능한 css를 찾아 적용해주면 모바일 화면에서도 내가 원하는 스타일링을 가진 select 태그를 사용할수 있습니당!

Comment on lines +9 to +12
let itemContainer;
let type='income';
let category;
let content;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요 변수들은 상수가 아닌데 최상단에 먼저 선언한 이유가 있는지 궁금합니댜 !!

개인적으로는, 데이터를 나타내는 상수를 제외하고는, 변수가 사용될 부분에서 선언하는 것이 더 가독성 있어 보인다구 생각합니당

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants