From f08ae0a1d1b5058fbafa21b9ea53759b19d7d8df Mon Sep 17 00:00:00 2001 From: sofiia koval Date: Wed, 13 Nov 2024 13:06:42 +0200 Subject: [PATCH 1/5] fix: adding link with spaces --- .../edit-profile/edit-profile.component.ts | 28 +++++++++++-------- .../social-networks.component.ts | 4 +-- src/assets/patterns/patterns.ts | 3 +- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/app/main/component/user/components/profile/edit-profile/edit-profile.component.ts b/src/app/main/component/user/components/profile/edit-profile/edit-profile.component.ts index b1d891c3d5..32aa53f251 100644 --- a/src/app/main/component/user/components/profile/edit-profile/edit-profile.component.ts +++ b/src/app/main/component/user/components/profile/edit-profile/edit-profile.component.ts @@ -17,8 +17,8 @@ import { import { EditProfileService } from '@global-user/services/edit-profile.service'; import { TranslateService } from '@ngx-translate/core'; import { FormBaseComponent } from '@shared/components/form-base/form-base.component'; -import { Subscription } from 'rxjs'; -import { filter, take } from 'rxjs/operators'; +import { ReplaySubject } from 'rxjs'; +import { filter, take, takeUntil } from 'rxjs/operators'; import { Patterns } from 'src/assets/patterns/patterns'; import { emailPreferencesList, periodicityOptions } from '@global-user/models/edit-profile-const'; @@ -29,7 +29,6 @@ import { emailPreferencesList, periodicityOptions } from '@global-user/models/ed }) export class EditProfileComponent extends FormBaseComponent implements OnInit, OnDestroy { editProfileForm: FormGroup; - private langChangeSub: Subscription; private currentLocation: UserLocationDto; coordinates: Coordinates = { latitude: null, longitude: null }; previousPath = '/profile'; @@ -44,7 +43,7 @@ export class EditProfileComponent extends FormBaseComponent implements OnInit, O private profileService: ProfileService; private snackBar: MatSnackBarComponent; private localStorageService: LocalStorageService; - private translate: TranslateService; + private readonly destroyed$: ReplaySubject = new ReplaySubject(1); cityOptions: google.maps.places.AutocompletionRequest = { input: '', types: ['(cities)'] @@ -81,9 +80,10 @@ export class EditProfileComponent extends FormBaseComponent implements OnInit, O } constructor( - private injector: Injector, + private readonly injector: Injector, public dialog: MatDialog, public router: Router, + private readonly translate: TranslateService, private readonly cdr: ChangeDetectorRef ) { super(router, dialog); @@ -92,14 +92,12 @@ export class EditProfileComponent extends FormBaseComponent implements OnInit, O this.profileService = injector.get(ProfileService); this.snackBar = injector.get(MatSnackBarComponent); this.localStorageService = injector.get(LocalStorageService); - this.translate = injector.get(TranslateService); } ngOnInit() { + this.subscribeToLangChange(); this.initForm(); this.getInitialValue(); - this.subscribeToLangChange(); - this.bindLang(this.localStorageService.getCurrentLanguage()); } getFormValues(): any { @@ -215,17 +213,25 @@ export class EditProfileComponent extends FormBaseComponent implements OnInit, O } private bindLang(lang: string): void { - this.translate.setDefaultLang(lang); + if (lang && this.translate.currentLang !== lang) { + this.translate.setDefaultLang(lang); + this.translate.use(lang).subscribe(() => { + this.cdr.detectChanges(); + }); + } if (this.city.pristine) { this.city.setValue(this.builder.getFormatedCity(this.currentLocation)); } } private subscribeToLangChange(): void { - this.langChangeSub = this.localStorageService.languageSubject.subscribe((lang) => this.bindLang(lang)); + this.localStorageService.languageBehaviourSubject.pipe(takeUntil(this.destroyed$)).subscribe((lang: string) => { + this.bindLang(lang); + }); } ngOnDestroy(): void { - this.langChangeSub.unsubscribe(); + this.destroyed$.next(null); + this.destroyed$.complete(); } } diff --git a/src/app/main/component/user/components/profile/edit-profile/social-networks/social-networks.component.ts b/src/app/main/component/user/components/profile/edit-profile/social-networks/social-networks.component.ts index a100af520b..91c55422fb 100644 --- a/src/app/main/component/user/components/profile/edit-profile/social-networks/social-networks.component.ts +++ b/src/app/main/component/user/components/profile/edit-profile/social-networks/social-networks.component.ts @@ -19,7 +19,7 @@ import { ProfileService } from 'src/app/main/component/user/components/profile/p ] }) export class SocialNetworksComponent implements ControlValueAccessor, OnInit { - urlValidationRegex = Patterns.linkPattern; + urlValidationRegex = Patterns.socialMediaPattern; showInput = false; inputTextValue; editedSocialLink: any = false; @@ -126,7 +126,7 @@ export class SocialNetworksComponent implements ControlValueAccessor, OnInit { onAddLink(link?) { this.onChange(link); - const value = link || this.inputTextValue; + const value = (link || this.inputTextValue).trim(); if (this.checkIsUrl(value) && !this.onCheckForExisting(value)) { this.socialNetworks.push({ url: value diff --git a/src/assets/patterns/patterns.ts b/src/assets/patterns/patterns.ts index a52d0eadf1..07d88e6073 100644 --- a/src/assets/patterns/patterns.ts +++ b/src/assets/patterns/patterns.ts @@ -10,8 +10,7 @@ export const Patterns = { Base64Regex: /data:image\/([a-zA-Z]*);base64,([^"]*)/g, - socialMediaPattern: /^(?:https?:\/\/)?(?:www\.)?([^\/?]+)\.com/, - + socialMediaPattern: /^(?:https?:\/\/)?(?:www\.)?([^\/\s?]+)\.com/, numericAndAlphabetic: /^[A-Za-zА-Яа-яїЇіІєЄёЁ0-9\-\\\/]*$/, serteficatePattern: /(?!0000)\d{4}-(?!0000)\d{4}/, From 4c866df2a2576c9b51da55568280572a07b7312f Mon Sep 17 00:00:00 2001 From: sofiia koval Date: Wed, 13 Nov 2024 14:29:10 +0200 Subject: [PATCH 2/5] fix: reloading of page and regex --- .../components/profile/edit-profile/edit-profile.component.ts | 2 +- .../user/components/profile/profile-service/profile.service.ts | 1 - src/assets/patterns/patterns.ts | 3 ++- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/main/component/user/components/profile/edit-profile/edit-profile.component.ts b/src/app/main/component/user/components/profile/edit-profile/edit-profile.component.ts index 32aa53f251..d351550ead 100644 --- a/src/app/main/component/user/components/profile/edit-profile/edit-profile.component.ts +++ b/src/app/main/component/user/components/profile/edit-profile/edit-profile.component.ts @@ -149,7 +149,7 @@ export class EditProfileComponent extends FormBaseComponent implements OnInit, O getInitialValue(): void { this.profileService .getUserInfo() - .pipe(take(1), filter(Boolean)) + .pipe(takeUntil(this.destroyed$)) .subscribe((data: EditProfileModel) => { this.editProfileForm = this.builder.getEditProfileForm(data); this.currentLocation = data.userLocationDto; diff --git a/src/app/main/component/user/components/profile/profile-service/profile.service.ts b/src/app/main/component/user/components/profile/profile-service/profile.service.ts index c156a38d39..8714120d02 100644 --- a/src/app/main/component/user/components/profile/profile-service/profile.service.ts +++ b/src/app/main/component/user/components/profile/profile-service/profile.service.ts @@ -71,7 +71,6 @@ export class ProfileService { private getDomainFromUrl(url: string): string | null { const regex = Patterns.socialMediaPattern; const match = regex.exec(url); - return match?.[1] || null; } } diff --git a/src/assets/patterns/patterns.ts b/src/assets/patterns/patterns.ts index 07d88e6073..6fc350f7d2 100644 --- a/src/assets/patterns/patterns.ts +++ b/src/assets/patterns/patterns.ts @@ -10,7 +10,8 @@ export const Patterns = { Base64Regex: /data:image\/([a-zA-Z]*);base64,([^"]*)/g, - socialMediaPattern: /^(?:https?:\/\/)?(?:www\.)?([^\/\s?]+)\.com/, + socialMediaPattern: /^(?:https?:\/\/)?(?:www\.)?([^\s/?]+)\.com(?:[/?][^\s]*)?$/, + numericAndAlphabetic: /^[A-Za-zА-Яа-яїЇіІєЄёЁ0-9\-\\\/]*$/, serteficatePattern: /(?!0000)\d{4}-(?!0000)\d{4}/, From fb62da757a74951930fb7d07c17e2f314c017ca2 Mon Sep 17 00:00:00 2001 From: sofiia koval Date: Wed, 13 Nov 2024 14:43:32 +0200 Subject: [PATCH 3/5] fix: delete unused imports --- .../components/profile/edit-profile/edit-profile.component.ts | 2 +- src/app/shared/search-popup/search-popup.component.ts | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/app/main/component/user/components/profile/edit-profile/edit-profile.component.ts b/src/app/main/component/user/components/profile/edit-profile/edit-profile.component.ts index d351550ead..24c3c2881e 100644 --- a/src/app/main/component/user/components/profile/edit-profile/edit-profile.component.ts +++ b/src/app/main/component/user/components/profile/edit-profile/edit-profile.component.ts @@ -18,7 +18,7 @@ import { EditProfileService } from '@global-user/services/edit-profile.service'; import { TranslateService } from '@ngx-translate/core'; import { FormBaseComponent } from '@shared/components/form-base/form-base.component'; import { ReplaySubject } from 'rxjs'; -import { filter, take, takeUntil } from 'rxjs/operators'; +import { takeUntil } from 'rxjs/operators'; import { Patterns } from 'src/assets/patterns/patterns'; import { emailPreferencesList, periodicityOptions } from '@global-user/models/edit-profile-const'; diff --git a/src/app/shared/search-popup/search-popup.component.ts b/src/app/shared/search-popup/search-popup.component.ts index 92083feabb..d27a99da07 100644 --- a/src/app/shared/search-popup/search-popup.component.ts +++ b/src/app/shared/search-popup/search-popup.component.ts @@ -1,6 +1,5 @@ import { NewsSearchModel } from '@global-models/search/newsSearch.model'; import { EventsSearchModel } from '@global-models/search/eventsSearch.model'; -import { SearchDataModel } from '@global-models/search/search.model'; import { LiveAnnouncer } from '@angular/cdk/a11y'; import { searchIcons } from '../../main/image-pathes/search-icons'; import { negate, isNil } from 'lodash'; From d4522870bfc17a24f8c1b64c929e21517049402d Mon Sep 17 00:00:00 2001 From: sofiia koval Date: Thu, 14 Nov 2024 13:56:15 +0200 Subject: [PATCH 4/5] fix: issues --- .../edit-profile/social-networks/social-networks.component.ts | 2 +- .../user/components/profile/profile-service/profile.service.ts | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/app/main/component/user/components/profile/edit-profile/social-networks/social-networks.component.ts b/src/app/main/component/user/components/profile/edit-profile/social-networks/social-networks.component.ts index 91c55422fb..1849974293 100644 --- a/src/app/main/component/user/components/profile/edit-profile/social-networks/social-networks.component.ts +++ b/src/app/main/component/user/components/profile/edit-profile/social-networks/social-networks.component.ts @@ -124,7 +124,7 @@ export class SocialNetworksComponent implements ControlValueAccessor, OnInit { return result; } - onAddLink(link?) { + onAddLink(link?: string) { this.onChange(link); const value = (link || this.inputTextValue).trim(); if (this.checkIsUrl(value) && !this.onCheckForExisting(value)) { diff --git a/src/app/main/component/user/components/profile/profile-service/profile.service.ts b/src/app/main/component/user/components/profile/profile-service/profile.service.ts index 8714120d02..347a96c996 100644 --- a/src/app/main/component/user/components/profile/profile-service/profile.service.ts +++ b/src/app/main/component/user/components/profile/profile-service/profile.service.ts @@ -32,8 +32,7 @@ export class ProfileService { constructor( private http: HttpClient, - private localStorageService: LocalStorageService, - private languageService: LanguageService + private localStorageService: LocalStorageService ) {} setUserId(): void { From e2a83c3fcaf833ae812c807e30805081cc8ef3d5 Mon Sep 17 00:00:00 2001 From: sofiia koval Date: Thu, 14 Nov 2024 14:49:07 +0200 Subject: [PATCH 5/5] fix: delete import --- .../user/components/profile/profile-service/profile.service.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/app/main/component/user/components/profile/profile-service/profile.service.ts b/src/app/main/component/user/components/profile/profile-service/profile.service.ts index 347a96c996..ff9f17ca71 100644 --- a/src/app/main/component/user/components/profile/profile-service/profile.service.ts +++ b/src/app/main/component/user/components/profile/profile-service/profile.service.ts @@ -6,7 +6,6 @@ import { HttpClient } from '@angular/common/http'; import { LocalStorageService } from '@global-service/localstorage/local-storage.service'; import { ProfileStatistics } from '@user-models/profile-statistiscs'; import { EditProfileModel } from '@user-models/edit-profile.model'; -import { LanguageService } from 'src/app/main/i18n/language.service'; import { mainLink, mainUserLink } from '../../../../../links'; import { Patterns } from 'src/assets/patterns/patterns';