Skip to content

[담임매니저 차현빈] Chapter 1-1. 프레임워크 없이 SPA 만들기#75

Open
chb6734 wants to merge 49 commits intohanghae-plus:mainfrom
chb6734:main
Open

[담임매니저 차현빈] Chapter 1-1. 프레임워크 없이 SPA 만들기#75
chb6734 wants to merge 49 commits intohanghae-plus:mainfrom
chb6734:main

Conversation

@chb6734
Copy link
Copy Markdown

@chb6734 chb6734 commented Jul 11, 2025

과제 체크포인트

배포 링크

기본과제

상품목록

상품 목록 로딩

  • 페이지 접속 시 로딩 상태가 표시된다
  • 데이터 로드 완료 후 상품 목록이 렌더링된다
  • 로딩 실패 시 에러 상태가 표시된다
  • 에러 발생 시 재시도 버튼이 제공된다

상품 목록 조회

  • 각 상품의 기본 정보(이미지, 상품명, 가격)가 카드 형태로 표시된다

한 페이지에 보여질 상품 수 선택

  • 드롭다운에서 10, 20, 50, 100개 중 선택할 수 있으며 기본 값은 20개 이다.
  • 선택 변경 시 즉시 목록에 반영된다

상품 정렬 기능

  • 상품을 가격순/인기순으로 오름차순/내림차순 정렬을 할 수 있다.
  • 드롭다운을 통해 정렬 기준을 선택할 수 있다
  • 정렬 변경 시 즉시 목록에 반영된다

무한 스크롤 페이지네이션

  • 페이지 하단 근처 도달 시 다음 페이지 데이터가 자동 로드된다
  • 스크롤에 따라 계속해서 새로운 상품들이 목록에 추가된다
  • 새 데이터 로드 중일 때 로딩 인디케이터와 스켈레톤 UI가 표시된다
  • 홈 페이지에서만 무한 스크롤이 활성화된다

상품을 장바구니에 담기

  • 각 상품에 장바구니 추가 버튼이 있다
  • 버튼 클릭 시 해당 상품이 장바구니에 추가된다
  • 추가 완료 시 사용자에게 알림이 표시된다

상품 검색

  • 상품명 기반 검색을 위한 텍스트 입력 필드가 있다
  • 검색 버튼 클릭으로 검색이 수행된다
  • Enter 키로 검색이 수행된다
  • 검색어와 일치하는 상품들만 목록에 표시된다

카테고리 선택

  • 사용 가능한 카테고리들을 선택할 수 있는 UI가 제공된다
  • 선택된 카테고리에 해당하는 상품들만 표시된다
  • 전체 상품 보기로 돌아갈 수 있다
  • 2단계 카테고리 구조를 지원한다 (1depth, 2depth)

카테고리 네비게이션

  • 현재 선택된 카테고리 경로가 브레드크럼으로 표시된다
  • 브레드크럼의 각 단계를 클릭하여 상위 카테고리로 이동할 수 있다
  • "전체" > "1depth 카테고리" > "2depth 카테고리" 형태로 표시된다

현재 상품 수 표시

  • 현재 조건에서 조회된 총 상품 수가 화면에 표시된다
  • 검색이나 필터 적용 시 상품 수가 실시간으로 업데이트된다

장바구니

장바구니 모달

  • 장바구니 아이콘 클릭 시 모달 형태로 장바구니가 열린다
  • X 버튼이나 배경 클릭으로 모달을 닫을 수 있다
  • ESC 키로 모달을 닫을 수 있다
  • 모달에서 장바구니의 모든 기능을 사용할 수 있다

장바구니 수량 조절

  • 각 장바구니 상품의 수량을 증가할 수 있다
  • 각 장바구니 상품의 수량을 감소할 수 있다
  • 수량 변경 시 총 금액이 실시간으로 업데이트된다

장바구니 삭제

  • 각 상품에 삭제 버튼이 배치되어 있다
  • 삭제 버튼 클릭 시 해당 상품이 장바구니에서 제거된다

장바구니 선택 삭제

  • 각 상품에 선택을 위한 체크박스가 제공된다
  • 선택 삭제 버튼이 있다
  • 체크된 상품들만 일괄 삭제된다

장바구니 전체 선택

  • 모든 상품을 한 번에 선택할 수 있는 마스터 체크박스가 있다
  • 전체 선택 시 모든 상품의 체크박스가 선택된다
  • 전체 해제 시 모든 상품의 체크박스가 해제된다

장바구니 비우기

  • 장바구니에 있는 모든 상품을 한 번에 삭제할 수 있다

상품 상세

상품 클릭시 상세 페이지 이동

  • 상품 목록에서 상품 이미지나 상품 정보 클릭 시 상세 페이지로 이동한다
  • URL이 /product/{productId} 형태로 변경된다
  • 상품의 자세한 정보가 전용 페이지에서 표시된다

