From 3f8e19d0b61012e6c33bb593626c274de399f9f4 Mon Sep 17 00:00:00 2001 From: zino Date: Sat, 15 May 2021 23:50:04 +0200 Subject: [PATCH] before reduce optimization --- client/src/modules/cart.ts | 62 +++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/client/src/modules/cart.ts b/client/src/modules/cart.ts index 0f21f83..d177d1a 100644 --- a/client/src/modules/cart.ts +++ b/client/src/modules/cart.ts @@ -4,26 +4,29 @@ import * as I from "../types/types"; import * as UI from "./ui"; import * as Events from "./events"; -export function addItem(inSeatObj: I.JSCSelectedSeat) { - const color = `#${XMLHelper.getVenuePricescalePropertyByPricescaleID("color", inSeatObj.data.seatsObj.id[0])}`; - const category = XMLHelper.getVenuePricescalePropertyByPricescaleID("desc", inSeatObj.data.seatsObj.id[0]); - const seat = config.state.layoutRows[inSeatObj.id][5]; - const row = config.state.layoutRows[inSeatObj.id][4]; - const sectionID = config.state.layoutRows[inSeatObj.id][3]; - const sectionDesc = XMLHelper.getSectionDescBySectionID(sectionID); - const seatStr = `${sectionDesc}
Reihe ${row} Platz ${seat}`; - const buyerTypes: (string | undefined)[][] | undefined = getBuyerTypesByPricescaleID(inSeatObj.data.seatsObj.id[0]); - const cartId = `cartItem-${inSeatObj.id}`; - const dropdownBuyerTypesSelector = `#${cartId} .dropdownBuyerTypes`; +type buyerType = (string | undefined)[][] | undefined; +type buyerTypeArr = (string | undefined)[]; - appendHTML(cartId, color, category, seatStr); - addDropdownBuyerTypesOptions(buyerTypes, dropdownBuyerTypesSelector); +export function addItem(inSeatObj: I.JSCSelectedSeat): void { + const color: string = `#${XMLHelper.getVenuePricescalePropertyByPricescaleID("color", inSeatObj.data.seatsObj.id[0])}`; + const category: string | undefined = XMLHelper.getVenuePricescalePropertyByPricescaleID("desc", inSeatObj.data.seatsObj.id[0]); + const seat: string = config.state.layoutRows[inSeatObj.id][5]; + const row: string = config.state.layoutRows[inSeatObj.id][4]; + const sectionID: string = config.state.layoutRows[inSeatObj.id][3]; + const sectionDesc: string | undefined = XMLHelper.getSectionDescBySectionID(sectionID); + const seatStr: string | undefined = `${sectionDesc}
Reihe ${row} Platz ${seat}`; + const buyerTypes: buyerType = getBuyerTypesByPricescaleID(inSeatObj.data.seatsObj.id[0]); + const cartID: string = `cartItem-${inSeatObj.id}`; + const dropdownBuyerTypesSelector: string = `#${cartID} .dropdownBuyerTypes`; + + appendHTML(cartID, color, category, seatStr); + addDropdownBuyerTypeOptions(buyerTypes, dropdownBuyerTypesSelector); Events.addCartDropdownBuyerTypes(dropdownBuyerTypesSelector, inSeatObj); } -function appendHTML(inCartId: string, inColor: string, inCategory: string | undefined, inSeatStr: string) { +function appendHTML(inCartID: string, inColor: string, inCategory: string | undefined, inSeatStr: string): void { jQuery("#cartItemHTML .fl-html").append(` -
+
${inCategory}
${inSeatStr}
@@ -32,26 +35,29 @@ function appendHTML(inCartId: string, inColor: string, inCategory: string | unde } // todo: generalize dropdown fill options -function addDropdownBuyerTypesOptions(inBuyerTypes: (string | undefined)[][] | undefined, inSelector: string) { +function addDropdownBuyerTypeOptions(inBuyerTypes: buyerType, inSelector: string) { if (!inBuyerTypes) return; - const dropdownBuyerTypes = jQuery(inSelector).get(0); + const dropdownBuyerTypes: HTMLElement = jQuery(inSelector).get(0); - inBuyerTypes.forEach(arr => { - if (!arr[0]) - return; - - let opt = document.createElement('option'); - opt.value = arr[0]; - opt.innerHTML = `${arr[2]} €${arr[1]}`; - dropdownBuyerTypes.appendChild(opt); + inBuyerTypes.forEach(arr => { + if (arr[0]) + appendOption(dropdownBuyerTypes, arr) }); } +function appendOption(inDropdownBuyerTypes: HTMLElement, inArr: buyerTypeArr) { + let opt: HTMLOptionElement = document.createElement('option'); + opt.value = inArr[0]; + opt.innerHTML = `${inArr[2]} €${inArr[1]}`; + inDropdownBuyerTypes.appendChild(opt); +} + function getBuyerTypesByPricescaleID(inPricescaleID: string) { - const venueXML = config.state.inVenueXML!; - const venuePricescaleArr = venueXML.price_structure[0].pricescale; + const venueXML: I.VenueXML = config.state.inVenueXML!; + const venuePricescaleArr: I.Pricescale5[] = venueXML.price_structure[0].pricescale; + const buyerTypesArr = venuePricescaleArr.find(obj => { return obj.id[0] === inPricescaleID; })?.buyer_type; @@ -59,7 +65,7 @@ function getBuyerTypesByPricescaleID(inPricescaleID: string) { if (!buyerTypesArr) return; - const buyerTypes: (string | undefined)[][] = buyerTypesArr.map(arr => { + const buyerTypes: buyerType = buyerTypesArr.map(arr => { const buyerTypeDesc = venueXML.venue[0].buyer_types[0].buyer_type.find(obj => { return obj.id[0] === arr.id[0] ? obj.desc[0] : undefined; })?.desc[0];