This commit is contained in:
2025-08-07 16:57:51 -05:00
parent 4efa6c9d77
commit 4dcff1d883
12 changed files with 158 additions and 161 deletions

View File

@@ -5,7 +5,7 @@ import { ActivatedRoute, Router, RouterModule } from '@angular/router';
import { NgSelectModule } from '@ng-select/ng-select';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { initFlowbite } from 'flowbite';
import { catchError, concat, debounceTime, distinctUntilChanged, lastValueFrom, Observable, of, Subject, Subscription, switchMap, tap } from 'rxjs';
import { catchError, concat, debounceTime, distinctUntilChanged, Observable, of, Subject, Subscription, switchMap, tap } from 'rxjs';
import { BusinessListingCriteria, CityAndStateResult, CommercialPropertyListingCriteria, GeoResult, KeycloakUser, UserListingCriteria } from '../../../../../bizmatch-server/src/models/main.model';
import { ModalService } from '../../components/search-modal/modal.service';
import { TooltipComponent } from '../../components/tooltip/tooltip.component';
@@ -18,7 +18,6 @@ import { SearchService } from '../../services/search.service';
import { SelectOptionsService } from '../../services/select-options.service';
import { UserService } from '../../services/user.service';
import {
assignProperties,
compareObjects,
createEmptyBusinessListingCriteria,
createEmptyCommercialPropertyListingCriteria,
@@ -26,6 +25,7 @@ import {
createEnhancedProxy,
getCriteriaStateObject,
map2User,
removeSortByStorage,
} from '../../utils/utils';
@UntilDestroy()
@Component({
@@ -86,12 +86,13 @@ export class HomeComponent {
initFlowbite();
}, 0);
this.numberOfBroker$ = this.userService.getNumberOfBroker(createEmptyUserListingCriteria());
this.numberOfCommercial$ = this.listingService.getNumberOfListings(createEmptyCommercialPropertyListingCriteria(), 'commercialProperty');
this.numberOfCommercial$ = this.listingService.getNumberOfListings('commercialProperty');
const token = await this.authService.getToken();
sessionStorage.removeItem('businessListings');
sessionStorage.removeItem('commercialPropertyListings');
sessionStorage.removeItem('brokerListings');
this.criteria = createEnhancedProxy(getCriteriaStateObject('businessListings'), this);
removeSortByStorage();
this.user = map2User(token);
this.loadCities();
this.setupCriteriaChangeListener();
@@ -201,7 +202,7 @@ export class HomeComponent {
if (this.criteria) {
console.log(`Getting total number of results for ${this.criteria.criteriaType}`);
if (this.criteria.criteriaType === 'businessListings' || this.criteria.criteriaType === 'commercialPropertyListings') {
this.numberOfResults$ = this.listingService.getNumberOfListings(this.criteria, this.criteria.criteriaType === 'businessListings' ? 'business' : 'commercialProperty');
this.numberOfResults$ = this.listingService.getNumberOfListings(this.criteria.criteriaType === 'businessListings' ? 'business' : 'commercialProperty');
} else if (this.criteria.criteriaType === 'brokerListings') {
this.numberOfResults$ = this.userService.getNumberOfBroker(this.criteria);
} else {
@@ -273,41 +274,4 @@ export class HomeComponent {
}, this.pauseTime);
}
}
async generateAiResponse() {
this.loadingAi = true;
this.aiSearchFailed = false;
try {
const result = await this.aiService.generateAiReponse(this.aiSearchText);
let criteria: BusinessListingCriteria | CommercialPropertyListingCriteria | UserListingCriteria | any;
if (result.criteriaType === 'businessListings') {
this.changeTab('business');
criteria = result as BusinessListingCriteria;
} else if (result.criteriaType === 'commercialPropertyListings') {
this.changeTab('commercialProperty');
criteria = result as CommercialPropertyListingCriteria;
} else {
this.changeTab('broker');
criteria = result as UserListingCriteria;
}
const city = criteria.city as string;
if (city && city.length > 0) {
let results = await lastValueFrom(this.geoService.findCitiesStartingWith(city, criteria.state));
if (results.length > 0) {
criteria.city = results[0];
} else {
criteria.city = null;
}
}
if (criteria.radius && criteria.radius.length > 0) {
criteria.radius = parseInt(criteria.radius);
}
this.loadingAi = false;
this.criteria = assignProperties(this.criteria, criteria);
this.search();
} catch (error) {
console.log(error);
this.aiSearchFailed = true;
this.loadingAi = false;
}
}
}

View File

@@ -3,7 +3,7 @@ import { ChangeDetectorRef, Component } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { ActivatedRoute, Router, RouterModule } from '@angular/router';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { BusinessListing, User } from '../../../../../../bizmatch-server/src/models/db.model';
import { BusinessListing, SortByOptions, User } from '../../../../../../bizmatch-server/src/models/db.model';
import { LISTINGS_PER_PAGE, ListingType, UserListingCriteria, emailToDirName } from '../../../../../../bizmatch-server/src/models/main.model';
import { environment } from '../../../../environments/environment';
import { CustomerSubTypeComponent } from '../../../components/customer-sub-type/customer-sub-type.component';
@@ -45,6 +45,7 @@ export class BrokerListingsComponent {
emailToDirName = emailToDirName;
page = 1;
pageCount = 1;
sortBy: SortByOptions = null; // Neu: Separate Property
constructor(
public selectOptions: SelectOptionsService,
private listingsService: ListingsService,
@@ -60,13 +61,19 @@ export class BrokerListingsComponent {
) {
this.criteria = getCriteriaProxy('brokerListings', this) as UserListingCriteria;
this.init();
this.searchService.currentCriteria.pipe(untilDestroyed(this)).subscribe(criteria => {
if (criteria && criteria.criteriaType === 'brokerListings') {
this.loadSortBy();
this.searchService.currentCriteria.pipe(untilDestroyed(this)).subscribe(({ criteria, sortBy }) => {
if (criteria.criteriaType === 'brokerListings') {
this.criteria = criteria as UserListingCriteria;
this.sortBy = sortBy || this.sortBy || null;
this.search();
}
});
}
private loadSortBy() {
const storedSortBy = sessionStorage.getItem('professionalsSortBy');
this.sortBy = storedSortBy && storedSortBy !== 'null' ? (storedSortBy as SortByOptions) : null;
}
async ngOnInit() {}
async init() {
this.search();
@@ -101,14 +108,14 @@ export class BrokerListingsComponent {
this.criteriaChangeService.notifyCriteriaChange();
// Search with cleared filters
this.searchService.search(this.criteria);
this.searchService.search('brokerListings');
}
async openFilterModal() {
// Open the search modal with current criteria
const modalResult = await this.modalService.showModal(this.criteria);
if (modalResult.accepted) {
this.searchService.search(this.criteria);
this.searchService.search('brokerListings');
} else {
this.criteria = assignProperties(this.criteria, modalResult.criteria);
}

View File

@@ -4,7 +4,7 @@ import { FormsModule } from '@angular/forms';
import { ActivatedRoute, Router, RouterModule } from '@angular/router';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import dayjs from 'dayjs';
import { BusinessListing } from '../../../../../../bizmatch-server/src/models/db.model';
import { BusinessListing, SortByOptions } from '../../../../../../bizmatch-server/src/models/db.model';
import { BusinessListingCriteria, LISTINGS_PER_PAGE, ListingType, emailToDirName } from '../../../../../../bizmatch-server/src/models/main.model';
import { environment } from '../../../../environments/environment';
import { PaginatorComponent } from '../../../components/paginator/paginator.component';
@@ -43,6 +43,7 @@ export class BusinessListingsComponent {
page = 1;
pageCount = 1;
emailToDirName = emailToDirName;
sortBy: SortByOptions = null; // Neu: Separate Property
constructor(
public selectOptions: SelectOptionsService,
private listingsService: ListingsService,
@@ -58,13 +59,19 @@ export class BusinessListingsComponent {
this.criteria = getCriteriaProxy('businessListings', this) as BusinessListingCriteria;
this.modalService.sendCriteria(this.criteria);
this.init();
this.searchService.currentCriteria.pipe(untilDestroyed(this)).subscribe(criteria => {
if (criteria && criteria.criteriaType === 'businessListings') {
this.loadSortBy();
this.searchService.currentCriteria.pipe(untilDestroyed(this)).subscribe(({ criteria, sortBy }) => {
if (criteria.criteriaType === 'businessListings') {
this.criteria = criteria as BusinessListingCriteria;
this.sortBy = sortBy || this.sortBy || null;
this.search();
}
});
}
private loadSortBy() {
const storedSortBy = sessionStorage.getItem('businessSortBy');
this.sortBy = storedSortBy && storedSortBy !== 'null' ? (storedSortBy as SortByOptions) : null;
}
async ngOnInit() {
this.search();
}
@@ -73,7 +80,7 @@ export class BusinessListingsComponent {
}
async search() {
const listingReponse = await this.listingsService.getListings(this.criteria, 'business');
const listingReponse = await this.listingsService.getListings('business');
this.listings = listingReponse.results;
this.totalRecords = listingReponse.totalCount;
this.pageCount = this.totalRecords % LISTINGS_PER_PAGE === 0 ? this.totalRecords / LISTINGS_PER_PAGE : Math.floor(this.totalRecords / LISTINGS_PER_PAGE) + 1;
@@ -106,7 +113,7 @@ export class BusinessListingsComponent {
this.criteriaChangeService.notifyCriteriaChange();
// Search with cleared filters
this.searchService.search(this.criteria);
this.searchService.search('businessListings');
}
async openFilterModal() {
@@ -114,7 +121,7 @@ export class BusinessListingsComponent {
const modalResult = await this.modalService.showModal(this.criteria);
if (modalResult.accepted) {
this.criteria = assignProperties(this.criteria, modalResult.criteria); // Update criteria with modal result
this.searchService.search(this.criteria); // Trigger search with updated criteria
this.searchService.search('businessListings'); // Trigger search with updated criteria
}
}
}

View File

@@ -4,7 +4,7 @@ import { FormsModule } from '@angular/forms';
import { ActivatedRoute, Router, RouterModule } from '@angular/router';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import dayjs from 'dayjs';
import { CommercialPropertyListing } from '../../../../../../bizmatch-server/src/models/db.model';
import { CommercialPropertyListing, SortByOptions } from '../../../../../../bizmatch-server/src/models/db.model';
import { CommercialPropertyListingCriteria, LISTINGS_PER_PAGE, ResponseCommercialPropertyListingArray } from '../../../../../../bizmatch-server/src/models/main.model';
import { environment } from '../../../../environments/environment';
import { PaginatorComponent } from '../../../components/paginator/paginator.component';
@@ -43,7 +43,7 @@ export class CommercialPropertyListingsComponent {
page = 1;
pageCount = 1;
ts = new Date().getTime();
sortBy: SortByOptions = null; // Neu: Separate Property
constructor(
public selectOptions: SelectOptionsService,
private listingsService: ListingsService,
@@ -58,23 +58,25 @@ export class CommercialPropertyListingsComponent {
) {
this.criteria = getCriteriaProxy('commercialPropertyListings', this) as CommercialPropertyListingCriteria;
this.modalService.sendCriteria(this.criteria);
this.init();
this.searchService.currentCriteria.pipe(untilDestroyed(this)).subscribe(criteria => {
if (criteria && criteria.criteriaType === 'commercialPropertyListings') {
this.loadSortBy();
this.searchService.currentCriteria.pipe(untilDestroyed(this)).subscribe(({ criteria, sortBy }) => {
if (criteria.criteriaType === 'commercialPropertyListings') {
this.criteria = criteria as CommercialPropertyListingCriteria;
this.sortBy = sortBy || this.sortBy || null;
this.search();
}
});
}
async ngOnInit() {}
async init() {
private loadSortBy() {
const storedSortBy = sessionStorage.getItem('commercialSortBy');
this.sortBy = storedSortBy && storedSortBy !== 'null' ? (storedSortBy as SortByOptions) : null;
}
async ngOnInit() {
this.search();
}
async search() {
const listingReponse = await this.listingsService.getListings(this.criteria, 'commercialProperty');
const listingReponse = await this.listingsService.getListings('commercialProperty');
this.listings = (<ResponseCommercialPropertyListingArray>listingReponse).results;
this.totalRecords = (<ResponseCommercialPropertyListingArray>listingReponse).totalCount;
this.pageCount = this.totalRecords % LISTINGS_PER_PAGE === 0 ? this.totalRecords / LISTINGS_PER_PAGE : Math.floor(this.totalRecords / LISTINGS_PER_PAGE) + 1;
@@ -114,14 +116,14 @@ export class CommercialPropertyListingsComponent {
this.criteriaChangeService.notifyCriteriaChange();
// Search with cleared filters
this.searchService.search(this.criteria);
this.searchService.search('commercialPropertyListings');
}
async openFilterModal() {
const modalResult = await this.modalService.showModal(this.criteria);
if (modalResult.accepted) {
this.criteria = assignProperties(this.criteria, modalResult.criteria); // Update criteria with modal result
this.searchService.search(this.criteria); // Trigger search with updated criteria
this.searchService.search('commercialPropertyListings'); // Trigger search with updated criteria
}
}
}