상품 상세 페이지 기능

  • 상품 이미지, 설명, 가격 등의 상세 정보가 표시된다
  • 전체 화면을 활용한 상세 정보 레이아웃이 제공된다

상품 상세 - 장바구니 담기

  • 상품 상세 페이지에서 해당 상품을 장바구니에 추가할 수 있다
  • 페이지 내에서 수량을 선택하여 장바구니에 추가할 수 있다
  • 수량 증가/감소 버튼이 제공된다

관련 상품 기능

  • 상품 상세 페이지에서 관련 상품들이 표시된다
  • 같은 카테고리(category2)의 다른 상품들이 관련 상품으로 표시된다
  • 관련 상품 클릭 시 해당 상품의 상세 페이지로 이동한다
  • 현재 보고 있는 상품은 관련 상품에서 제외된다

상품 상세 페이지 내 네비게이션

  • 상품 상세에서 상품 목록으로 돌아가는 버튼이 제공된다
  • 브레드크럼을 통해 카테고리별 상품 목록으로 이동할 수 있다
  • SPA 방식으로 페이지 간 이동이 부드럽게 처리된다

사용자 피드백 시스템

토스트 메시지

  • 장바구니 추가 시 성공 메시지가 토스트로 표시된다
  • 장바구니 삭제, 선택 삭제, 전체 삭제 시 알림 메시지가 표시된다
  • 토스트는 3초 후 자동으로 사라진다
  • 토스트에 닫기 버튼이 제공된다
  • 토스트 타입별로 다른 스타일이 적용된다 (success, info, error)

심화과제

SPA 네비게이션 및 URL 관리

페이지 이동

  • 어플리케이션 내의 모든 페이지 이동(뒤로가기/앞으로가기를 포함)은 하여 새로고침이 발생하지 않아야 한다.

상품 목록 - URL 쿼리 반영

  • 검색어가 URL 쿼리 파라미터에 저장된다
  • 카테고리 선택이 URL 쿼리 파라미터에 저장된다
  • 상품 옵션이 URL 쿼리 파라미터에 저장된다
  • 정렬 조건이 URL 쿼리 파라미터에 저장된다
  • 조건 변경 시 URL이 자동으로 업데이트된다
  • URL을 통해 현재 검색/필터 상태를 공유할 수 있다

상품 목록 - 새로고침 시 상태 유지

  • 새로고침 후 URL 쿼리에서 검색어가 복원된다
  • 새로고침 후 URL 쿼리에서 카테고리가 복원된다
  • 새로고침 후 URL 쿼리에서 옵션 설정이 복원된다
  • 새로고침 후 URL 쿼리에서 정렬 조건이 복원된다
  • 복원된 조건에 맞는 상품 데이터가 다시 로드된다

장바구니 - 새로고침 시 데이터 유지

  • 장바구니 내용이 브라우저에 저장된다
  • 새로고침 후에도 이전 장바구니 내용이 유지된다
  • 장바구니의 선택 상태도 함께 유지된다

상품 상세 - URL에 ID 반영

  • 상품 상세 페이지 이동 시 상품 ID가 URL 경로에 포함된다 (/product/{productId})
  • URL로 직접 접근 시 해당 상품의 상세 페이지가 자동으로 로드된다

상품 상세 - 새로고침시 유지

  • 새로고침 후에도 URL의 상품 ID를 읽어서 해당 상품 상세 페이지가 유지된다

404 페이지

  • 존재하지 않는 경로 접근 시 404 에러 페이지가 표시된다
  • 홈으로 돌아가기 버튼이 제공된다

AI로 한 번 더 구현하기

  • 기존에 구현한 기능을 AI로 다시 구현한다.
  • 이 과정에서 직접 가공하는 것은 최대한 지양한다.

과제 셀프회고

기술적 성장

자랑하고 싶은 코드

개선이 필요하다고 생각하는 코드

학습 효과 분석

과제 피드백

AI 활용 경험 공유하기

리뷰 받고 싶은 내용

저두... 코드 피드백 해주세여...

와 배포 어렵다고 해서 배포하려고 올린건데 하다가 앉은채로 기절해버렸어요..;;
그래서 배포는 실패...

https://chb6734.github.io/front_6th_chapter1-1/

@JunilHwang
Copy link
Copy Markdown
Contributor

오~~~

@JunilHwang
Copy link
Copy Markdown
Contributor

conflicts도 해결해주세요 매니저님 ㅋㅋㅋ

@chb6734
Copy link
Copy Markdown
Author

chb6734 commented Jul 12, 2025

conflicts도 해결해주세요 매니저님 ㅋㅋㅋ

엌ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ넴....

