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

[7주차 과제] - 카드 맞추기 리펙토링 #5

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ba8dff4
[FEAT] 2주차 세팅
gunom Apr 17, 2023
1fe7a3a
[FEAT] backery - tag filter 추가 및 삭제 구현
gunom Apr 17, 2023
c488283
[FEAT] backery - 상품 js로 로딩 및 필터링 구현
gunom Apr 17, 2023
f75994a
[FEAT] backery - 태그 모달 구현
gunom Apr 17, 2023
622d2e1
[FEAT] todomate - todo리스트 js로 구현 및 할일 숫자 반영
gunom Apr 17, 2023
bebcc04
[FEAT] todomate - todo 남은 할 일 동적 반영
gunom Apr 17, 2023
24f40e4
[FEAT] todomate - todo 할 일 추가 구현
gunom Apr 17, 2023
414e1ba
[FEAT] todomate - 달력, mypage 버튼 이동 구현
gunom Apr 17, 2023
0f2b4d3
[FIX] todomate - article 동적으로 제대로 생성안되는 오류 수정
gunom Apr 17, 2023
8024bce
[FIX] todomate - todo 추가시 tododataList 리셋되는 오류 수정
gunom Apr 17, 2023
cdc1720
[FIX] backery - tag 넘어가는 사이즈 조정
gunom Apr 17, 2023
d42d494
[FEAT] 1번과제 - 헤더, 난이도 버튼 구현
gunom Apr 25, 2023
9f81e6f
[FEAT] 1번과제 - 버튼 셀렉 시 고정 및 리셋 버튼 구현
gunom Apr 25, 2023
2a4084e
[FEAT] 1번과제 - 카드 컴포넌트 기본 구현
gunom Apr 25, 2023
24dda04
[FEAT] 1번과제 - 카드 매칭 구현 및 리셋 초기화 구현
gunom Apr 27, 2023
3e4d2d5
[FEAT] 1번과제 - 정답 시 모달과 스코어 색깔 변경
gunom May 5, 2023
a06d114
[REFACTOR] 코드 리뷰 반영
gunom Jun 2, 2023
ac086b9
[CHORE] 3주차 복사
gunom Jun 5, 2023
69f3667
[REFACTOR] ts 컨버팅
gunom Jun 7, 2023
61fc87c
[FEAT] recoil 적용
gunom Jun 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions week2/backery/backery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const data = [
{
name: '케이크인 소금빵',
category: 'cake',
tag: ['#맛있어', '#내가 좋아해', '#진짜야'],
image: "./salt-bread.jpg"
},
{
name: '다쿠아즈인 소금빵',
category: 'dacquoise',
tag: ['#맛있어', '#내가 좋아해', '#진짜야'],
image: "./salt-bread.jpg"
},
{
name: '소금빵',
category: 'backery',
tag: ['#맛있어', '#내가 좋아해', '#진짜야'],
image: "./salt-bread.jpg"
},
{
name: '소금빵',
category: 'backery',
tag: ['#맛있어', '#내가 좋아해', '#진짜야'],
image: "./salt-bread.jpg"
},
{
name: '소금빵',
category: 'backery',
tag: ['#맛있어', '#내가 좋아해', '#진짜야'],
image: "./salt-bread.jpg"
},
{
name: '소금빵',
category: 'backery',
tag: ['#맛있어', '#내가 좋아해', '#진짜야'],
image: "./salt-bread.jpg"
},
]

export default data;
59 changes: 59 additions & 0 deletions week2/backery/bakery.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>backery</title>
<link rel="stylesheet" href="./style.css" />
<script
src="https://kit.fontawesome.com/fdaeef652b.js"
crossorigin="anonymous"
></script>
<script async src="./index.js" type="module"></script>
</head>

<body>
<header>
<h1 class="title">Goo's Backery</h1>
<button class="menu-btn">
<i class="fa-solid fa-bars"></i>
</button>
</header>
<main>
<nav>
<span class="nav-title">종류</span>
<ul class="nav-box">
<li class="nav-item">
<label for="all-filter">
<input type="checkbox" data-category="all" />
전체</label
>
</li>
<li class="nav-item">
<label for="backery-filter">
<input type="checkbox" data-category="backery" />
베이커리</label
>
</li>
<li class="nav-item">
<label for="cake-filter">
<input type="checkbox" data-category="cake" />
케이크</label
>
</li>
<li class="nav-item">
<label for="dacquoise-filter">
<input type="checkbox" data-category="dacquoise" />
다쿠아즈</label
>
</li>
</ul>
</nav>
<section class="product-section">
<section class="select-filter"></section>
<section class="grid-container"></section>
</section>
</main>
</body>
</html>
Binary file added week2/backery/cake-slice.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 week2/backery/heart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
185 changes: 185 additions & 0 deletions week2/backery/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
import data from "./backery.js";

const products = data
console.log(data)
const categoryList = [];

const categoryButton = document.querySelectorAll('.nav-item > label > input');

