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

[2주차 기본/심화/생각 과제 ] 웨비의 사진관 😋/가계부 #2

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
3 changes: 3 additions & 0 deletions jsbank/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}

Choose a reason for hiding this comment

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

오엥?

Copy link
Member

Choose a reason for hiding this comment

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

어라 5500포트로 다른 거 돌아가고 잇나...?

Copy link
Member Author

Choose a reason for hiding this comment

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

켈록켈록...아마 두 개를 동시에 돌렸나 봄...큼큼큼

70 changes: 70 additions & 0 deletions jsbank/category-manage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import {HISTORY_CATEGORY} from './initial.js';

const listIn = document.getElementById("list_in");
const listOut = document.getElementById("list_out");

/*최초 렌더링*/
HISTORY_CATEGORY.forEach((element)=>{
addCategory(element);
});

/*카테고리 화면에 추가*/
function addCategory(element){
const list = document.createElement("li");

list.innerHTML = `
<span>${element.name}</span>
Copy link
Member

Choose a reason for hiding this comment

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

템플릿 리터럴 활용 조아요👏🏻👏🏻

`;

element.type === "input"
? listIn.appendChild(list)
: listOut.appendChild(list);
}

/*새 카테고리 생성*/
const inCategory = document.getElementById("categorypg_input");
const outCategory = document.getElementById("categorypg_output");