@k-sang-soo
Copy link
Copy Markdown

대박 코드 훔치러 와야겠다🤩

@chb6734
Copy link
Copy Markdown
Author

chb6734 commented Jul 12, 2025

대박 코드 훔치러 와야겠다🤩

깔짝한거라 가져가실게 없을텐데 ..헣헣

@chb6734
Copy link
Copy Markdown
Author

chb6734 commented Jul 12, 2025

conflicts도 해결해주세요 매니저님 ㅋㅋㅋ

해결 완료입니다...ㅎ

Copy link
Copy Markdown
Contributor

@JunilHwang JunilHwang left a comment

Choose a reason for hiding this comment

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

매니징도 하면서 과제도 하시다니! 대단쓰...

Comment on lines +7 to +18
jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "18"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

영서님덕분에 github actions로 배포하는게 퍼졌는데요,
저는 꼭 actions로 할 필요가 없다고 생각해서요 ㅋㅋ 팀원들과 협업할게 아니라면..?
"어떻게 배포가 되는건가?" 자체에 대해 고민하는 과정도 필요하다고 생각합니다! 원리 자체랄까..

Comment thread e2e/e2e.spec.js
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

흠.. 원래 원본에 있는 파일인데, 이렇게 추가된게 이상하네요.
컨플릭 해결과정에서 문제가 있었나봐요

Comment thread public/404.html
Comment on lines +20 to +37
<script type="text/javascript">
var pathSegmentsToKeep = 1;
var l = window.location;
l.replace(
l.protocol +
"//" +
l.hostname +
(l.port ? ":" + l.port : "") +
l.pathname
.split("/")
.slice(0, 1 + pathSegmentsToKeep)
.join("/") +
"/?/" +
l.pathname.slice(1).split("/").slice(pathSegmentsToKeep).join("/").replace(/&/g, "~and~") +
(l.search ? "&" + l.search.slice(1).replace(/&/g, "~and~") : "") +
l.hash,
);
</script>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

이 코드 없어도 정상 동작 할 것 같아요 ㅋㅋ

Comment on lines +4 to +9
categories = {},
currentCategory1 = "",
currentCategory2 = "",
currentLimit = 20,
currentSort = "price_asc",
currentSearch = "",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

current를 꼭 붙였어야할까요!?
없어도 무방해보여요~

Comment on lines +12 to +28
const breadcrumbItems = [];
breadcrumbItems.push(
`<button data-breadcrumb="reset" class="text-xs hover:text-blue-800 hover:underline">전체</button>`,
);
if (currentCategory1) {
breadcrumbItems.push(`<span class="text-xs text-gray-500">&gt;</span>`);
breadcrumbItems.push(
`<button data-breadcrumb="category1" data-category1="${currentCategory1}" class="text-xs hover:text-blue-800 hover:underline">${currentCategory1}</button>`,
);
}
if (currentCategory2) {
breadcrumbItems.push(`<span class="text-xs text-gray-500">&gt;</span>`);
breadcrumbItems.push(
`<button data-breadcrumb="category2" data-category1="${currentCategory1}" data-category2="${currentCategory2}" class="text-xs hover:text-blue-800 hover:underline">${currentCategory2}</button>`,
);
}
const breadcrumbHtml = breadcrumbItems.join("");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
const breadcrumbItems = [];
breadcrumbItems.push(
`<button data-breadcrumb="reset" class="text-xs hover:text-blue-800 hover:underline">전체</button>`,
);
if (currentCategory1) {
breadcrumbItems.push(`<span class="text-xs text-gray-500">&gt;</span>`);
breadcrumbItems.push(
`<button data-breadcrumb="category1" data-category1="${currentCategory1}" class="text-xs hover:text-blue-800 hover:underline">${currentCategory1}</button>`,
);
}
if (currentCategory2) {
breadcrumbItems.push(`<span class="text-xs text-gray-500">&gt;</span>`);
breadcrumbItems.push(
`<button data-breadcrumb="category2" data-category1="${currentCategory1}" data-category2="${currentCategory2}" class="text-xs hover:text-blue-800 hover:underline">${currentCategory2}</button>`,
);
}
const breadcrumbHtml = breadcrumbItems.join("");
const breadcrumbItems = [];
breadcrumbItems.push(
`<button data-breadcrumb="reset" class="text-xs hover:text-blue-800 hover:underline">전체</button>`,
);
if (currentCategory1) {
breadcrumbItems.push(...[
`<span class="text-xs text-gray-500">&gt;</span>`,
`<button data-breadcrumb="category1" data-category1="${currentCategory1}" class="text-xs hover:text-blue-800 hover:underline">${currentCategory1}</button>`
]);
}
if (currentCategory2) {
breadcrumbItems.push(...[
`<span class="text-xs text-gray-500">&gt;</span>`,
`<button data-breadcrumb="category2" data-category1="${currentCategory1}" data-category2="${currentCategory2}" class="text-xs hover:text-blue-800 hover:underline">${currentCategory2}</button>`
]);
}
const breadcrumbHtml = breadcrumbItems.join("");

