Skip to content

Commit

Permalink
Removed unused imports, interfaces, and components; refactored profil…
Browse files Browse the repository at this point in the history
…e component code organization and logic
  • Loading branch information
miladsoft committed Nov 12, 2024
1 parent 09e72f7 commit 5890c03
Showing 1 changed file with 39 additions and 28 deletions.
67 changes: 39 additions & 28 deletions src/app/components/profile/profile.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,24 @@ import { MatTooltipModule } from '@angular/material/tooltip';
import { DomSanitizer, SafeUrl } from '@angular/platform-browser';
import { ActivatedRoute, Router, RouterLink } from '@angular/router';
import { PickerComponent } from '@ctrl/ngx-emoji-mart';
import { bech32 } from '@scure/base';
import { QRCodeModule } from 'angularx-qrcode';
import { PaginatedEventService } from 'app/services/event.service';
import { LightningService } from 'app/services/lightning.service';
import { SignerService } from 'app/services/signer.service';
import { SocialService } from 'app/services/social.service';
import { StorageService } from 'app/services/storage.service';
import { SafeUrlPipe } from 'app/shared/pipes/safe-url.pipe';
import { LightningInvoice, LightningResponse } from 'app/types/post';
import { InfiniteScrollModule } from 'ngx-infinite-scroll';
import { Filter, NostrEvent } from 'nostr-tools';
import { Observable, Subject, takeUntil } from 'rxjs';
import { SubscriptionService } from 'app/services/subscription.service';
import { SubscriptionService } from 'app/services/subscription.service';
import { Clipboard } from '@angular/cdk/clipboard';
import { MatExpansionModule } from '@angular/material/expansion';
import { ParseContentService } from 'app/services/parse-content.service';
import { MatSidenavModule } from '@angular/material/sidenav';
import { ContactInfoComponent } from '../chat/contact-info/contact-info.component';
import { AgoPipe } from 'app/shared/pipes/ago.pipe';
import { ZapDialogComponent } from 'app/shared/zap-dialog/zap-dialog.component';
import { ZapDialogData } from 'app/services/interfaces';
interface Chip {
interface Chip {
color?: string;
selected?: string;
name: string;
Expand Down Expand Up @@ -79,17 +75,12 @@ import { ZapDialogData } from 'app/services/interfaces';
QRCodeModule,
PickerComponent,
MatSlideToggle,
SafeUrlPipe,
MatProgressSpinnerModule,
InfiniteScrollModule,
MatIconModule,
MatExpansionModule,
MatSidenavModule,
ContactInfoComponent,
NgTemplateOutlet,
DatePipe,
AgoPipe,

],
})
export class ProfileComponent implements OnInit, OnDestroy {
Expand Down Expand Up @@ -141,7 +132,6 @@ export class ProfileComponent implements OnInit, OnDestroy {
followingCount: number = 0;
aboutExpanded: boolean = true;


stats$!: Observable<{ pubKey: string, totalContacts: number, followersCount: number, followingCount: number }>;

constructor(
Expand All @@ -153,7 +143,6 @@ export class ProfileComponent implements OnInit, OnDestroy {
private _router: Router,
private _socialService: SocialService,
private _snackBar: MatSnackBar,
private _lightning: LightningService,
private _dialog: MatDialog,
private _angorConfigService: AngorConfigService,
private _angorConfirmationService: AngorConfirmationService,
Expand All @@ -164,33 +153,55 @@ export class ProfileComponent implements OnInit, OnDestroy {
) { }

async ngOnInit(): Promise<void> {
this.initializeTheme();
this.processRouteParams();
this.loadInitialPosts();
this.subscribeToNewPosts();
}

private initializeTheme(): void {
this._angorConfigService.config$.subscribe((config) => {
if (config.scheme === 'auto') {
this.detectSystemTheme();
} else {
this.darkMode = config.scheme === 'dark';
}
});
this._route.paramMap.subscribe((params) => {
const routePubKey = params.get('pubkey');
if (!routePubKey) {
this.isCurrentUserProfile = true;
const currentUserPubKey = this._signerService.getPublicKey();
}

this.routePubKey = currentUserPubKey;
}
else {
this.routePubKey = routePubKey;
private processRouteParams(): void {
this._route.paramMap.subscribe((params) => {
const routePubKey = params.get('pubkey') || '';

if (routePubKey) {
if (this.isValidHexPubkey(routePubKey)) {
this.routePubKey = routePubKey;
this.isCurrentUserProfile = false;
} else {
this.errorMessage = 'Public key is invalid. Please check your input.';
this.setCurrentUserProfile();
}
} else {
this.setCurrentUserProfile();
}
this.loadProfileUser(this.routePubKey);

this.stats$ = this._storageService.getContactStats$(this.routePubKey);

this.loadUserProfileData(this.routePubKey);
});
this.loadInitialPosts();
this.subscribeToNewPosts();
}

private setCurrentUserProfile(): void {
this.isCurrentUserProfile = true;
this.routePubKey = this._signerService.getPublicKey();
}

private loadUserProfileData(pubKey: string): void {
this.loadProfileUser(pubKey);
this.stats$ = this._storageService.getContactStats$(pubKey);
}

private isValidHexPubkey(pubkey: string): boolean {
const hexPattern = /^[a-fA-F0-9]{64}$/;
return hexPattern.test(pubkey);
}

private async loadInitialPosts(): Promise<void> {
Expand Down Expand Up @@ -340,7 +351,7 @@ export class ProfileComponent implements OnInit, OnDestroy {
}


openZapDialog(eventId:string =""): void {
openZapDialog(eventId: string = ""): void {
if (this.canUseZap()) {
const zapData: ZapDialogData = {
lud16: this.profileUser.lud16,
Expand Down

0 comments on commit 5890c03

Please sign in to comment.