From 60e69ae8b168d2fc3d44b514c84374e725cc1c48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjo=CC=88rn=20Fromme?= Date: Wed, 28 Jul 2021 12:08:11 +0200 Subject: [PATCH] Code cleanup --- .../Assets/js/components/search-bar.js | 39 ++++++++++++------- .../Private/Assets/js/components/search.js | 10 ++++- .../Private/Templates/Search/Searchbar.html | 2 +- .../Private/Templates/Search/Searchbox.html | 16 ++++++-- .../Templates/Search/Searchresult.html | 2 +- 5 files changed, 48 insertions(+), 21 deletions(-) diff --git a/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/components/search-bar.js b/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/components/search-bar.js index dd9e9c98..2542f28b 100644 --- a/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/components/search-bar.js +++ b/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/components/search-bar.js @@ -17,18 +17,16 @@ export default props => ({ dateRangeLabel: null, init() { this.$watch('dateRangeSelected', () => { - let dateRangeLabel = '' if (null === this.dateRangeSelected.from && null === this.dateRangeSelected.to) { this.searchParams.dateFrom = null this.searchParams.dateTo = null } else { let dateFrom = this.dateRangeSelected.from let dateTo = this.dateRangeSelected.to - dateRangeLabel = `${flatpickr.formatDate(dateFrom, 'd.m.Y')} - ${flatpickr.formatDate(dateTo, 'd.m.Y')}` this.searchParams.dateFrom = flatpickr.formatDate(dateFrom, 'Y-m-d') this.searchParams.dateTo = flatpickr.formatDate(dateTo, 'Y-m-d') } - this.dateRangeLabel = dateRangeLabel + this.updateDateRangeLabel() this.load() }) }, @@ -48,20 +46,28 @@ export default props => ({ applyOptions(json) { this.filterOptions.totalResults = json.totalResults const filterOptions = json.filterOptions - this.filterOptions.priceRanges = filterOptions.priceRanges - this.filterOptions.pax = filterOptions.pax - this.filterOptions.destinations = filterOptions.destinations + this.filterOptions = { + ...this.filterOptions, + totalResults: json.totalResults, + priceRanges: filterOptions.priceRanges, + pax: filterOptions.pax, + destinations: filterOptions.destinations + } if (filterOptions.dateFrom !== null) { this.filterOptions.selectableRangeFrom = filterOptions.dateFrom - this.picker.set('minDate', new Date(filterOptions.dateFrom)) + if (this.picker !== null) { + this.picker.set('minDate', new Date(filterOptions.dateFrom)) + } } if (filterOptions.dateTo !== null) { this.filterOptions.selectableRangeTo = filterOptions.dateTo - this.picker.set('maxDate', new Date(filterOptions.dateTo)) + if (this.picker !== null) { + this.picker.set('maxDate', new Date(filterOptions.dateTo)) + } } }, updateSearchParam(param, value) { - this.searchParams[param] = value + this.searchParams = {...this.searchParams, [param]: value} this.load() }, selectDateRangePreset(preset) { @@ -79,16 +85,14 @@ export default props => ({ this.destinationName = name this.destinationSelected = type !== 'concept' this.conceptSelected = type === 'concept' - this.searchParams.destinationUid = uid - this.searchParams.destinationType = type + this.searchParams = {...this.searchParams, destinationUid: uid, destinationType: type} this.load() }, resetDestination() { this.destinationName = 'beliebig' this.destinationSelected = false this.conceptSelected = false - this.searchParams.destinationUid = null - this.searchParams.destinationType = null + this.searchParams = {...this.searchParams, destinationUid: null, destinationType: null} this.load() }, initDatePicker() { @@ -126,4 +130,13 @@ export default props => ({ } return min + ' - ' + max + ' €' }, + updateDateRangeLabel() { + let dateRangeLabel = '' + if (null !== this.dateRangeSelected.from && null !== this.dateRangeSelected.to) { + let dateFrom = this.dateRangeSelected.from + let dateTo = this.dateRangeSelected.to + dateRangeLabel = `${flatpickr.formatDate(dateFrom, 'd.m.Y')} - ${flatpickr.formatDate(dateTo, 'd.m.Y')}` + } + this.dateRangeLabel = dateRangeLabel + }, }) diff --git a/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/components/search.js b/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/components/search.js index 9411ef31..f12d2ce6 100644 --- a/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/components/search.js +++ b/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/components/search.js @@ -16,13 +16,15 @@ export default props => ({ dateRangeLabel: null, contentWrapper: null, init() { + this.$watch('dateRangeSelected', () => { + this.updateDateRangeLabel() + }) this.contentWrapper = this.$refs.container this.updateFilterCount() this.load() }, refresh() { this.updateFilterCount() - this.updateDateRangeLabel() this.load() }, load() { @@ -39,7 +41,6 @@ export default props => ({ if (null !== this.filterSettings.dateFrom && null !== this.filterSettings.dateTo) { this.picker.setDate([ this.filterSettings.dateFrom, this.filterSettings.dateTo ]) this.dateRangeSelected = { from: new Date(this.filterSettings.dateFrom), to: new Date(this.filterSettings.dateTo) } - this.updateDateRangeLabel() } this.$el.scrollIntoView({behavior: 'smooth'}) }) @@ -65,6 +66,7 @@ export default props => ({ dateTo: flatpickr.formatDate(selectedDates[1], 'Y-m-d'), }) this.show = null + this.refresh() } } }) @@ -83,6 +85,7 @@ export default props => ({ dateTo: flatpickr.formatDate(dateTo, 'Y-m-d'), }) this.show = null + this.refresh() }, resetDateRange() { this.dateRangeSelected = { from: null, to: null } @@ -90,7 +93,10 @@ export default props => ({ dateFrom: null, dateTo: null, }) + this.picker.clear() + this.picker.jumpToDate() this.show = null + this.refresh() }, updateDateRangeLabel() { let dateRangeLabel = '' diff --git a/public/typo3conf/ext/ep_theme/Resources/Private/Templates/Search/Searchbar.html b/public/typo3conf/ext/ep_theme/Resources/Private/Templates/Search/Searchbar.html index fb470648..e96513b1 100644 --- a/public/typo3conf/ext/ep_theme/Resources/Private/Templates/Search/Searchbar.html +++ b/public/typo3conf/ext/ep_theme/Resources/Private/Templates/Search/Searchbar.html @@ -155,7 +155,7 @@
diff --git a/public/typo3conf/ext/ep_theme/Resources/Private/Templates/Search/Searchresult.html b/public/typo3conf/ext/ep_theme/Resources/Private/Templates/Search/Searchresult.html index 47a6680d..f964907c 100644 --- a/public/typo3conf/ext/ep_theme/Resources/Private/Templates/Search/Searchresult.html +++ b/public/typo3conf/ext/ep_theme/Resources/Private/Templates/Search/Searchresult.html @@ -22,7 +22,7 @@ })'>
-
+
Suchergebnis wird geladen...