diff --git a/client/src/local-businesses/local-business-item.js b/client/src/local-businesses/local-business-item.js index 03ec0a4..ec26ae1 100644 --- a/client/src/local-businesses/local-business-item.js +++ b/client/src/local-businesses/local-business-item.js @@ -63,14 +63,6 @@ customElements.define('local-business-item', class extends Component { `); } - connectedCallback() { - super.connectedCallback(); - } - - attributeChangedCallback(name, oldV, newV) { - super.attributeChangedCallback(name, oldV, newV); - } - get price() { const n = parseInt(this.getAttribute('price')); return isNaN(n) ? 0 : n; @@ -103,4 +95,8 @@ customElements.define('local-business-item', class extends Component { const el = this.shadowRoot.querySelector('#img'); el.src = v; } + + matches(text) { + return !!this.name.match(text) + } }); diff --git a/client/src/local-businesses/local-business.js b/client/src/local-businesses/local-business.js index b262619..6f28149 100644 --- a/client/src/local-businesses/local-business.js +++ b/client/src/local-businesses/local-business.js @@ -60,4 +60,14 @@ customElements.define('local-business', class extends Component { set service_id(v) { this.setAttribute('service-id', v); } + + get description() { + return Array.from(this.querySelectorAll('[slot=description]')).map(el => el.textContent); + } + + matches(regex) { + return this.name.match(regex) || + this.description.any(s => s.match(regex)) || + Array.from(this.querySelectorAll('local-business-item')).any(el => el.matches(regex)); + } }); diff --git a/client/src/local-businesses/local-businesses.js b/client/src/local-businesses/local-businesses.js index 200b139..8403b49 100644 --- a/client/src/local-businesses/local-businesses.js +++ b/client/src/local-businesses/local-businesses.js @@ -38,7 +38,7 @@ customElements.define('local-business-list', class extends Component {
- +
@@ -86,8 +86,7 @@ customElements.define('local-business-list', class extends Component { } else { this.setAttribute('filter', value); for (const el of this.querySelectorAll('local-business')) { - if (!el.name) continue; - if (el.name.includes(value)) { + if (el.matches(new RegExp(value))) { el.setAttribute('local-business-visible', 'visible'); } else { el.setAttribute('local-business-visible', 'invisible'); diff --git a/client/src/marketplace/marketplace-offer.js b/client/src/marketplace/marketplace-offer.js index d0d4fe9..001078a 100644 --- a/client/src/marketplace/marketplace-offer.js +++ b/client/src/marketplace/marketplace-offer.js @@ -232,4 +232,8 @@ customElements.define('marketplace-offer', class extends Component { } return ''; } + + matches(regex) { + return !!this.description.match(regex) + } }); diff --git a/client/src/poly.js b/client/src/poly.js index a8da5e5..65868ff 100644 --- a/client/src/poly.js +++ b/client/src/poly.js @@ -15,8 +15,32 @@ Object.defineProperties(Object.prototype, { }) Object.defineProperties(Array.prototype, { - 'last': { get() { return this[this.length - 1] } }, - 'tail': { get() { return this[this.length - 1] } }, - 'first': { get() { return this[0] } }, - 'head': { get() { return this[0] } }, + 'last': { + get() { + return this[this.length - 1] + } + }, + 'tail': { + get() { + return this[this.length - 1] + } + }, + 'first': { + get() { + return this[0] + } + }, + 'head': { + get() { + return this[0] + } + }, + 'any': { + value(cb) { + for (const el of this) { + if (cb(el)) return true; + } + return false; + } + } })