From e60d7267720d6a1eb04f7d529f17a2d22de65cad Mon Sep 17 00:00:00 2001 From: andriikamaldinov1 Date: Wed, 13 Sep 2023 12:07:55 +0300 Subject: [PATCH 1/3] downgrade to v15 --- base-http/base-http.service.ts | 4 ++- chip/chip.component.ts | 2 +- github-buttons/github-buttons.component.html | 2 +- github-buttons/github-buttons.component.ts | 6 ++-- github/github-stars.service.ts | 3 +- input/input.component.ts | 19 +++++------ .../accordion/accordion.component.html | 12 +++---- open-source/accordion/accordion.component.ts | 32 +++++++++++++------ open-source/accordion/accordion.service.ts | 10 +++--- open-source/footer/footer.component.html | 2 +- open-source/footer/footer.component.ts | 3 +- open-source/header/header.component.html | 8 ++--- open-source/header/header.component.ts | 13 ++++++-- open-source/scroll/scroll.service.ts | 11 +++---- .../visit-btn/visit-btn.component.html | 2 +- open-source/visit-btn/visit-btn.component.ts | 3 +- unsubscriber/unsubscriber.service.ts | 16 ++++++++++ 17 files changed, 94 insertions(+), 54 deletions(-) create mode 100644 unsubscriber/unsubscriber.service.ts diff --git a/base-http/base-http.service.ts b/base-http/base-http.service.ts index 3a3c4dc..08ae4d8 100644 --- a/base-http/base-http.service.ts +++ b/base-http/base-http.service.ts @@ -1,6 +1,8 @@ import { isPlatformBrowser } from '@angular/common'; import { HttpClient } from '@angular/common/http'; -import { inject, Injectable, PLATFORM_ID, StateKey, TransferState } from '@angular/core'; +import { inject, Injectable, PLATFORM_ID } from '@angular/core'; +import { StateKey, TransferState } from '@angular/platform-browser'; + import { catchError, Observable, of, tap } from 'rxjs'; import { DOMAIN } from '../token/token'; diff --git a/chip/chip.component.ts b/chip/chip.component.ts index 817e19b..57dddc2 100644 --- a/chip/chip.component.ts +++ b/chip/chip.component.ts @@ -7,7 +7,7 @@ import { Component, Input } from '@angular/core'; styleUrls: ['./chip.component.scss'], }) export class ChipComponent { - @Input({ required: true }) + @Input() public chip!: string; @Input() public chipBgColor = 'rgba(0,0,0,0.05)'; diff --git a/github-buttons/github-buttons.component.html b/github-buttons/github-buttons.component.html index bc78256..962566c 100644 --- a/github-buttons/github-buttons.component.html +++ b/github-buttons/github-buttons.component.html @@ -4,7 +4,7 @@ [href]="jsdaddyGithub" aria-label="Navigate to github">
- Github + Github {{ title }}
{{ (countOfStarsOnGithub$ | async) || 0 }}
diff --git a/github-buttons/github-buttons.component.ts b/github-buttons/github-buttons.component.ts index 791cfc0..d16460e 100644 --- a/github-buttons/github-buttons.component.ts +++ b/github-buttons/github-buttons.component.ts @@ -1,5 +1,5 @@ import { Component, inject, Input } from '@angular/core'; -import { AsyncPipe } from '@angular/common'; +import { AsyncPipe, NgOptimizedImage } from '@angular/common'; import { Observable } from 'rxjs'; import { AssetPipe } from '../asset/asset.pipe'; import { SharedAssetPath } from '../asset/asset.path'; @@ -10,10 +10,10 @@ import { GithubStarsService } from '../github/github-stars.service'; templateUrl: './github-buttons.component.html', styleUrls: ['./github-buttons.component.scss'], standalone: true, - imports: [AsyncPipe, AssetPipe], + imports: [AsyncPipe, AssetPipe, NgOptimizedImage], }) export class GithubButtonsComponent { - @Input({ required: true }) public title!: string; + @Input() public title!: string; public readonly assetPathShared = SharedAssetPath.ROOT; public readonly jsdaddyGithub = 'https://github.com/JsDaddy/'; public readonly countOfStarsOnGithub$: Observable = diff --git a/github/github-stars.service.ts b/github/github-stars.service.ts index a3dc24b..c228f78 100644 --- a/github/github-stars.service.ts +++ b/github/github-stars.service.ts @@ -1,7 +1,8 @@ import { isPlatformServer } from '@angular/common'; -import { Injectable, PLATFORM_ID, inject, makeStateKey } from '@angular/core'; +import { Injectable, PLATFORM_ID, inject } from '@angular/core'; import { concatAll, of, reduce } from 'rxjs'; import { BaseHttpService } from '../base-http/base-http.service'; +import { makeStateKey } from '@angular/platform-browser'; @Injectable() export class GithubStarsService { diff --git a/input/input.component.ts b/input/input.component.ts index dff7c84..9ad87dd 100644 --- a/input/input.component.ts +++ b/input/input.component.ts @@ -3,7 +3,6 @@ import { ChangeDetectionStrategy, ChangeDetectorRef, Component, - DestroyRef, EventEmitter, inject, Input, @@ -22,7 +21,8 @@ import { import { AssetPipe } from '../asset/asset.pipe'; import { InputPipe } from './input.pipe'; import { AutofocusDirective } from '../input/auto-focus.directive'; -import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; +import { UnSubscriber } from '@libraries/unsubscriber/unsubscriber.service'; +import { takeUntil } from 'rxjs'; @Component({ selector: 'jsdaddy-input[placeholder]', @@ -48,10 +48,10 @@ import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; }, ], }) -export class InputComponent implements ControlValueAccessor, OnInit { +export class InputComponent extends UnSubscriber implements ControlValueAccessor, OnInit { private readonly fb = inject(FormBuilder); - @Input({ required: true }) public placeholder!: string; + @Input() public placeholder!: string; @Input() public label?: string | null; @Input() public isTextarea = false; @Input() public validators: ValidatorFn[] = []; @@ -64,15 +64,12 @@ export class InputComponent implements ControlValueAccessor, OnInit { public control: FormControl = this.fb.control(null); private cdr = inject(ChangeDetectorRef); - private readonly destroyRef = inject(DestroyRef); public ngOnInit(): void { - this.control.valueChanges - .pipe(takeUntilDestroyed(this.destroyRef)) - .subscribe((value: string) => { - this.onChange && this.onChange(value); - this.cdr.detectChanges(); - }); + this.control.valueChanges.pipe(takeUntil(this.unsubscribe$$)).subscribe((value: string) => { + this.onChange && this.onChange(value); + this.cdr.detectChanges(); + }); } // eslint-disable-next-line @typescript-eslint/no-explicit-any diff --git a/open-source/accordion/accordion.component.html b/open-source/accordion/accordion.component.html index 19507ec..d87c3c0 100644 --- a/open-source/accordion/accordion.component.html +++ b/open-source/accordion/accordion.component.html @@ -6,13 +6,13 @@ class="white-chevron" width="18" height="18" - [src]="'white-chevron-down' | asset: openSourceAccordionPath" + [ngSrc]="'white-chevron-down' | asset: openSourceAccordionPath" alt="Chevron white" /> Chevron yellow Navigation @@ -29,13 +29,13 @@ Accordion white Accordion yellow @@ -46,13 +46,13 @@ Chevron white Chevron yellow diff --git a/open-source/accordion/accordion.component.ts b/open-source/accordion/accordion.component.ts index 0f26a17..f3fd5b0 100644 --- a/open-source/accordion/accordion.component.ts +++ b/open-source/accordion/accordion.component.ts @@ -1,7 +1,6 @@ import { AfterViewInit, Component, - DestroyRef, ElementRef, EventEmitter, inject, @@ -12,7 +11,14 @@ import { ViewChild, ViewChildren, } from '@angular/core'; -import { DOCUMENT, isPlatformServer, NgClass, NgFor, NgStyle } from '@angular/common'; +import { + DOCUMENT, + isPlatformServer, + NgClass, + NgFor, + NgOptimizedImage, + NgStyle, +} from '@angular/common'; import { IListItem } from './content.interfaces'; import { AssetPipe } from '../../asset/asset.pipe'; import { HidePipe } from '../hide/hide.pipe'; @@ -20,20 +26,29 @@ import { VisitBtnComponent } from '../visit-btn/visit-btn.component'; import { ColorPipe } from '../color/color.pipe'; import { TrackByService } from '../../track-by/track-by.service'; import { ActivatedRoute, Router } from '@angular/router'; -import { filter, fromEvent } from 'rxjs'; +import { filter, fromEvent, takeUntil } from 'rxjs'; import { BodyStylesService } from '../../body-styles/body-styles.service'; import { OpenSourcePath } from '../path/open-source.path'; -import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; +import { UnSubscriber } from '@libraries/unsubscriber/unsubscriber.service'; @Component({ selector: 'jsdaddy-open-source-accordion', templateUrl: './accordion.component.html', styleUrls: ['./accordion.component.scss'], - imports: [NgClass, NgFor, NgStyle, AssetPipe, HidePipe, VisitBtnComponent, ColorPipe], + imports: [ + NgClass, + NgFor, + NgStyle, + AssetPipe, + HidePipe, + VisitBtnComponent, + ColorPipe, + NgOptimizedImage, + ], standalone: true, providers: [BodyStylesService], }) -export class AccordionComponent implements AfterViewInit { +export class AccordionComponent extends UnSubscriber implements AfterViewInit { @Input() public lists!: IListItem[]; @Output() public switchCardIndex = new EventEmitter(); @@ -52,7 +67,6 @@ export class AccordionComponent implements AfterViewInit { private readonly router = inject(Router); private readonly platformId = inject(PLATFORM_ID); private readonly document = inject(DOCUMENT); - private readonly destroyRef = inject(DestroyRef); public ngAfterViewInit(): void { fromEvent(window, 'click') @@ -62,12 +76,12 @@ export class AccordionComponent implements AfterViewInit { this.showAccordion && event?.target !== this.accordionBlockElement.nativeElement ), - takeUntilDestroyed(this.destroyRef) + takeUntil(this.unsubscribe$$) ) .subscribe(() => this.showAccordionBlock()); this.openFirstAccordion(); this.activatedRoute.fragment - .pipe(filter(Boolean), takeUntilDestroyed(this.destroyRef)) + .pipe(filter(Boolean), takeUntil(this.unsubscribe$$)) .subscribe((itemId) => { this.itemInAccordion = Number(itemId); }); diff --git a/open-source/accordion/accordion.service.ts b/open-source/accordion/accordion.service.ts index 06af597..2c77d43 100644 --- a/open-source/accordion/accordion.service.ts +++ b/open-source/accordion/accordion.service.ts @@ -1,18 +1,18 @@ -import { DestroyRef, ElementRef, inject, Injectable, PLATFORM_ID, QueryList } from '@angular/core'; +import { ElementRef, inject, Injectable, PLATFORM_ID, QueryList } from '@angular/core'; import { DOCUMENT, isPlatformServer } from '@angular/common'; -import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; +import { takeUntil } from 'rxjs'; +import { UnSubscriber } from '@libraries/unsubscriber/unsubscriber.service'; @Injectable() -export class AccordionService { +export class AccordionService extends UnSubscriber { private readonly platformId = inject(PLATFORM_ID); private readonly document = inject(DOCUMENT); - private readonly destroyRef = inject(DestroyRef); public onChangeAccordion(cards: QueryList): void { if (isPlatformServer(this.platformId)) { return; } - cards.changes.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((elementRef) => { + cards.changes.pipe(takeUntil(this.unsubscribe$$)).subscribe((elementRef) => { const firstNativeElement: HTMLElement | null = this.document.getElementById( elementRef.first.nativeElement.id ); diff --git a/open-source/footer/footer.component.html b/open-source/footer/footer.component.html index 40f6a39..95bb38f 100644 --- a/open-source/footer/footer.component.html +++ b/open-source/footer/footer.component.html @@ -2,7 +2,7 @@ All rights reserved diff --git a/open-source/footer/footer.component.ts b/open-source/footer/footer.component.ts index a0d01ec..560e9bf 100644 --- a/open-source/footer/footer.component.ts +++ b/open-source/footer/footer.component.ts @@ -1,13 +1,14 @@ import { Component } from '@angular/core'; import { AssetPipe } from '../../asset/asset.pipe'; import { OpenSourcePath } from '../path/open-source.path'; +import { NgOptimizedImage } from '@angular/common'; @Component({ selector: 'jsdaddy-open-source-footer', templateUrl: './footer.component.html', styleUrls: ['./footer.component.scss'], standalone: true, - imports: [AssetPipe], + imports: [AssetPipe, NgOptimizedImage], }) export class FooterComponent { public readonly openSourceFooterPath = OpenSourcePath.FOOTER; diff --git a/open-source/header/header.component.html b/open-source/header/header.component.html index fdddc4b..debb956 100644 --- a/open-source/header/header.component.html +++ b/open-source/header/header.component.html @@ -8,7 +8,7 @@ @@ -24,19 +24,19 @@
- Burger + Burger
Logo JsDaddy Close
diff --git a/open-source/header/header.component.ts b/open-source/header/header.component.ts index cf15ed0..a7eb738 100644 --- a/open-source/header/header.component.ts +++ b/open-source/header/header.component.ts @@ -1,5 +1,5 @@ import { Component, inject, Input } from '@angular/core'; -import { NgClass, NgFor, NgIf } from '@angular/common'; +import { NgClass, NgFor, NgIf, NgOptimizedImage } from '@angular/common'; import { ColorPipe } from '../color/color.pipe'; import { HidePipe } from '../hide/hide.pipe'; import { VisitBtnComponent } from '../visit-btn/visit-btn.component'; @@ -15,7 +15,16 @@ import { OpenSourcePath } from '../path/open-source.path'; templateUrl: './header.component.html', styleUrls: ['./header.component.scss'], standalone: true, - imports: [NgFor, NgIf, NgClass, AssetPipe, ColorPipe, HidePipe, VisitBtnComponent], + imports: [ + NgFor, + NgIf, + NgClass, + AssetPipe, + ColorPipe, + HidePipe, + VisitBtnComponent, + NgOptimizedImage, + ], providers: [BodyStylesService], }) export class HeaderComponent { diff --git a/open-source/scroll/scroll.service.ts b/open-source/scroll/scroll.service.ts index 3fccf55..17ac685 100644 --- a/open-source/scroll/scroll.service.ts +++ b/open-source/scroll/scroll.service.ts @@ -1,24 +1,23 @@ -import { DestroyRef, ElementRef, inject, Injectable, PLATFORM_ID, QueryList } from '@angular/core'; -import { BehaviorSubject, debounceTime, fromEvent } from 'rxjs'; +import { ElementRef, inject, Injectable, PLATFORM_ID, QueryList } from '@angular/core'; +import { BehaviorSubject, debounceTime, fromEvent, takeUntil } from 'rxjs'; import { Router } from '@angular/router'; import { DOCUMENT, isPlatformServer } from '@angular/common'; -import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; +import { UnSubscriber } from '@libraries/unsubscriber/unsubscriber.service'; @Injectable() -export class ScrollService { +export class ScrollService extends UnSubscriber { private readonly activeCardId$$: BehaviorSubject = new BehaviorSubject(1); private readonly router = inject(Router); private readonly minusTopHeight = 300; private readonly minusTopMobileHeight = 150; private readonly document = inject(DOCUMENT); private readonly platformId = inject(PLATFORM_ID); - private readonly destroyRef = inject(DestroyRef); public readonly activeCard$ = this.activeCardId$$.asObservable(); public onScroll(cards: QueryList): void { fromEvent(document, 'scroll') - .pipe(debounceTime(100), takeUntilDestroyed(this.destroyRef)) + .pipe(debounceTime(100), takeUntil(this.unsubscribe$$)) .subscribe(() => { const scrollIdCard = cards.find((e) => this.isInViewport(e.nativeElement)) ?.nativeElement.id; diff --git a/open-source/visit-btn/visit-btn.component.html b/open-source/visit-btn/visit-btn.component.html index 56e0dd3..12c777b 100644 --- a/open-source/visit-btn/visit-btn.component.html +++ b/open-source/visit-btn/visit-btn.component.html @@ -4,7 +4,7 @@ Chevron button diff --git a/open-source/visit-btn/visit-btn.component.ts b/open-source/visit-btn/visit-btn.component.ts index 296d0ec..3f3ae8f 100644 --- a/open-source/visit-btn/visit-btn.component.ts +++ b/open-source/visit-btn/visit-btn.component.ts @@ -2,13 +2,14 @@ import { Component } from '@angular/core'; import { AssetPipe } from '../../asset/asset.pipe'; import { LinkPath } from '../../link/link.path'; import { OpenSourcePath } from '../path/open-source.path'; +import { NgOptimizedImage } from '@angular/common'; @Component({ selector: 'jsdaddy-open-source-visit-btn', templateUrl: './visit-btn.component.html', styleUrls: ['./visit-btn.component.scss'], standalone: true, - imports: [AssetPipe], + imports: [AssetPipe, NgOptimizedImage], }) export class VisitBtnComponent { public readonly jsDaddyWebsite = LinkPath.WEBSITE_JSDDADY; diff --git a/unsubscriber/unsubscriber.service.ts b/unsubscriber/unsubscriber.service.ts new file mode 100644 index 0000000..942fbb4 --- /dev/null +++ b/unsubscriber/unsubscriber.service.ts @@ -0,0 +1,16 @@ +import { Injectable, OnDestroy } from '@angular/core'; +import { Subject } from 'rxjs'; + +@Injectable() +export class UnSubscriber implements OnDestroy { + public _unsubscribe$$ = new Subject(); + + public get unsubscribe$$() { + return this._unsubscribe$$.asObservable(); + } + + public ngOnDestroy(): void { + this._unsubscribe$$.next(true); + this._unsubscribe$$.complete(); + } +} From 63357c562893a61235be5dc0eb8409dd996a9529 Mon Sep 17 00:00:00 2001 From: andriikamaldinov1 Date: Wed, 13 Sep 2023 12:15:14 +0300 Subject: [PATCH 2/3] downgrade to v15 --- github-buttons/github-buttons.component.html | 2 +- input/input.component.html | 4 ++-- open-source/accordion/accordion.component.html | 14 +++++++------- open-source/footer/footer.component.html | 2 +- open-source/header/header.component.html | 16 ++++++++++------ open-source/visit-btn/visit-btn.component.html | 2 +- 6 files changed, 22 insertions(+), 18 deletions(-) diff --git a/github-buttons/github-buttons.component.html b/github-buttons/github-buttons.component.html index 962566c..86dfef9 100644 --- a/github-buttons/github-buttons.component.html +++ b/github-buttons/github-buttons.component.html @@ -4,7 +4,7 @@ [href]="jsdaddyGithub" aria-label="Navigate to github">
- Github + Github {{ title }}
{{ (countOfStarsOnGithub$ | async) || 0 }}
diff --git a/input/input.component.html b/input/input.component.html index b40ef54..34ee242 100644 --- a/input/input.component.html +++ b/input/input.component.html @@ -1,4 +1,4 @@ -
+
+ [src]="'done-yellow' | asset : additionalPath" />
diff --git a/open-source/accordion/accordion.component.html b/open-source/accordion/accordion.component.html index d87c3c0..d168b19 100644 --- a/open-source/accordion/accordion.component.html +++ b/open-source/accordion/accordion.component.html @@ -6,13 +6,13 @@ class="white-chevron" width="18" height="18" - [ngSrc]="'white-chevron-down' | asset: openSourceAccordionPath" + [ngSrc]="'white-chevron-down' | asset : openSourceAccordionPath" alt="Chevron white" /> Chevron yellow Navigation
@@ -29,13 +29,13 @@ Accordion white Accordion yellow @@ -46,13 +46,13 @@ Chevron white Chevron yellow @@ -61,7 +61,7 @@

{{ item.content }}

diff --git a/open-source/footer/footer.component.html b/open-source/footer/footer.component.html index 95bb38f..7da2417 100644 --- a/open-source/footer/footer.component.html +++ b/open-source/footer/footer.component.html @@ -2,7 +2,7 @@ All rights reserved diff --git a/open-source/header/header.component.html b/open-source/header/header.component.html index debb956..f2acfdc 100644 --- a/open-source/header/header.component.html +++ b/open-source/header/header.component.html @@ -8,14 +8,14 @@
- Burger + Burger
Logo JsDaddy Close
@@ -45,7 +49,7 @@

Repositories