sr-npm 1.7.66 → 1.7.68

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