products.forEach((product) => {
const productsContainer = document.querySelector('.grid-container');
const productElement = document.createElement('article');
productElement.classList.add('card');
productElement.innerHTML = `
<h2 class="card-title">${product.name}</h2>
<div class="card-tagwrapper">
<ul class="card-tags">
</ul>
<button class="card-tags-add">+</button>
<div class="modal">
<div class="modal-content">
<span class="close-btn">&times;</span>
<ul class="modal-tags">
</ul>
</div>
</div>
</div>
</div>
<img src="${product.image}" alt="상품이미지" />
<button class="card-like">
<i class="fa fa-heart"></i>
</button>
`;
product.tag.forEach((tag) => {
const tagElement = document.createElement('li');
tagElement.classList.add('card-tag');
tagElement.textContent = tag;
productElement.querySelector('.card-tags').appendChild(tagElement);
});
product.tag.forEach((tag) => {
const tagElement = document.createElement('li');
tagElement.classList.add('modal-tag');
tagElement.textContent = tag;
productElement.querySelector('.modal-tags').appendChild(tagElement);
});
productsContainer.addEventListener('click', (event) => {
const addButton = event.target.closest('.card-tags-add');
if (addButton) {
const productElement = addButton.closest('.card');
const modal = productElement.querySelector('.modal');
modal.style.display = "block";
const buttonRect = addButton.getBoundingClientRect();
const modalTop = buttonRect.top - modal.offsetHeight;
const modalLeft = buttonRect.right - (modal.offsetWidth / 2);
modal.style.top = `${modalTop}px`;
modal.style.left = `${modalLeft}px`;
modal.classList.add('show');
}
});
productsContainer.addEventListener('click', (event) => {
const closeButton = event.target.closest('.close-btn');
if (closeButton) {
const modal = closeButton.closest('.modal');
modal.style.display = "none";
modal.classList.remove('show');
}
});
productsContainer.appendChild(productElement);
});

categoryButton.forEach((button) => {
button.addEventListener('click', (event) => {
const category = event.target.dataset.category;
if (button.checked) {
categoryList.push(category);
} else {
const index = categoryList.indexOf(category);
categoryList.splice(index, 1);
}
displaySelectFilter();
displayProducts();
});
});

const displaySelectFilter = () => {
const selectFilter = document.querySelector('.select-filter');
const selectFilterElements = categoryList.map((category) => {
return `
<div class="select-filter-item">
<span>${category}</span>
<button class="select-filter-item-delete">
<i class="fa fa-times"></i>
</button>
</div>
`;
});
selectFilter.innerHTML = selectFilterElements.join("");
const deleteButtons = selectFilter.querySelectorAll('.select-filter-item-delete');
deleteButtons.forEach((button) => {
button.addEventListener('click', (event) => {
const parent = event.target.closest('.select-filter-item');
const category = parent.querySelector('span').textContent;
const index = categoryList.indexOf(category);
categoryList.splice(index, 1);
categoryButton.forEach((categoryBtn) => {
if (categoryBtn.dataset.category === category) {
categoryBtn.checked = false;
}
})
displaySelectFilter();
displayProducts();
});
});
};

const displayProducts = () => {
let categoryProducts = [];
if (categoryList.length === 0) {
categoryProducts = products;
} else if (categoryList.indexOf('all') > -1) {
categoryProducts = products;
} else {
categoryProducts = products.filter((product) => categoryList.indexOf(product.category) !== -1);
}
const productsContainer = document.querySelector('.grid-container');
productsContainer.innerHTML = '';
categoryProducts.forEach((product) => {
const productElement = document.createElement('article');
productElement.classList.add('card');
productElement.innerHTML = `
<h2 class="card-title">${product.name}</h2>
<div class="card-tagwrapper">
<ul class="card-tags">
</ul>
<button class="card-tags-add">+</button>
<div class="modal">
<div class="modal-content">
<span class="close-btn">&times;</span>
<ul class="modal-tags">
</ul>
</div>
</div>
</div>
</div>
<img src="${product.image}" alt="상품이미지" />
<button class="card-like">
<i class="fa fa-heart"></i>
</button>
`;
product.tag.forEach((tag) => {
const tagElement = document.createElement('li');
tagElement.classList.add('card-tag');
tagElement.textContent = tag;
productElement.querySelector('.card-tags').appendChild(tagElement);
});
product.tag.forEach((tag) => {
const tagElement = document.createElement('li');
tagElement.classList.add('modal-tag');
tagElement.textContent = tag;
productElement.querySelector('.modal-tags').appendChild(tagElement);
});
productsContainer.addEventListener('click', (event) => {
const addButton = event.target.closest('.card-tags-add');
if (addButton) {
const productElement = addButton.closest('.card');
const modal = productElement.querySelector('.modal');
modal.style.display = "block";
const buttonRect = addButton.getBoundingClientRect();
const modalTop = buttonRect.top - modal.offsetHeight;
const modalLeft = buttonRect.right - (modal.offsetWidth / 2);
modal.style.top = `${modalTop}px`;
modal.style.left = `${modalLeft}px`;
modal.classList.add('show');
}
});
productsContainer.addEventListener('click', (event) => {
const closeButton = event.target.closest('.close-btn');
if (closeButton) {
const modal = closeButton.closest('.modal');
modal.style.display = "none";
modal.classList.remove('show');
}
});
productsContainer.appendChild(productElement);
});
}
Binary file added week2/backery/salt-bread.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading