Skip to content

Commit

Permalink
Merge pull request #3457 from ita-social-projects/bugfix/#7750-social…
Browse files Browse the repository at this point in the history
…-links

[Bugfix] #7750 social links
  • Loading branch information
hnativlyubomyr authored Nov 18, 2024
2 parents a74a962 + b59965c commit 5f7adac
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 { takeUntil } from 'rxjs/operators';
import { Patterns } from 'src/assets/patterns/patterns';
import { emailPreferencesList, periodicityOptions } from '@global-user/models/edit-profile-const';

Expand All @@ -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';
Expand All @@ -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<any> = new ReplaySubject<any>(1);
cityOptions: google.maps.places.AutocompletionRequest = {
input: '',
types: ['(cities)']
Expand Down Expand Up @@ -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);
Expand All @@ -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 {
Expand Down Expand Up @@ -151,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;
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -124,9 +124,9 @@ export class SocialNetworksComponent implements ControlValueAccessor, OnInit {
return result;
}

onAddLink(link?) {
onAddLink(link?: string) {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 'src/app/main/links';
import { Patterns } from 'src/assets/patterns/patterns';

Expand All @@ -32,8 +31,7 @@ export class ProfileService {

constructor(
private http: HttpClient,
private localStorageService: LocalStorageService,
private languageService: LanguageService
private localStorageService: LocalStorageService
) {}

setUserId(): void {
Expand Down Expand Up @@ -71,7 +69,6 @@ export class ProfileService {
private getDomainFromUrl(url: string): string | null {
const regex = Patterns.socialMediaPattern;
const match = regex.exec(url);

return match?.[1] || null;
}
}
1 change: 0 additions & 1 deletion src/app/shared/search-popup/search-popup.component.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/assets/patterns/patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const Patterns = {

Base64Regex: /data:image\/([a-zA-Z]*);base64,([^"]*)/g,

socialMediaPattern: /^(?:https?:\/\/)?(?:www\.)?([^\/?]+)\.com/,
socialMediaPattern: /^(?:https?:\/\/)?(?:www\.)?([^\s/?]+)\.com(?:[/?][^\s]*)?$/,

numericAndAlphabetic: /^[A-Za-zА-Яа-яїЇіІєЄёЁ0-9\-\\\/]*$/,

Expand Down

0 comments on commit 5f7adac

Please sign in to comment.