-
Notifications
You must be signed in to change notification settings - Fork 4
cinema - JS version #79
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
Open
krylenger
wants to merge
5
commits into
main
Choose a base branch
from
krylenger/html-movie-seat-booking-js
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
159e2c8
initial commit
krylenger 7f80772
removing assets folder
krylenger 1dffd0c
refractoring render function
krylenger e501967
adding payment confirmation message and resetting the initial app aft…
krylenger 2e47766
setting max width on modal window
krylenger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| const bodyContainer = document.getElementById('body-container'), | ||
| hall = document.getElementById('choose-section__hall'), | ||
| confirmationSection = document.getElementById('choose-section__chosen-tickets'), | ||
| confirmationSectionInnerContainer = document.getElementById('chosen-tickets__inner'), | ||
| ticketsContainer = document.getElementById('chosen-tickets__tickets-container'), | ||
| checkoutButton = document.getElementById('checkout-seats__checkout-button'); | ||
|
|
||
| const postPaymentDelay = 2000; | ||
|
|
||
| const state = { | ||
| chosenSeats: [], | ||
| }; | ||
|
|
||
| const removeSeat = (currentSeat, chosenSeatsArray) => | ||
| (chosenSeatsArray = chosenSeatsArray.filter((seatInArray) => seatInArray !== currentSeat)); | ||
|
|
||
| const addSeat = (seat, chosenSeatsArray) => { | ||
| chosenSeatsArray.push(seat); | ||
| return chosenSeatsArray; | ||
| }; | ||
|
|
||
| const checkIfSeatAlreadyChosen = (seat, chosenSeatsArray) => | ||
| (chosenSeatsArray = chosenSeatsArray.includes(seat) | ||
| ? removeSeat(seat, chosenSeatsArray) | ||
| : addSeat(seat, chosenSeatsArray)); | ||
|
|
||
| const updateChosenSeats = (seat, chosenSeatsArray) => | ||
| (chosenSeatsArray = checkIfSeatAlreadyChosen(seat, chosenSeatsArray)); | ||
|
|
||
| createTicketTemplate = ([row, seat], index) => `<div class="chosen-tickets__ticket"> | ||
| <span class="chosen-tickets__dot"></span> | ||
| <span class="chosen-tickets__span-bold">${++index}.</span> | ||
| <div class="chosen-tickets__row-seat"> | ||
| <span>Row: ${row}</span> | ||
| <span>Seat: ${seat}</span> | ||
| </div> | ||
| <span class="chosen-tickets__span-bold">7$</span> | ||
| </div>`; | ||
|
|
||
| createModalConfirmationTemplate = () => `<section class="choose-section__chosen-tickets choose-section__chosen-tickets--modal chosen-tickets__modal-wrapper" id="choose-section__chosen-tickets"> | ||
| <div class="chosen-tickets chosen-tickets__inner" id="chosen-tickets__inner"> | ||
| <div class="chosen-tickets__header"> | ||
| <span class="chosen-tickets__dot chosen-tickets__dot--main"></span> | ||
| <button class="chosen-tickets__button--go-back" id="chosen-tickets__button--go-back">cancel</button> | ||
| </div> | ||
| <h3 class="choose-section__title">Please double check</h3> | ||
| <div class="chosen-tickets__tickets-container chosen-tickets__tickets-container--modal" id="chosen-tickets__tickets-container--modal"> | ||
| </div> | ||
| <a class="checkout-seats__checkout-button" id="checkout-seats__checkout-button--modal" type="submit"> | ||
| Pay | ||
| </a> | ||
| </div> | ||
| </section>`; | ||
|
|
||
| const createModalConfirmation = (modalConfirmationTemplate) => { | ||
| const modalConfirmation = document.createElement('div'); | ||
| modalConfirmation.setAttribute('id', 'modal-wrapper'); | ||
| modalConfirmation.innerHTML = modalConfirmationTemplate; | ||
| bodyContainer.append(modalConfirmation); | ||
| }; | ||
|
|
||
| const emptyContainer = (container) => { | ||
| container.innerHTML = ''; | ||
| }; | ||
|
|
||
| const convertStringRowSeatToNumberValues = (stringValue) => | ||
| stringValue.split('.').map((stringNumber) => parseInt(stringNumber)); | ||
|
|
||
| const renderSuccessfulPaymentConfirmation = (containerWhereRender, buttonToRenderSuccessfulPayment) => { | ||
| emptyContainer(containerWhereRender); | ||
| containerWhereRender.innerHTML = '√ SUCCESSFUL PAYMENT'; | ||
| buttonToRenderSuccessfulPayment.innerHTML = 'SUCCESSFUL'; | ||
| } | ||
|
|
||
| const renderConfirmationTickets = (chosenSeatsArray, containerWhereRender) => { | ||
| emptyContainer(containerWhereRender); | ||
| chosenSeatsArray.forEach((ticketValue, index) => { | ||
| const rowSeatArray = convertStringRowSeatToNumberValues(ticketValue); | ||
| const newTicket = createTicketTemplate(rowSeatArray, index); | ||
| containerWhereRender.innerHTML += newTicket; | ||
| }); | ||
| }; | ||
|
|
||
| const renderButtonInformation = (chosenSeatsState, button) => { | ||
| let ticketWord = 'tickets'; | ||
| if (chosenSeatsState.length === 1) ticketWord = 'ticket'; | ||
| button.innerHTML = `Buy ${chosenSeatsState.length} ${ticketWord} for $${chosenSeatsState.length * 7}.00`; | ||
| }; | ||
|
|
||
| const render = (chosenSeatsState, containerWhereRenderTickets, buttonToRenderTotalInformation) => { | ||
| renderConfirmationTickets(chosenSeatsState, containerWhereRenderTickets); | ||
| renderButtonInformation(chosenSeatsState, buttonToRenderTotalInformation); | ||
| }; | ||
|
|
||
| const renderModalConfirmation = (template, chosenSeatsState, resetStateFunc) => { | ||
| createModalConfirmation(template); | ||
|
|
||
| const ticketsContainerModal = document.getElementById('chosen-tickets__tickets-container--modal'), | ||
| buttonCloseModalConfirmation = document.getElementById('chosen-tickets__button--go-back'), | ||
| modalWrapper = document.getElementById('modal-wrapper'), | ||
| checkoutButtonModal = document.getElementById('checkout-seats__checkout-button--modal'); | ||
|
|
||
| render(chosenSeatsState, ticketsContainerModal, checkoutButtonModal); | ||
|
|
||
| buttonCloseModalConfirmation.addEventListener('click', () => { | ||
| modalWrapper.remove(); | ||
| }); | ||
| checkoutButtonModal.addEventListener('click', () => { | ||
| renderSuccessfulPaymentConfirmation(ticketsContainerModal, checkoutButtonModal); | ||
| resetStateFunc(); | ||
| setTimeout(() => { | ||
| modalWrapper.remove(); | ||
| }, postPaymentDelay) | ||
| }) | ||
| }; | ||
|
|
||
| const initApp = () => { | ||
| let chosenSeatsState = state.chosenSeats; | ||
|
|
||
| const resetApp = () => { | ||
| const seatsLabels = hall.children; | ||
|
|
||
| for (let seatLabel of seatsLabels) { | ||
| if (seatLabel.firstElementChild.checked) seatLabel.firstElementChild.checked = false; | ||
| } | ||
| chosenSeatsState = []; | ||
| ticketsContainer.innerHTML = ''; | ||
| checkoutButton.innerHTML = 'Buy 0 tickets for $0.00'; | ||
| } | ||
|
|
||
| hall.addEventListener('click', ({ target }) => { | ||
| if (target.name !== 'seat') return; | ||
| chosenSeatsState = updateChosenSeats(target.value, chosenSeatsState); | ||
| render(chosenSeatsState, ticketsContainer, checkoutButton); | ||
| }); | ||
|
|
||
| checkoutButton.addEventListener('click', ({ target }) => { | ||
| if (chosenSeatsState.length) renderModalConfirmation(createModalConfirmationTemplate(), chosenSeatsState, resetApp); | ||
| }); | ||
| }; | ||
|
|
||
| document.addEventListener('DOMContentLoaded', initApp); | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Submit button not working. Please fix it

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've fixed this.
Now it renders the success message, closes modal window after a short delay and resets the initial application.
Could you please check briefly the structure of my app and tell is it proper structured or maybe it should be done in other (more efficient) way.
Thank you in advance!