영화를 클릭하고 좌석을 클릭하면 클릭된 좌석이 표시되고 그와 함께 영화 티켓의 값도 표시된다.
그리고 localStorage를 사용하기 때문에 새로고침해도 정보가 그대로 남아있다.
main.js
App.js
utils
[코드좌표]
- HTML
<div class="movie-container">
<label>Pick a moive:</label>
<select id="movie">
<option value="12">Soul($12)</option>
<option value="10">Avengers: Endgame($10)</option>
<option value="9">Harry Potter: Deathly Hallows($9)</option>
<option value="8">Wallace and Gromit($8)</option>
</select>
</div>
ul과 li를 통해 showcase를 만듬
container를 통해 스크린과 좌석을 만듬
- SCSS
.seat:nth-of-type(2) {
margin-right: 18px;
}
.seat:nth-last-of-type(2) {
margin-left: 18px;
}
.seat:not(.occupied):hover {
cursor: pointer;
transform: scale(1.2);
}
perspective를 통해 3d효과를 줌
positional 인자는(keyword가 없는 그냥 인자. 위치에 따라 영향을 받는 인자) keyword인자보다(위치에 영향을 받지 않는 인자) 앞에 명시되어야 한다.
// 요런식으로 되어야 한다.
@include flex(center, $keyword: something);
- JS
const seats = document.querySelectorAll(".row .seat:not(.occupied)");
container.addEventListener("click", (e) => {
if (
e.target.classList.contains("seat") &&
!e.target.classList.contains("occupied")
) {
e.target.classList.toggle("selected");
updateSelectedCountAndTotal();
}
});
const selectedSeats = document.querySelectorAll(".row .seat.selected");
if (selectedSeats !== null && selectedSeats.length > 0) {
seats.forEach((seat, index) => {
if (selectedSeats.indexOf(index) > -1) {
seat.classList.add("selected");
}
});
}
querySelecterAll은 static NodeList를 반환한다.
요런식으로, 클릭 될때마다 불러와야함. 그래서 dom.js에 넣고 꺼내서 사용하면 null이 나온다.
const onClickSeats = (e = null) => {
const selectedSeat = e.target;
if (
selectedSeat.classList.contains('seat') &&
!selectedSeat.classList.contains('occupied')
) {
selectedSeat.classList.toggle('selected');
const selectedSeats = document.querySelectorAll('.row .seat.selected');
const selectedSeatsIndexArr = [...selectedSeats].map(seat =>
[...allSeats].indexOf(seat)
);
this.setState({ ...this.state, selectedSeatsIndexArr });
}
};
코드를 읽을때 처음 시작하는 순간부터 차근차근 파고들며 읽어나간다. 무작정 보이는대로 읽지 말고.
지극히 작은 것 부터 시작! ex(DUMMY데이터 만들기, console.log로 데이터 보기)
끝!