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

[toko] Amazon - Week5 (Pair : litae) #111

Draft
wants to merge 8 commits into
base: litae
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ dist-ssr
*.sw?

# css
*.css
.map
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
href="https://cdn.jsdelivr.net/gh/orioncactus/[email protected]/dist/web/static/pretendard.css"
/>
<link rel="stylesheet" href="./src/style/css/reset.css" />
<link rel="stylesheet" href="./src/style/css/style.css" />
<link rel="stylesheet" href="./src/style/style.css" />
<script defer type="module" src="./src/js/Main.js"></script>
<title>Amazon.com</title>
</head>
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"start": "json-server --watch ./server/db.json --port 3000"
},
"repository": {
"type": "git",
Expand Down
38 changes: 37 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,43 @@

<br>

***
---

## Pair: TOKO

### To Do List

- 검색바 영역

- [ ] 최근 검색어 목록
- [ ] 검색을 하면 db.josn의 history 배열에 추가
- [ ] 가장 최근 검색어가 최상단에 노출되도록
- [ ] 최대 5개의 검색어 노출
- [ ] 이미 검색어 목록에 있는 검색어를 다시 검색할 경우 해당 검색어가 최상단으로 순서 변경
- [ ] 최근 검색어의 오른쪽 삭제 버튼 클릭 시 해당 최근 검색어 삭제
- [ ] 추천 검색어
- [ ] 추천 검색어의 왼쪽 화살표 버튼을 클릭하면 해당 검색어가 검색바의 value 값으로 들어감
- [ ] 자동 완성 기능
- [ ] 검색바에 검색어를 입력하면 자동 완성 검색어 노출

- 사이드바 영역

- [ ] 네비게이션바의 '모두' 버튼을 클릭하면 사이드바가 노출
- [ ] db.josn의 SideBar에서 데이터를 fetch
- [ ] Model에서 카테고리 목록의 상태 관리(더보기 콘텐츠가 열려있는지 여부)
- [ ] View에서 상태에 따른 렌터링
- [ ] Controller에서 이벤트 관리

- 메인 영역

- [ ] 메인 콘텐츠
- [ ] db.josn의 MainContents에서 데이터 fetch
- [ ] View에서 렌더링

- Footer
- [ ] Footer
- [ ] db.josn의 Footer에서 데이터 fetch
- [ ] View에서 렌더링

### 참고

Expand Down
25 changes: 25 additions & 0 deletions server/db.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,31 @@
}
],

"HeroImgs":
{
"slider": [
"./src/asset/images/hero/img1.jpg",
"./src/asset/images/hero/img2.jpg",
"./src/asset/images/hero/img3.jpg",
"./src/asset/images/hero/img4.jpg",
"./src/asset/images/hero/img5.jpg",
"./src/asset/images/hero/img6.jpg"
],
"btn" : [
{
"class": "hero-btn prev",
"id": "hero-prev-btn",
"src": "./src/asset/icons/prev-img.svg"
},
{
"class": "hero-btn next",
"id": "hero-next-btn",
"src": "./src/asset/icons/next-img.svg"
}
]
}
,