이렇게 표현할 수도 있답니다 ㅎㅎ

Comment on lines +91 to +98
id: "limit-select",
label: "개수",
options: [
{ value: "10", label: "10개" },
{ value: "20", label: "20개" },
{ value: "50", label: "50개" },
{ value: "100", label: "100개" },
],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

이렇게만 상수로 분리해도 좋을 것 같아요!

Comment on lines +102 to +110
id: "sort-select",
label: "정렬",
options: [
{ value: "price_asc", label: "가격 낮은순" },
{ value: "popularity", label: "인기순" },
{ value: "price_desc", label: "가격 높은순" },
{ value: "name_asc", label: "이름순" },
{ value: "name_desc", label: "이름 역순" },
],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

앞선 리뷰와 동일합니다!

Comment thread src/utils/cart.js
Comment on lines +3 to +101
export const cartManager = {
getCart() {
return JSON.parse(storage.getItem("shopping_cart") || "[]");
},

addToCart(product, cnt = 1) {
const cart = this.getCart();
const existingItem = cart.find((item) => item.productId === product.productId);
if (existingItem) {
existingItem.quantity += cnt;
} else {
cart.push({ ...product, quantity: cnt, selected: false });
}

storage.setItem("shopping_cart", JSON.stringify(cart));
this.updateCartCount();
},

removeFromCart(productId) {
const cart = this.getCart().filter((item) => item.productId !== productId);
storage.setItem("shopping_cart", JSON.stringify(cart));
this.updateCartCount();
},

increaseQuantity(productId) {
const cart = this.getCart();
const existingItem = cart.find((item) => item.productId === productId);

existingItem.quantity += 1;
storage.setItem("shopping_cart", JSON.stringify(cart));
this.updateCartCount();
},

decreaseQuantity(productId) {
const cart = this.getCart();
const existingItem = cart.find((item) => item.productId === productId);

if (existingItem.quantity === 1) {
this.removeFromCart(productId);
} else {
existingItem.quantity -= 1;
storage.setItem("shopping_cart", JSON.stringify(cart));
this.updateCartCount();
}
},

getSelectedItems() {
const cart = this.getCart();
return cart.filter((item) => item.selected);
},

toggleSelected(productId) {
const cart = this.getCart();

if (productId) {
const targetItem = cart.find((item) => item.productId === productId);
targetItem.selected = !targetItem.selected;
} else {
const isAllSelected = cart.every((item) => item.selected);
cart.forEach((item) => {
item.selected = !isAllSelected;
});
}

storage.setItem("shopping_cart", JSON.stringify(cart));
},

removeSelectedItems() {
const cart = this.getCart();
const updatedCart = cart.filter((item) => !item.selected);
storage.setItem("shopping_cart", JSON.stringify(updatedCart));
this.updateCartCount();
},

resetCart() {
storage.removeItem("shopping_cart");
this.updateCartCount();
},

updateCartCount() {
const cart = this.getCart();
const cartButton = document.querySelector("#cart-icon-btn");
let badge = cartButton.querySelector(".cart-count-badge");

if (cart.length > 0 && cartButton) {
if (!badge) {
badge = document.createElement("span");
badge.className =
"absolute -top-1 -right-1 bg-red-500 text-white text-xs rounded-full h-5 w-5 flex items-center justify-center cart-count-badge";
cartButton.appendChild(badge);
}
badge.textContent = cart.length;
}

if (cart.length === 0) {
badge.remove();
}
},
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

로컬스토리지 사용 부분만 따로 떼어내서 추상화해도 좋을 것 같아요!

Comment thread src/main.js
Comment on lines +20 to +35
let totalCount = 0;
let currentPage = 1;
let currentLimit = 20;
let currentSort = "price_asc";
let hasNext = true;
let allProducts = [];
let categories = {};
let currentCategory1 = "";
let currentCategory2 = "";
let currentSearch = "";

// 다음 페이지 로딩 중복 방지 플래그
let loadingNextPage = false;

// 현재 상세 페이지 상품 저장용 변수
let currentDetailProduct = null;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

네임스페이스로 묶어서 관리해야 덜 헷갈린답니다!

Comment thread src/main.js
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

메인페이지에 거의 모든 로직이 모여있군요.. ㅎㅎ
이쪽 교통정리를 잘 하는게 관건일 것 같아요.

@JunilHwang JunilHwang force-pushed the main branch 2 times, most recently from a90ad7b to d5eb31b Compare September 26, 2025 01:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants