All filters & debounce
This commit is contained in:
@@ -35,7 +35,7 @@ export class SearchModalComponent {
|
||||
countyInput$ = new Subject<string>();
|
||||
private criteriaChangeSubscription: Subscription;
|
||||
public criteria: BusinessListingCriteria;
|
||||
|
||||
private debounceTimeout: any;
|
||||
public backupCriteria: BusinessListingCriteria | CommercialPropertyListingCriteria | UserListingCriteria = getCriteriaStateObject('businessListings');
|
||||
numberOfResults$: Observable<number>;
|
||||
cancelDisable = false;
|
||||
@@ -49,7 +49,7 @@ export class SearchModalComponent {
|
||||
private searchService: SearchService,
|
||||
) {}
|
||||
// Define property type options
|
||||
propertyTypeOptions = [
|
||||
public propertyTypeOptions = [
|
||||
{ name: 'Real Estate', value: 'realEstateChecked' },
|
||||
{ name: 'Leased Location', value: 'leasedLocation' },
|
||||
{ name: 'Franchise', value: 'franchiseResale' },
|
||||
@@ -78,14 +78,19 @@ export class SearchModalComponent {
|
||||
return !!(
|
||||
this.criteria.state ||
|
||||
this.criteria.city ||
|
||||
(<BusinessListingCriteria>this.criteria).minPrice ||
|
||||
(<BusinessListingCriteria>this.criteria).maxPrice ||
|
||||
(<BusinessListingCriteria>this.criteria).minRevenue ||
|
||||
(<BusinessListingCriteria>this.criteria).maxRevenue ||
|
||||
(<BusinessListingCriteria>this.criteria).minCashFlow ||
|
||||
(<BusinessListingCriteria>this.criteria).maxCashFlow ||
|
||||
this.criteria.minPrice ||
|
||||
this.criteria.maxPrice ||
|
||||
this.criteria.minRevenue ||
|
||||
this.criteria.maxRevenue ||
|
||||
this.criteria.minCashFlow ||
|
||||
this.criteria.maxCashFlow ||
|
||||
this.criteria.types.length ||
|
||||
this.selectedPropertyType
|
||||
this.selectedPropertyType ||
|
||||
this.criteria.minNumberEmployees ||
|
||||
this.criteria.maxNumberEmployees ||
|
||||
this.criteria.establishedSince ||
|
||||
this.criteria.establishedUntil ||
|
||||
this.criteria.brokerName
|
||||
);
|
||||
}
|
||||
removeFilter(filterType: string) {
|
||||
@@ -100,26 +105,37 @@ export class SearchModalComponent {
|
||||
this.criteria.searchType = 'exact';
|
||||
break;
|
||||
case 'price':
|
||||
(<BusinessListingCriteria>this.criteria).minPrice = null;
|
||||
(<BusinessListingCriteria>this.criteria).maxPrice = null;
|
||||
this.criteria.minPrice = null;
|
||||
this.criteria.maxPrice = null;
|
||||
break;
|
||||
case 'revenue':
|
||||
(<BusinessListingCriteria>this.criteria).minRevenue = null;
|
||||
(<BusinessListingCriteria>this.criteria).maxRevenue = null;
|
||||
this.criteria.minRevenue = null;
|
||||
this.criteria.maxRevenue = null;
|
||||
break;
|
||||
case 'cashflow':
|
||||
(<BusinessListingCriteria>this.criteria).minCashFlow = null;
|
||||
(<BusinessListingCriteria>this.criteria).maxCashFlow = null;
|
||||
this.criteria.minCashFlow = null;
|
||||
this.criteria.maxCashFlow = null;
|
||||
break;
|
||||
case 'types':
|
||||
this.criteria.types = [];
|
||||
break;
|
||||
case 'propertyType':
|
||||
(<BusinessListingCriteria>this.criteria).realEstateChecked = false;
|
||||
(<BusinessListingCriteria>this.criteria).leasedLocation = false;
|
||||
(<BusinessListingCriteria>this.criteria).franchiseResale = false;
|
||||
this.criteria.realEstateChecked = false;
|
||||
this.criteria.leasedLocation = false;
|
||||
this.criteria.franchiseResale = false;
|
||||
this.selectedPropertyType = null;
|
||||
break;
|
||||
case 'employees':
|
||||
this.criteria.minNumberEmployees = null;
|
||||
this.criteria.maxNumberEmployees = null;
|
||||
break;
|
||||
case 'established':
|
||||
this.criteria.establishedSince = null;
|
||||
this.criteria.establishedUntil = null;
|
||||
break;
|
||||
case 'brokerName':
|
||||
this.criteria.brokerName = null;
|
||||
break;
|
||||
}
|
||||
this.searchService.search(this.criteria);
|
||||
}
|
||||
@@ -140,7 +156,6 @@ export class SearchModalComponent {
|
||||
this.criteria[value] = true;
|
||||
}
|
||||
this.selectedPropertyType = value;
|
||||
this.updateSelectedPropertyTypeName();
|
||||
this.searchService.search(this.criteria);
|
||||
}
|
||||
|
||||
@@ -150,10 +165,9 @@ export class SearchModalComponent {
|
||||
else if ((<BusinessListingCriteria>this.criteria).leasedLocation) this.selectedPropertyType = 'leasedLocation';
|
||||
else if ((<BusinessListingCriteria>this.criteria).franchiseResale) this.selectedPropertyType = 'franchiseResale';
|
||||
else this.selectedPropertyType = null;
|
||||
this.updateSelectedPropertyTypeName();
|
||||
}
|
||||
updateSelectedPropertyTypeName() {
|
||||
this.selectedPropertyTypeName = this.selectedPropertyType ? this.propertyTypeOptions.find(opt => opt.value === this.selectedPropertyType)?.name : null;
|
||||
getSelectedPropertyTypeName() {
|
||||
return this.selectedPropertyType ? this.propertyTypeOptions.find(opt => opt.value === this.selectedPropertyType)?.name : null;
|
||||
}
|
||||
categoryClicked(checked: boolean, value: string) {
|
||||
if (checked) {
|
||||
@@ -268,4 +282,10 @@ export class SearchModalComponent {
|
||||
this.criteria[checkbox] = value;
|
||||
this.searchService.search(this.criteria);
|
||||
}
|
||||
debouncedSearch() {
|
||||
clearTimeout(this.debounceTimeout);
|
||||
this.debounceTimeout = setTimeout(() => {
|
||||
this.searchService.search(this.criteria);
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user