"MainContents": [
{
"type": "login",
Expand Down
2 changes: 1 addition & 1 deletion src/js/Controller/ExtendedLoginModalController.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { $ } from '../Utils.js';
import { $ } from '../utils.js';

export class ExtendedLoginModalController {
constructor(model, view) {
Expand Down
68 changes: 68 additions & 0 deletions src/js/Controller/HeroSectionController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { HeroSliderView } from '../View/Hero/HeroSliderView.js';
import { HeroBtnView } from '../View/Hero/HeroBtnView.js';
import { $ } from '../utils.js';

export class HeroSectionController {
constructor(model, view) {
this.model = model;
this.view = view;

this.setEvent();
this.initHeroSlider();
}

async initHeroSlider() {
new HeroSliderView(await this.model.getHeroImg());
new HeroBtnView(await this.model.getHeroImg());
this.cloneSlide();
this.setDefaultStyle();
}

setEvent() {
$('.hero-section').addEventListener('click', (event) => {
const target = event.target;
const isPrevBtn = target.classList.contains("prev") || target.id === "hero-prev-btn";
const isNextBtn = target.classList.contains("next") || target.id === "hero-next-btn";

switch (true) {
case isPrevBtn:
this.movePrevSlide();
break;
case isNextBtn:
this.moveNextSlide();
break;
}
});
}

cloneSlide() {
const heroSlider = $('.hero-slider');
const slides = heroSlider.querySelectorAll('li');
const clonedFirstSlide = slides[0].cloneNode(true);
const clonedLastSlide = slides[slides.length - 1].cloneNode(true);
heroSlider.insertBefore(clonedLastSlide, slides[0]);
heroSlider.appendChild(clonedFirstSlide);
}

setDefaultStyle() {
const heroSlider = $('.hero-slider');
heroSlider.style.width = `${this.model.widthOfSlider}px`;
this.model.currentIndex = 1;
this.model.transform -= this.model.widthOfSlide;
heroSlider.style.transform = `translateX(${this.model.transform}px)`;
};

movePrevSlide() {
const heroSlider = $('.hero-slider');
this.model.transform += this.model.widthOfSlide;
this.model.currentIndex -= 1;
heroSlider.style.transform = `translateX(${this.model.transform}px)`;
}

moveNextSlide() {
const heroSlider = $('.hero-slider');
this.model.transform -= this.model.widthOfSlide;
this.model.currentIndex += 1;
heroSlider.style.transform = `translateX(${this.model.transform}px)`;
}
}
2 changes: 1 addition & 1 deletion src/js/Controller/LocationModalController.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { $ } from '../Utils.js';
import { $ } from '../utils.js';

export class LocationModalController {
constructor(model, view) {
Expand Down
2 changes: 1 addition & 1 deletion src/js/Controller/SearchBarController.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { $ } from '../Utils.js';
import { $ } from '../utils.js';
import { HistoryView } from '../View/SearchBar/HistoryView.js';
import { RecommendView } from '../View/SearchBar/RecommendView.js';

Expand Down
6 changes: 6 additions & 0 deletions src/js/Data.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ export class Data {
const data = await response.json();
return data;
}

async getHeroImgs() {
const response = await fetch(this.url + 'HeroImgs');
const data = await response.json();
return data;
}
}
9 changes: 8 additions & 1 deletion src/js/Main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { $ } from './Utils.js';
import { $ } from './utils.js';
import { Data } from './Data.js';
import { App } from './App.js';
import { NavbarMainView } from './View/NavBar/NavbarMain.js';
Expand All @@ -15,6 +15,9 @@ import { ExtendedLoginModalController } from './Controller/ExtendedLoginModalCon
import { LocationModalView } from './View/Modal/LocationModal.js';
import { LocationModalModel } from './Model/LocationModalModel.js';
import { LocationModalController } from './Controller/LocationModalController.js';
import { HeroSectionView } from './View/Hero/HeroSectionView.js';
import { HeroSectionModel } from './Model/HeroSectionModel.js';
import { HeroSectionController } from './Controller/HeroSectionController.js';

class Main {
constructor() {
Expand Down Expand Up @@ -42,6 +45,10 @@ class Main {
this.LocationModal = new LocationModalView($('.nav-main__location'));
this.LocationModalModel = new LocationModalModel();
this.LocationModalController = new LocationModalController(this.LocationModalModel, this.LocationModal);

this.HeroSection = new HeroSectionView($('main'));
this.HeroSectionModel = new HeroSectionModel(this.data.getHeroImgs());
this.HeroSectionController = new HeroSectionController(this.HeroSectionModel, this.HeroSection)
}
}

Expand Down
13 changes: 13 additions & 0 deletions src/js/Model/HeroSectionModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export class HeroSectionModel {
constructor(data) {
this.data = data;
this.widthOfSlide = 1280;
this.transform = 0;
this.currentIndex = 0;
}

async getHeroImg() {
const fetchedData = await this.data;
return fetchedData;
}
}
21 changes: 21 additions & 0 deletions src/js/View/Hero/HeroBtnView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { $ } from '../../utils.js';

export class HeroBtnView {
constructor(data) {
this.data = data;
this.render();
}

getTemplate(heroImgs) {
return heroImgs.btn.map(
btn => `
<button class="${btn.class}"><img id="${btn.id}" src="${btn.src}" alt=""></button>
`
)
.join('');
}

render() {
$('.hero-section').insertAdjacentHTML('beforeend', this.getTemplate(this.data));
}
}
9 changes: 9 additions & 0 deletions src/js/View/Hero/HeroSectionView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Component } from '../../Core/Component.js';

export class HeroSectionView extends Component {
getTemplate() {
return `
<div class="hero-section">
</div>`;
}
}
24 changes: 24 additions & 0 deletions src/js/View/Hero/HeroSliderView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { $ } from '../../utils.js';

export class HeroSliderView {
constructor(data) {
this.data = data;
this.render();
}

getTemplate(heroImgs) {
return `
<ul class="hero-slider">
${heroImgs.slider
.map(
src => `<li><img src="${src}" alt=""></li>`
)
.join('')}
</ul>
`;
}

render() {
$('.hero-section').insertAdjacentHTML('beforeend', this.getTemplate(this.data));
}
}
2 changes: 1 addition & 1 deletion src/js/View/Modal/ExtendedLoginModal.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { $ } from '../../Utils.js';
import { $ } from '../../utils.js';
import { Component } from '../../Core/Component.js';

export class ExtendedLoginModalView extends Component {
Expand Down
2 changes: 1 addition & 1 deletion src/js/View/Modal/LocationModal.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { $ } from '../../Utils.js';
import { $ } from '../../utils.js';
import { Component } from '../../Core/Component.js';

export class LocationModalView extends Component {
Expand Down
2 changes: 1 addition & 1 deletion src/js/View/Modal/LoginModal.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { $ } from '../../Utils.js';
import { $ } from '../../utils.js';
import { Component } from '../../Core/Component.js';

export class LoginModalView extends Component {
Expand Down
4 changes: 2 additions & 2 deletions src/js/View/SearchBar/HistoryView.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { $ } from '../../Utils.js';
import { $ } from '../../utils.js';

export class HistoryView {
constructor(data) {
Expand All @@ -7,7 +7,7 @@ export class HistoryView {
}

getTemplate(history) {
if (history === []) return;
if (history.length > 0) return;
return `
${history
.map(
Expand Down
2 changes: 1 addition & 1 deletion src/js/View/SearchBar/RecommendView.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { $ } from '../../Utils.js';
import { $ } from '../../utils.js';

export class RecommendView {
constructor(data) {
Expand Down
2 changes: 1 addition & 1 deletion src/js/View/SearchBar/SearchBarView.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component } from '../../Core/Component.js';
import { $, addDimmed, removeDimmed, addHiddenClass, removeHiddenClass } from '../../Utils.js';
import { $, addDimmed, removeDimmed, addHiddenClass, removeHiddenClass } from '../../utils.js';

export class SearchBarView extends Component {
getTemplate() {
Expand Down
1 change: 1 addition & 0 deletions src/js/View/Sidebar/SidebarView.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class SidebarView {

render(state) {
const template = this.getTemplate(state);
// @ts-ignore
this.sidebarContents.innerHTML = template;
}

Expand Down
2 changes: 1 addition & 1 deletion src/js/components/NavBar/NavMain/Searchbar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component } from '../../../core/Component.js';
import { Component } from '../../../Core/Component.js';
import { $, addDimmed, addHiddenClass, removeHiddenClass } from '../../../utils.js';

export class Searchbar extends Component {
Expand Down
13 changes: 8 additions & 5 deletions src/style/scss/components/_hero.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

.hero-slider {
display: flex;
transition: 0.5s;
transition: transform 0.5s;
li {
width: 100%;
}
Expand All @@ -26,10 +26,13 @@
border: none;
background: none;
top: 0px;
> img {
width: 24px;
height: 40px;
}
}

.hero-btn:hover {
border-radius: 5px;
border: 1px solid $color-black;
box-shadow: 0 0 0 1px $color-white inset;
cursor: pointer;
}

.prev {
Expand Down