abmp-npm 2.0.60 → 2.0.61
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/pages/Home.js +1 -1
- package/pages/personalDetails.js +33 -11
- package/public/Utils/homePage.js +58 -81
package/package.json
CHANGED
package/pages/Home.js
CHANGED
|
@@ -366,7 +366,7 @@ const homePageOnReady = async ({
|
|
|
366
366
|
isSearchingNearby: _$w('#nearBy').checked,
|
|
367
367
|
preservePagination,
|
|
368
368
|
});
|
|
369
|
-
|
|
369
|
+
!preservePagination && (await updateUrlParams(filter, pagination));
|
|
370
370
|
return searchResults;
|
|
371
371
|
}
|
|
372
372
|
|
package/pages/personalDetails.js
CHANGED
|
@@ -2033,14 +2033,29 @@ async function personalDetailsOnReady({
|
|
|
2033
2033
|
});
|
|
2034
2034
|
|
|
2035
2035
|
_$w('#showPhoneCheckbox').onChange(event => {
|
|
2036
|
-
const data = _$w('#phoneNumbersList').data;
|
|
2036
|
+
const data = _$w('#phoneNumbersList').data || [];
|
|
2037
2037
|
const clickedItemData = data.find(item => item._id === event.context.itemId);
|
|
2038
|
-
|
|
2038
|
+
if (!clickedItemData) {
|
|
2039
|
+
return;
|
|
2040
|
+
}
|
|
2039
2041
|
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
+
const isChecked = event.target.checked;
|
|
2043
|
+
let updated;
|
|
2044
|
+
if (isChecked) {
|
|
2045
|
+
updated = data.map(item =>
|
|
2046
|
+
item._id === clickedItemData._id
|
|
2047
|
+
? { ...item, showPhone: true }
|
|
2048
|
+
: { ...item, showPhone: false }
|
|
2049
|
+
);
|
|
2050
|
+
updateShowPhoneSelection(clickedItemData._id, true);
|
|
2051
|
+
} else {
|
|
2052
|
+
updated = data.map(item =>
|
|
2053
|
+
item._id === clickedItemData._id ? { ...item, showPhone: false } : item
|
|
2054
|
+
);
|
|
2055
|
+
updateShowPhoneSelection(clickedItemData._id, false);
|
|
2056
|
+
}
|
|
2042
2057
|
|
|
2043
|
-
|
|
2058
|
+
renderPhonesList(updated);
|
|
2044
2059
|
checkFormChanges(FORM_SECTION_HANDLER_MAP.CONTACT_BOOKING);
|
|
2045
2060
|
});
|
|
2046
2061
|
|
|
@@ -2168,12 +2183,19 @@ async function personalDetailsOnReady({
|
|
|
2168
2183
|
const currentData = _$w('#phoneNumbersList').data || [];
|
|
2169
2184
|
const selectedItem = currentData.find(item => item._id === phoneId);
|
|
2170
2185
|
|
|
2171
|
-
if (selectedItem
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2186
|
+
if (!selectedItem) {
|
|
2187
|
+
return;
|
|
2188
|
+
}
|
|
2189
|
+
|
|
2190
|
+
if (isVisible) {
|
|
2191
|
+
itemMemberObj.toShowPhone = selectedItem.phoneNumber?.trim()
|
|
2192
|
+
? selectedItem.phoneNumber
|
|
2193
|
+
: null;
|
|
2194
|
+
return;
|
|
2195
|
+
}
|
|
2196
|
+
|
|
2197
|
+
if (selectedItem.phoneNumber) {
|
|
2198
|
+
itemMemberObj.toShowPhone = null;
|
|
2177
2199
|
}
|
|
2178
2200
|
}
|
|
2179
2201
|
|
package/public/Utils/homePage.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
const { location: wixLocation, queryParams: wixQueryParams } = require('@wix/site-location');
|
|
2
2
|
const { window: wixWindow, rendering } = require('@wix/site-window');
|
|
3
3
|
|
|
4
|
-
const { DEFAULT_FILTER
|
|
4
|
+
const { DEFAULT_FILTER } = require('../consts.js');
|
|
5
|
+
|
|
6
|
+
const { debouncedFunction } = require('./sharedUtils.js');
|
|
7
|
+
|
|
8
|
+
/** Returned when an in-flight search was superseded; do not apply results to UI */
|
|
9
|
+
const STALE_SEARCH_RESPONSE = Symbol('STALE_SEARCH_RESPONSE');
|
|
5
10
|
|
|
6
11
|
function generateSearchId() {
|
|
7
12
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
|
|
@@ -13,11 +18,23 @@ function generateSearchId() {
|
|
|
13
18
|
|
|
14
19
|
const createHomepageUtils = (_$w, filterProfiles) => {
|
|
15
20
|
let currentSearchId = null;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
|
|
22
|
+
async function fetchProfilesWithSearchId(args) {
|
|
23
|
+
const thisSearchId = generateSearchId();
|
|
24
|
+
currentSearchId = thisSearchId;
|
|
25
|
+
try {
|
|
26
|
+
const response = await filterProfiles(args);
|
|
27
|
+
if (thisSearchId !== currentSearchId) {
|
|
28
|
+
return STALE_SEARCH_RESPONSE;
|
|
29
|
+
}
|
|
30
|
+
return response;
|
|
31
|
+
} catch (error) {
|
|
32
|
+
if (thisSearchId !== currentSearchId) {
|
|
33
|
+
return STALE_SEARCH_RESPONSE;
|
|
34
|
+
}
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
21
38
|
|
|
22
39
|
const getFiltersSelectors = filterName => ({
|
|
23
40
|
checkBoxContainerSelector: _$w(`#${filterName}CheckBoxContainer`),
|
|
@@ -668,14 +685,13 @@ const createHomepageUtils = (_$w, filterProfiles) => {
|
|
|
668
685
|
async function search({
|
|
669
686
|
filter,
|
|
670
687
|
pagination,
|
|
671
|
-
debounceTimeout
|
|
688
|
+
debounceTimeout,
|
|
672
689
|
timeoutType,
|
|
673
690
|
isSearchingNearby,
|
|
674
691
|
preservePagination = false,
|
|
675
692
|
}) {
|
|
676
693
|
const multiStateBoxSelector = _$w('#resultsStateBox');
|
|
677
694
|
const renderingEnv = await rendering.env();
|
|
678
|
-
|
|
679
695
|
const initSearchResultsUI = () => {
|
|
680
696
|
JSON.stringify(filter) === JSON.stringify(DEFAULT_FILTER)
|
|
681
697
|
? _$w('#resetFilter').hide()
|
|
@@ -686,115 +702,76 @@ const createHomepageUtils = (_$w, filterProfiles) => {
|
|
|
686
702
|
_$w('#profileRepeater').data = [];
|
|
687
703
|
console.log({ filter });
|
|
688
704
|
};
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
filterToUse,
|
|
692
|
-
isSearchingNearbyToUse,
|
|
693
|
-
preservePaginationToUse
|
|
694
|
-
) => {
|
|
695
|
-
if (!isSearchingNearbyToUse) {
|
|
705
|
+
const runSearchAndUpdateUI = async (filter, isSearchingNearby) => {
|
|
706
|
+
if (!isSearchingNearby) {
|
|
696
707
|
if (
|
|
697
708
|
JSON.stringify({
|
|
698
|
-
...
|
|
709
|
+
...filter,
|
|
699
710
|
latitude: 0,
|
|
700
711
|
longitude: 0,
|
|
701
712
|
}) === JSON.stringify(DEFAULT_FILTER)
|
|
702
713
|
) {
|
|
703
714
|
multiStateBoxSelector.changeState('noSearchCriteria');
|
|
704
|
-
await updateUrlParams(filterToUse, pagination);
|
|
705
715
|
return [];
|
|
706
716
|
}
|
|
707
717
|
}
|
|
708
|
-
const
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
718
|
+
const nonDebouncedFilterProfiles = async () => {
|
|
719
|
+
try {
|
|
720
|
+
const result = await fetchProfilesWithSearchId({ filter, isSearchingNearby });
|
|
721
|
+
if (result === STALE_SEARCH_RESPONSE) {
|
|
722
|
+
return { success: true, response: STALE_SEARCH_RESPONSE };
|
|
723
|
+
}
|
|
724
|
+
return { success: true, response: result };
|
|
725
|
+
} catch (error) {
|
|
726
|
+
return { success: false, error };
|
|
727
|
+
}
|
|
728
|
+
};
|
|
729
|
+
//Don't run setTimeout on SSR
|
|
730
|
+
const funcPromise =
|
|
731
|
+
renderingEnv === 'backend'
|
|
732
|
+
? () => nonDebouncedFilterProfiles()
|
|
733
|
+
: () =>
|
|
734
|
+
debouncedFunction({
|
|
735
|
+
func: fetchProfilesWithSearchId,
|
|
736
|
+
debounceTimeout,
|
|
737
|
+
timeoutType,
|
|
738
|
+
args: { filter, isSearchingNearby },
|
|
739
|
+
});
|
|
740
|
+
const { success, response, error } = await funcPromise();
|
|
741
|
+
if (response === STALE_SEARCH_RESPONSE) {
|
|
742
|
+
return [];
|
|
743
|
+
}
|
|
744
|
+
if (!success) {
|
|
719
745
|
_$w('#numberOfResults').text = '';
|
|
720
746
|
console.error('[search] failed with error:', error);
|
|
721
747
|
multiStateBoxSelector.changeState('errorState');
|
|
722
|
-
await updateUrlParams(filterToUse, pagination);
|
|
723
748
|
return [];
|
|
724
749
|
}
|
|
725
|
-
|
|
726
|
-
if (thisSearchId !== currentSearchId) return [];
|
|
727
|
-
|
|
728
|
-
const response = result;
|
|
729
750
|
const totalCount = response.items.length;
|
|
730
751
|
if (!totalCount) {
|
|
731
752
|
_$w('#numberOfResults').text = 'Showing 0 results';
|
|
732
753
|
_$w('#noResultsMessage').text = `${
|
|
733
|
-
|
|
734
|
-
? `'${
|
|
754
|
+
filter.searchText && filter.searchText.length > 0
|
|
755
|
+
? `'${filter.searchText}' did not match any search. Please try again.`
|
|
735
756
|
: 'No results found for the selected filters. Please adjust your filters and try again'
|
|
736
757
|
}`;
|
|
737
758
|
multiStateBoxSelector.changeState('noResultsState');
|
|
738
|
-
await updateUrlParams(filterToUse, pagination);
|
|
739
759
|
return [];
|
|
740
760
|
}
|
|
741
761
|
console.log({ response });
|
|
742
762
|
handleNumberOfResults(pagination, totalCount);
|
|
743
763
|
_$w('#showingResult').show();
|
|
744
764
|
|
|
745
|
-
if (!
|
|
765
|
+
if (!preservePagination || pagination.currentPage >= pagination.totalPages) {
|
|
746
766
|
pagination.currentPage = 0;
|
|
747
767
|
}
|
|
748
768
|
pagination.totalPages = Math.ceil(totalCount / pagination.pageSize);
|
|
749
769
|
paginateSearchResults(response.items, pagination);
|
|
750
770
|
multiStateBoxSelector.changeState('resultsState');
|
|
751
|
-
await updateUrlParams(filterToUse, pagination);
|
|
752
771
|
return response.items;
|
|
753
772
|
};
|
|
754
|
-
|
|
755
|
-
// Always show loading as soon as user changes input
|
|
756
773
|
initSearchResultsUI();
|
|
757
|
-
|
|
758
|
-
// SSR: run immediately, no debounce
|
|
759
|
-
if (renderingEnv === 'backend') {
|
|
760
|
-
return await runSearchAndUpdateUI(filter, isSearchingNearby, preservePagination);
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
// Client: debounce the API call; loading is already shown above.
|
|
764
|
-
// Snapshot the filter so rapid clicks / URL sync can't mutate it before the debounced run.
|
|
765
|
-
lastSearchFilter = JSON.parse(JSON.stringify(filter));
|
|
766
|
-
lastSearchIsSearchingNearby = isSearchingNearby;
|
|
767
|
-
lastSearchPreservePagination = preservePagination;
|
|
768
|
-
|
|
769
|
-
if (pendingSearchResolve) {
|
|
770
|
-
pendingSearchResolve([]);
|
|
771
|
-
pendingSearchResolve = null;
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
if (searchDebounceTimer) {
|
|
775
|
-
clearTimeout(searchDebounceTimer);
|
|
776
|
-
searchDebounceTimer = null;
|
|
777
|
-
}
|
|
778
|
-
|
|
779
|
-
const delay = DEBOUNCE_DELAY[timeoutType] ?? 300;
|
|
780
|
-
return new Promise(resolve => {
|
|
781
|
-
pendingSearchResolve = resolve;
|
|
782
|
-
searchDebounceTimer = setTimeout(async () => {
|
|
783
|
-
searchDebounceTimer = null;
|
|
784
|
-
const filterToUse = lastSearchFilter;
|
|
785
|
-
const isSearchingNearbyToUse = lastSearchIsSearchingNearby;
|
|
786
|
-
const preservePaginationToUse = lastSearchPreservePagination;
|
|
787
|
-
const items = await runSearchAndUpdateUI(
|
|
788
|
-
filterToUse,
|
|
789
|
-
isSearchingNearbyToUse,
|
|
790
|
-
preservePaginationToUse
|
|
791
|
-
);
|
|
792
|
-
if (pendingSearchResolve) {
|
|
793
|
-
pendingSearchResolve(items);
|
|
794
|
-
pendingSearchResolve = null;
|
|
795
|
-
}
|
|
796
|
-
}, delay);
|
|
797
|
-
});
|
|
774
|
+
return await runSearchAndUpdateUI(filter, isSearchingNearby);
|
|
798
775
|
}
|
|
799
776
|
|
|
800
777
|
return {
|