function createCateogry(element){
if(element.keyCode === 13){
Comment on lines +28 to +29
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
function createCateogry(element){
if(element.keyCode === 13){
function createCateogry(event){
if(event.keyCode === 13){

여기는 event 객체를 받아오는거니까, e나 event로 변수명을 지어줘야 event객체를 사용하고 있구나 한 눈에 알아보기 쉽겠죠 ?!

let tempVal = {};

element.target.id === "categorypg_input"
? tempVal.type = "input"
: tempVal.type = "output";
Comment on lines +32 to +34
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
element.target.id === "categorypg_input"
? tempVal.type = "input"
: tempVal.type = "output";
tempVal.type = element.target.id === "categorypg_input"
? "input" : "output";

요렇게 사용하면 된답니당 ~!


tempVal.name = element.target.value;

addCategory(tempVal);
addStorage(tempVal);
}
}

/*로컬 저장소에 업데이트*/
function addStorage(element){
localStorage.setItem(localStorage.length, JSON.stringify(element));
}
Comment on lines +44 to +46
Copy link
Member

Choose a reason for hiding this comment

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

key 값을 현재 로컬스토리지 length로 줘서 아이템 추가될때마다 순차적으로 인덱스 부여받도록 한 건가?? 신박하다😮

Copy link
Member Author

Choose a reason for hiding this comment

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

엉,,ㅋㅋㅋ key 값을 도저히 뭘로 줘야될 지 모르겠더라고,,!!! 먼가 symbol을 써도 될 것 같기도 하고?! 일단 저 때는 제 최선이었슴다....

Copy link
Member

Choose a reason for hiding this comment

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

보통 key값은 해당 값이 무엇인지를 나타낼 수 있는 값으로 지정해줘요 ! 그래야 각 값의 key가 뭔지 매번 보지 않고, 해당하는 명명값만을 가지고 getItem을 할 수 있으니까용 !


inCategory.addEventListener("keypress",createCateogry);
outCategory.addEventListener("keypress",createCateogry);

Choose a reason for hiding this comment

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

키햐,,,심화과제 팜미,,,

Copy link
Member

Choose a reason for hiding this comment

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

요기 createCateogry 부분 스펠링 오타 있어.....ㅎ

Copy link
Member Author

Choose a reason for hiding this comment

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

오우싯~ㅋ;; 민망이슈;;

Copy link
Member

Choose a reason for hiding this comment

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

현재 keypress는 deprecated된 이벤트리스너여서 keydown사용을 권장합니다!

/*카테고리 값 불러오기*/
function loadCategory(){
let keys = Object.keys(localStorage);

for (let key of keys){
let objOption = document.createElement("li");
Comment on lines +55 to +56
Copy link
Member

Choose a reason for hiding this comment

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

함수형 프로그래밍을 위해 forEach사용을 권장합니다!
그리고 노드의 element를 만들거나 가져올 때는 const 사용을 해보는게 어떨까요??

let tempObj = JSON.parse(localStorage.getItem(key));

let type = tempObj.type;
let name = tempObj.name;

objOption.innerHTML = name;

type === "input"
?listIn.appendChild(objOption)
:listOut.appendChild(objOption);
};
}

loadCategory();
43 changes: 43 additions & 0 deletions jsbank/category.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="sub-style.css">
<title>돈쪽이의 카테고리 관리</title>
</head>
<body>
<header>
<h1>돈쪽이의 카테고리 관리</h1>
</header>
<main>
<section class="category">
<h2>수입 카테고리</h2>
<section>
<ul class="category_list" id="list_in">
</ul>
<div class="insert_category">
<label for="categorypg_input">추가</label>
<input type="text" name="categorypg_input" id="categorypg_input"/>
</div>
</section>
</section>
<hr>
<section class="category">
<h2>지출 카테고리</h2>
<section>
<ul class="category_list" id="list_out">
</ul>
<div class="insert_category">
<label for="categorypg_output">추가</label>
<input type="text" name="categorypg_output" id="categorypg_output"/>
</div>
</section>
</section>
</main>
<footer>
<a href="./index.html"><img src="./home.png" class="btn" id="home_btn"></a>
</footer>
<script src="category-manage.js" type="module"></script>
</body>
</html>
Binary file added jsbank/category.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added jsbank/home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
95 changes: 95 additions & 0 deletions jsbank/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="main-style.css">
<title>돈쪽이의 가계부</title>
</head>
<body>
<header>
<h1>돈쪽이의 가계부</h1>
</header>
<main>
<section id="asset">
<h2>나의 자산</h2>
<span class="total_asset"></span>
<div class="total_inout">
<span class="input" id="plus_ic">+</span><span class="input">-</span>
&nbsp;
<span class="output" id="minus_ic">-</span><span class="output">-</span>
</div>
</section>
<hr>
<section id="nav">
<nav id="nav_date">
<button>&lt;</button>
<h3>10월 11일</h3>
<button>&gt;</button>
</nav>
<div id="nav_list">
<span>내역 리스트</span>
<div class="input_wrapper">
<input type="checkbox" id="input_box" name="input_box" checked />
<label for="input_box">수입</label>
<input type="checkbox" id="output_box" name="output_box" checked />
<label for="output_box">지출</label>
</div>
</div>
</section>
<hr>
<section id="list_wrapper">
<ul>
</ul>

Choose a reason for hiding this comment

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

요기 빈 ul 안에는 js파일에서 무언가가 들어가는 곳인가여?!

Copy link
Member Author

Choose a reason for hiding this comment

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

맞슴다!! 렌더링 하면서 리스트 항목이 들어가는 곳!!

</section>
</main>
<section class="delete_modal">
<span>삭제하시겠습니까?</span>
<div class="input_wrapper">
<button type="button" id="allow">예</button>
<button type="button" id="reject">아니오</button>
</div>
</section>
<section class="modal_wrapper">
<h2>내역 추가</h2>
<div class="input_wrapper">
<input type="checkbox" id="input_modalbox" name="modalbox" checked />
<label for="input_modalbox">수입</label>
<input type="checkbox" id="output_modalbox" name="modalbox" />
<label for="output_modalbox">지출</label>
</div>
<div class="modal_type" id="select_input">
<label for="category_input">카테고리</label>
<select name="category" id="category_input">
<option value="" selected disabled hidden>선택해주세요</option>
<option value="알바">알바</option>
<option value="용돈">용돈</option>
</select>
</div>
<div class="modal_type" id="select_output">
<label for="category_output">카테고리</label>
<select name="category" id="category_output">
<option value="" selected disabled hidden>선택해주세요</option>
<option value="food">음식</option>
<option value="shop">쇼핑</option>
</select>
</div>
<div class="modal_type">
<label for="amount">금액</label>
<input type="text" name="amount" id="amount"/>
</div>
<div class="modal_type">
<label for="title">내역</label>
<input type="text" name="title" id="title"/>
</div>
<button type="button" id="save">저장하기</button>
<button type="button" id="close">닫기</button>
</section>
<footer>
<button type="button" class="btn" id="add_btn">+</button>
<a href="./category.html"><img src="./category.png" class="btn" id="category_btn"></a>
</footer>
<script src="main.js" type="module"></script>
<script src="modal.js" type="module"></script>

Choose a reason for hiding this comment

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

type='module' 굿~!

</body>
</html>
47 changes: 47 additions & 0 deletions jsbank/initial.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
export const INIT_BALANCE = 0;

export const HISTORY_LIST = [
{
category: "음식",
title: "GS25 코엑스점",
type: "output",
amount: 3100,
},
{
category: "음식",
title: "그릭 요거트",
type: "output",
amount: 12000,
},
{
category: "알바",
title: "현대 백화점",
type: "input",
amount: 120000,
},
{
category: "쇼핑",
title: "지그재그",
type: "output",
amount: 24500,
}
];

export const HISTORY_CATEGORY = [
{
type: "input",
name: "알바"
},
{
type: "input",
name: "용돈"
},
{
type: "output",
name: "음식"
},
{
type: "output",
name: "쇼핑"
}
];

Choose a reason for hiding this comment

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

상수파일 따로 뺀거 구웃-!

Copy link
Member

Choose a reason for hiding this comment

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

22!!!!👍🏻👍🏻

Loading