sr-npm 1.7.66 → 1.7.67
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/homePage.js +108 -0
- package/pages/index.js +1 -0
- package/pages/positionPage.js +3 -2
- package/public/filterUtils.js +36 -0
- package/public/index.js +1 -0
package/package.json
CHANGED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
const {
|
|
2
|
+
debounce,
|
|
3
|
+
getFilter,
|
|
4
|
+
} = require('../public/filterUtils');
|
|
5
|
+
const { location } = require('@wix/site-location');
|
|
6
|
+
|
|
7
|
+
async function homePageOnReady(_$w) {
|
|
8
|
+
console.log('homePageOnReady inisde SR-NPM');
|
|
9
|
+
await bind(_$w);
|
|
10
|
+
await init(_$w);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function bind(_$w) {
|
|
14
|
+
_$w('#teamRepeater').onItemReady(($item, itemData) => {
|
|
15
|
+
$item('#teamButton').label = `View ${itemData.count} Open Positions`;
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
_$w('#citiesDataset').onReady(async () => {
|
|
19
|
+
const numOfItems = await _$w('#citiesDataset').getTotalCount();
|
|
20
|
+
const items = await _$w('#citiesDataset').getItems(0, numOfItems);
|
|
21
|
+
let baseUrl = await location.baseUrl();
|
|
22
|
+
const linkUrl = `${baseUrl}/positions`;
|
|
23
|
+
|
|
24
|
+
const markers = items.items.map(item => {
|
|
25
|
+
const location = item.locationAddress.location;
|
|
26
|
+
return {
|
|
27
|
+
location: {
|
|
28
|
+
latitude: location.latitude,
|
|
29
|
+
longitude: location.longitude
|
|
30
|
+
},
|
|
31
|
+
address: item.locationAddress.formatted,
|
|
32
|
+
description: `<a href=${linkUrl} target="_parent" rel="noopener noreferrer" style="color:#000000;text-decoration:underline;font-weight:bold;">View ${item.count} Open Positions</a>`
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
//@ts-ignore
|
|
36
|
+
_$w('#googleMaps').setMarkers(markers);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function init(_$w) {
|
|
41
|
+
const debouncedInput = debounce(handleSearchInput, 400);
|
|
42
|
+
|
|
43
|
+
_$w('#searchInput').onInput(debouncedInput);
|
|
44
|
+
_$w('#searchInput').maxLength = 40;
|
|
45
|
+
|
|
46
|
+
_$w('#searchInput').onKeyPress((event) => {
|
|
47
|
+
if (event.key === 'Enter') {
|
|
48
|
+
handleEnterPress(_$w('#searchInput').value);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
_$w('#searchInput').onFocus(() => {
|
|
53
|
+
if (_$w(`#resultsContainer`).collapsed) {
|
|
54
|
+
_$w(`#resultsContainer`).expand();
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
_$w('#searchInput').onBlur(() => {
|
|
59
|
+
setTimeout(() => {
|
|
60
|
+
if (!_$w(`#resultsContainer`).collapsed) {
|
|
61
|
+
_$w(`#resultsContainer`).collapse();
|
|
62
|
+
}
|
|
63
|
+
}, 250);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
_$w('#locationItem').onClick((event)=>{
|
|
67
|
+
handleOnLocationClick(event, '#locationsRepeater', '#googleMaps');
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function handleSearchInput(_$w) {
|
|
72
|
+
let searchInput;
|
|
73
|
+
let count;
|
|
74
|
+
|
|
75
|
+
searchInput = _$w('#searchInput').value;
|
|
76
|
+
const trimmedInput = searchInput.trim();
|
|
77
|
+
|
|
78
|
+
const fieldsToSearch = [
|
|
79
|
+
{ field: 'title', searchTerm: trimmedInput },
|
|
80
|
+
{ field: 'cityText', searchTerm: trimmedInput }
|
|
81
|
+
];
|
|
82
|
+
|
|
83
|
+
const filter = await getFilter(fieldsToSearch, 'or');
|
|
84
|
+
|
|
85
|
+
await _$w('#jobsDataset').setFilter(filter);
|
|
86
|
+
await _$w('#jobsDataset').refresh();
|
|
87
|
+
|
|
88
|
+
count = _$w('#jobsDataset').getTotalCount();
|
|
89
|
+
|
|
90
|
+
if (count > 0) {
|
|
91
|
+
_$w('#resultsContainer').expand();
|
|
92
|
+
_$w('#searchMultiStateBox').changeState('results');
|
|
93
|
+
} else {
|
|
94
|
+
_$w('#searchMultiStateBox').changeState('noResults');
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function handleEnterPress(searchInput) {
|
|
99
|
+
const trimmedInput = searchInput.trim();
|
|
100
|
+
|
|
101
|
+
if (trimmedInput) {
|
|
102
|
+
location.to(`/positions?keyWord=${trimmedInput}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
module.exports = {
|
|
107
|
+
homePageOnReady,
|
|
108
|
+
};
|
package/pages/index.js
CHANGED
package/pages/positionPage.js
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const { items:wixData } = require('@wix/data');
|
|
2
|
+
|
|
3
|
+
export function getFilter(fieldsToSearch = [], mode = 'or') {
|
|
4
|
+
const baseFilter = wixData.filter();
|
|
5
|
+
// if no fields to search, return empty filter
|
|
6
|
+
if (fieldsToSearch.length === 0) {
|
|
7
|
+
return baseFilter;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// build filters
|
|
11
|
+
let filter;
|
|
12
|
+
fieldsToSearch.forEach(({ field, searchTerm }) => {
|
|
13
|
+
const condition = typeof searchTerm === 'boolean'
|
|
14
|
+
? baseFilter.eq(field, searchTerm)
|
|
15
|
+
: baseFilter.contains(field, searchTerm);
|
|
16
|
+
|
|
17
|
+
filter = filter
|
|
18
|
+
? (mode === 'or' ? filter.or(condition) : filter.and(condition))
|
|
19
|
+
: condition;
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
return filter;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function debounce(fn, delay = 400) {
|
|
26
|
+
let timeout;
|
|
27
|
+
return function (...args) {
|
|
28
|
+
clearTimeout(timeout);
|
|
29
|
+
timeout = setTimeout(() => fn.apply(this, args), delay);
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = {
|
|
34
|
+
getFilter,
|
|
35
|
+
debounce
|
|
36
|
+
};
|