From a3e7d59369ba85ce7bc0be58c2cee7e1b054016b Mon Sep 17 00:00:00 2001 From: David LJ Date: Sun, 15 Oct 2023 21:21:56 +0200 Subject: [PATCH] refactor(profile): add prefix to child comps (#116) --- src/app/about/profile/_profile-theme.scss | 12 +++++------ .../_profile-contact-social-icons-theme.scss} | 4 ++-- ...ofile-contact-social-icons.component.html} | 0 ...ofile-contact-social-icons.component.scss} | 2 +- ...le-contact-social-icons.component.spec.ts} | 10 ++++----- ...profile-contact-social-icons.component.ts} | 8 +++---- ...file-contact-traditional-icons-theme.scss} | 4 ++-- ...-contact-traditional-icons.component.html} | 0 ...-contact-traditional-icons.component.scss} | 0 ...ntact-traditional-icons.component.spec.ts} | 10 ++++----- ...le-contact-traditional-icons.component.ts} | 8 +++---- .../profile-description.component.html} | 4 ++-- .../profile-description.component.scss} | 0 .../profile-description.component.spec.ts} | 21 +++++++++++-------- .../profile-description.component.ts} | 18 +++++++++------- src/app/about/profile/profile.component.html | 6 +++--- .../about/profile/profile.component.spec.ts | 18 ++++++++-------- src/app/app.module.ts | 12 +++++------ 18 files changed, 71 insertions(+), 66 deletions(-) rename src/app/about/profile/{contact-social-icons/_contact-social-icons-theme.scss => profile-contact-social-icons/_profile-contact-social-icons-theme.scss} (80%) rename src/app/about/profile/{contact-social-icons/contact-social-icons.component.html => profile-contact-social-icons/profile-contact-social-icons.component.html} (100%) rename src/app/about/profile/{contact-social-icons/contact-social-icons.component.scss => profile-contact-social-icons/profile-contact-social-icons.component.scss} (80%) rename src/app/about/profile/{contact-social-icons/contact-social-icons.component.spec.ts => profile-contact-social-icons/profile-contact-social-icons.component.spec.ts} (88%) rename src/app/about/profile/{contact-social-icons/contact-social-icons.component.ts => profile-contact-social-icons/profile-contact-social-icons.component.ts} (82%) rename src/app/about/profile/{contact-traditional-icons/_contact-traditional-icons-theme.scss => profile-contact-traditional-icons/_profile-contact-traditional-icons-theme.scss} (77%) rename src/app/about/profile/{contact-traditional-icons/contact-traditional-icons.component.html => profile-contact-traditional-icons/profile-contact-traditional-icons.component.html} (100%) rename src/app/about/profile/{contact-traditional-icons/contact-traditional-icons.component.scss => profile-contact-traditional-icons/profile-contact-traditional-icons.component.scss} (100%) rename src/app/about/profile/{contact-traditional-icons/contact-traditional-icons.component.spec.ts => profile-contact-traditional-icons/profile-contact-traditional-icons.component.spec.ts} (78%) rename src/app/about/profile/{contact-traditional-icons/contact-traditional-icons.component.ts => profile-contact-traditional-icons/profile-contact-traditional-icons.component.ts} (70%) rename src/app/about/profile/{description/description.component.html => profile-description/profile-description.component.html} (90%) rename src/app/about/profile/{description/description.component.scss => profile-description/profile-description.component.scss} (100%) rename src/app/about/profile/{description/description.component.spec.ts => profile-description/profile-description.component.spec.ts} (96%) rename src/app/about/profile/{description/description.component.ts => profile-description/profile-description.component.ts} (89%) diff --git a/src/app/about/profile/_profile-theme.scss b/src/app/about/profile/_profile-theme.scss index 5f554298..997665c6 100644 --- a/src/app/about/profile/_profile-theme.scss +++ b/src/app/about/profile/_profile-theme.scss @@ -1,21 +1,21 @@ @use 'animations'; @use 'profile-picture/profile-picture-theme'; -@use 'contact-social-icons/contact-social-icons-theme'; -@use 'contact-traditional-icons/contact-traditional-icons-theme'; +@use 'profile-contact-social-icons/profile-contact-social-icons-theme'; +@use 'profile-contact-traditional-icons/profile-contact-traditional-icons-theme'; @mixin color($theme) { app-profile { @include profile-picture-theme.color($theme); - @include contact-traditional-icons-theme.color($theme); - @include contact-social-icons-theme.color($theme); + @include profile-contact-traditional-icons-theme.color($theme); + @include profile-contact-social-icons-theme.color($theme); } } @mixin motion() { app-profile { @include profile-picture-theme.motion(); - @include contact-traditional-icons-theme.motion; - @include contact-social-icons-theme.motion; + @include profile-contact-traditional-icons-theme.motion; + @include profile-contact-social-icons-theme.motion; } } diff --git a/src/app/about/profile/contact-social-icons/_contact-social-icons-theme.scss b/src/app/about/profile/profile-contact-social-icons/_profile-contact-social-icons-theme.scss similarity index 80% rename from src/app/about/profile/contact-social-icons/_contact-social-icons-theme.scss rename to src/app/about/profile/profile-contact-social-icons/_profile-contact-social-icons-theme.scss index d24b08dc..28af6ccc 100644 --- a/src/app/about/profile/contact-social-icons/_contact-social-icons-theme.scss +++ b/src/app/about/profile/profile-contact-social-icons/_profile-contact-social-icons-theme.scss @@ -3,7 +3,7 @@ @mixin color($theme) { $text-palette: map-get($theme, text); - app-contact-social-icons { + app-profile-contact-social-icons { color: map-get($theme, icon); li:hover { @@ -12,7 +12,7 @@ } } @mixin motion { - app-contact-social-icons { + app-profile-contact-social-icons { @include animations.single-transition(color, animations.$emphasized-style); } } diff --git a/src/app/about/profile/contact-social-icons/contact-social-icons.component.html b/src/app/about/profile/profile-contact-social-icons/profile-contact-social-icons.component.html similarity index 100% rename from src/app/about/profile/contact-social-icons/contact-social-icons.component.html rename to src/app/about/profile/profile-contact-social-icons/profile-contact-social-icons.component.html diff --git a/src/app/about/profile/contact-social-icons/contact-social-icons.component.scss b/src/app/about/profile/profile-contact-social-icons/profile-contact-social-icons.component.scss similarity index 80% rename from src/app/about/profile/contact-social-icons/contact-social-icons.component.scss rename to src/app/about/profile/profile-contact-social-icons/profile-contact-social-icons.component.scss index 2d589619..c68b00a0 100644 --- a/src/app/about/profile/contact-social-icons/contact-social-icons.component.scss +++ b/src/app/about/profile/profile-contact-social-icons/profile-contact-social-icons.component.scss @@ -7,7 +7,7 @@ margin-left: 0; } - // Position in same place as Material Symbols from app-contact-traditional-icons + // Position in same place as Material Symbols from app-profile-contact-traditional-icons margin-left: 2px; display: flex; flex-direction: row; diff --git a/src/app/about/profile/contact-social-icons/contact-social-icons.component.spec.ts b/src/app/about/profile/profile-contact-social-icons/profile-contact-social-icons.component.spec.ts similarity index 88% rename from src/app/about/profile/contact-social-icons/contact-social-icons.component.spec.ts rename to src/app/about/profile/profile-contact-social-icons/profile-contact-social-icons.component.spec.ts index 8c9993f7..8f69314a 100644 --- a/src/app/about/profile/contact-social-icons/contact-social-icons.component.spec.ts +++ b/src/app/about/profile/profile-contact-social-icons/profile-contact-social-icons.component.spec.ts @@ -6,17 +6,17 @@ import { MockProvider } from 'ng-mocks' import { METADATA } from '../../../common/injection-tokens' import { Metadata } from '../../../metadata' -import { ContactSocialIconsComponent } from './contact-social-icons.component' +import { ProfileContactSocialIconsComponent } from './profile-contact-social-icons.component' import { byComponent } from '../../../../test/helpers/component-query-predicates' describe('ContactSocialIconsComponent', () => { - let component: ContactSocialIconsComponent - let fixture: ComponentFixture + let component: ProfileContactSocialIconsComponent + let fixture: ComponentFixture const nickname = 'foo' beforeEach(() => { TestBed.configureTestingModule({ - declarations: [ContactSocialIconsComponent, FaIconComponent], + declarations: [ProfileContactSocialIconsComponent, FaIconComponent], providers: [ MockProvider(METADATA, { nickname: nickname } as Pick< Metadata, @@ -24,7 +24,7 @@ describe('ContactSocialIconsComponent', () => { > as Metadata), ], }) - fixture = TestBed.createComponent(ContactSocialIconsComponent) + fixture = TestBed.createComponent(ProfileContactSocialIconsComponent) component = fixture.componentInstance fixture.detectChanges() }) diff --git a/src/app/about/profile/contact-social-icons/contact-social-icons.component.ts b/src/app/about/profile/profile-contact-social-icons/profile-contact-social-icons.component.ts similarity index 82% rename from src/app/about/profile/contact-social-icons/contact-social-icons.component.ts rename to src/app/about/profile/profile-contact-social-icons/profile-contact-social-icons.component.ts index 64cac064..2695e72f 100644 --- a/src/app/about/profile/contact-social-icons/contact-social-icons.component.ts +++ b/src/app/about/profile/profile-contact-social-icons/profile-contact-social-icons.component.ts @@ -10,11 +10,11 @@ import { METADATA } from '../../../common/injection-tokens' import { Metadata } from '../../../metadata' @Component({ - selector: 'app-contact-social-icons', - templateUrl: './contact-social-icons.component.html', - styleUrls: ['./contact-social-icons.component.scss'], + selector: 'app-profile-contact-social-icons', + templateUrl: './profile-contact-social-icons.component.html', + styleUrls: ['./profile-contact-social-icons.component.scss'], }) -export class ContactSocialIconsComponent { +export class ProfileContactSocialIconsComponent { public items: ReadonlyArray<{ name: string icon: IconDefinition diff --git a/src/app/about/profile/contact-traditional-icons/_contact-traditional-icons-theme.scss b/src/app/about/profile/profile-contact-traditional-icons/_profile-contact-traditional-icons-theme.scss similarity index 77% rename from src/app/about/profile/contact-traditional-icons/_contact-traditional-icons-theme.scss rename to src/app/about/profile/profile-contact-traditional-icons/_profile-contact-traditional-icons-theme.scss index 07d0e6ef..b5b56490 100644 --- a/src/app/about/profile/contact-traditional-icons/_contact-traditional-icons-theme.scss +++ b/src/app/about/profile/profile-contact-traditional-icons/_profile-contact-traditional-icons-theme.scss @@ -3,7 +3,7 @@ @mixin color($theme) { $text-palette: map-get($theme, text); - app-contact-traditional-icons { + app-profile-contact-traditional-icons { color: map-get($theme, icon); li:hover { @@ -12,7 +12,7 @@ } } @mixin motion { - app-contact-traditional-icons { + app-profile-contact-traditional-icons { @include animations.single-transition(color, animations.$emphasized-style); } } diff --git a/src/app/about/profile/contact-traditional-icons/contact-traditional-icons.component.html b/src/app/about/profile/profile-contact-traditional-icons/profile-contact-traditional-icons.component.html similarity index 100% rename from src/app/about/profile/contact-traditional-icons/contact-traditional-icons.component.html rename to src/app/about/profile/profile-contact-traditional-icons/profile-contact-traditional-icons.component.html diff --git a/src/app/about/profile/contact-traditional-icons/contact-traditional-icons.component.scss b/src/app/about/profile/profile-contact-traditional-icons/profile-contact-traditional-icons.component.scss similarity index 100% rename from src/app/about/profile/contact-traditional-icons/contact-traditional-icons.component.scss rename to src/app/about/profile/profile-contact-traditional-icons/profile-contact-traditional-icons.component.scss diff --git a/src/app/about/profile/contact-traditional-icons/contact-traditional-icons.component.spec.ts b/src/app/about/profile/profile-contact-traditional-icons/profile-contact-traditional-icons.component.spec.ts similarity index 78% rename from src/app/about/profile/contact-traditional-icons/contact-traditional-icons.component.spec.ts rename to src/app/about/profile/profile-contact-traditional-icons/profile-contact-traditional-icons.component.spec.ts index 640d8098..98a31d01 100644 --- a/src/app/about/profile/contact-traditional-icons/contact-traditional-icons.component.spec.ts +++ b/src/app/about/profile/profile-contact-traditional-icons/profile-contact-traditional-icons.component.spec.ts @@ -1,17 +1,17 @@ import { ComponentFixture, TestBed } from '@angular/core/testing' import { By } from '@angular/platform-browser' -import { ContactTraditionalIconsComponent } from './contact-traditional-icons.component' +import { ProfileContactTraditionalIconsComponent } from './profile-contact-traditional-icons.component' describe('ContactTraditionalIconsComponent', () => { - let component: ContactTraditionalIconsComponent - let fixture: ComponentFixture + let component: ProfileContactTraditionalIconsComponent + let fixture: ComponentFixture beforeEach(() => { TestBed.configureTestingModule({ - declarations: [ContactTraditionalIconsComponent], + declarations: [ProfileContactTraditionalIconsComponent], }) - fixture = TestBed.createComponent(ContactTraditionalIconsComponent) + fixture = TestBed.createComponent(ProfileContactTraditionalIconsComponent) component = fixture.componentInstance fixture.detectChanges() }) diff --git a/src/app/about/profile/contact-traditional-icons/contact-traditional-icons.component.ts b/src/app/about/profile/profile-contact-traditional-icons/profile-contact-traditional-icons.component.ts similarity index 70% rename from src/app/about/profile/contact-traditional-icons/contact-traditional-icons.component.ts rename to src/app/about/profile/profile-contact-traditional-icons/profile-contact-traditional-icons.component.ts index b7fa514d..50b0921d 100644 --- a/src/app/about/profile/contact-traditional-icons/contact-traditional-icons.component.ts +++ b/src/app/about/profile/profile-contact-traditional-icons/profile-contact-traditional-icons.component.ts @@ -2,11 +2,11 @@ import { Component } from '@angular/core' import { Call, Email, MyLocation } from '../../../material-symbols' @Component({ - selector: 'app-contact-traditional-icons', - templateUrl: './contact-traditional-icons.component.html', - styleUrls: ['./contact-traditional-icons.component.scss'], + selector: 'app-profile-contact-traditional-icons', + templateUrl: './profile-contact-traditional-icons.component.html', + styleUrls: ['./profile-contact-traditional-icons.component.scss'], }) -export class ContactTraditionalIconsComponent { +export class ProfileContactTraditionalIconsComponent { public readonly items: ReadonlyArray<{ name: string materialSymbol: string diff --git a/src/app/about/profile/description/description.component.html b/src/app/about/profile/profile-description/profile-description.component.html similarity index 90% rename from src/app/about/profile/description/description.component.html rename to src/app/about/profile/profile-description/profile-description.component.html index 1acccfcc..4d08dcc0 100644 --- a/src/app/about/profile/description/description.component.html +++ b/src/app/about/profile/profile-description/profile-description.component.html @@ -34,7 +34,7 @@ [@expanded]="isCollapsible ? isExpanded : true" >
  • - - + +
  • diff --git a/src/app/about/profile/description/description.component.scss b/src/app/about/profile/profile-description/profile-description.component.scss similarity index 100% rename from src/app/about/profile/description/description.component.scss rename to src/app/about/profile/profile-description/profile-description.component.scss diff --git a/src/app/about/profile/description/description.component.spec.ts b/src/app/about/profile/profile-description/profile-description.component.spec.ts similarity index 96% rename from src/app/about/profile/description/description.component.spec.ts rename to src/app/about/profile/profile-description/profile-description.component.spec.ts index d01b535f..c79bdbd6 100644 --- a/src/app/about/profile/description/description.component.spec.ts +++ b/src/app/about/profile/profile-description/profile-description.component.spec.ts @@ -22,15 +22,15 @@ import { DescriptionLine, DescriptionLineData } from '../../../metadata' import { COLLAPSIBLE_CONFIG, CollapsibleConfiguration, - DescriptionComponent, -} from './description.component' + ProfileDescriptionComponent, +} from './profile-description.component' import { MaterialSymbolDirective } from '../../../common/material-symbol.directive' import { byComponent } from '../../../../test/helpers/component-query-predicates' import { getReflectedAttribute } from '../../../../test/helpers/get-reflected-attribute' describe('DescriptionComponent', () => { - let component: DescriptionComponent - let fixture: ComponentFixture + let component: ProfileDescriptionComponent + let fixture: ComponentFixture const DATA_CLASS_SELECTOR = By.css('.data') const LIST_SELECTOR = By.css('ul') const CARET_SELECTOR = By.css('.caret') @@ -133,7 +133,7 @@ describe('DescriptionComponent', () => { childrenElements.forEach((childElement, index) => { // Contains line element const childLineElement = childElement.query( - byComponent(DescriptionComponent), + byComponent(ProfileDescriptionComponent), ) expect(childLineElement) .withContext(`child ${index} line element`) @@ -205,7 +205,7 @@ describe('DescriptionComponent', () => { }) describe('when depth is set to configured depth to start a collapsible', () => { function configureToBeCollapsible( - component: DescriptionComponent, + component: ProfileDescriptionComponent, line?: DescriptionLine, ) { component.depth = fakeConfig.collapsibleStartAtDepth @@ -430,16 +430,19 @@ function setup({ platformId, }: { platformId?: typeof PLATFORM_BROWSER_ID | typeof PLATFORM_SERVER_ID -} = {}): [ComponentFixture, DescriptionComponent] { +} = {}): [ + ComponentFixture, + ProfileDescriptionComponent, +] { TestBed.configureTestingModule({ - declarations: [DescriptionComponent, MaterialSymbolDirective], + declarations: [ProfileDescriptionComponent, MaterialSymbolDirective], providers: [ MockProvider(COLLAPSIBLE_CONFIG, fakeConfig), MockProvider(PLATFORM_ID, platformId ?? PLATFORM_BROWSER_ID), ], imports: [NoopAnimationsModule], }) - const fixture = TestBed.createComponent(DescriptionComponent) + const fixture = TestBed.createComponent(ProfileDescriptionComponent) return [fixture, fixture.componentInstance] } diff --git a/src/app/about/profile/description/description.component.ts b/src/app/about/profile/profile-description/profile-description.component.ts similarity index 89% rename from src/app/about/profile/description/description.component.ts rename to src/app/about/profile/profile-description/profile-description.component.ts index 4451334f..926072a7 100644 --- a/src/app/about/profile/description/description.component.ts +++ b/src/app/about/profile/profile-description/profile-description.component.ts @@ -26,9 +26,9 @@ import { DescriptionLine } from '../../../metadata' import { SlugGeneratorService } from '../../../common/slug-generator.service' @Component({ - selector: 'app-description', - templateUrl: './description.component.html', - styleUrls: ['./description.component.scss'], + selector: 'app-profile-description', + templateUrl: './profile-description.component.html', + styleUrls: ['./profile-description.component.scss'], animations: [ trigger('expanded', [ // TODO: Investigate how to set display in state without triggering Angular warning @@ -55,10 +55,10 @@ import { SlugGeneratorService } from '../../../common/slug-generator.service' ]), ], }) -export class DescriptionComponent { +export class ProfileDescriptionComponent { @Input({ required: true }) public line!: DescriptionLine @Input() public depth: number = 0 - @Input() protected parent?: DescriptionComponent + @Input() protected parent?: ProfileDescriptionComponent // 👇 Using `protected` to avoid being marked as unused @HostBinding('class.displayBlockIfNoScript') @@ -70,8 +70,8 @@ export class DescriptionComponent { public isExpanded = this.isRenderingOnBrowser ? this.EXPANDED_DEFAULT_JS_ENABLED : this.EXPANDED_DEFAULT_NO_JS - @ViewChildren(DescriptionComponent) - private children!: QueryList + @ViewChildren(ProfileDescriptionComponent) + private children!: QueryList constructor( protected readonly sanitizer: DomSanitizer, @@ -115,7 +115,9 @@ export class DescriptionComponent { this.parent?.collapseAllChildren({ except: this }) } - collapseAllChildren({ except }: { except?: DescriptionComponent } = {}) { + collapseAllChildren({ + except, + }: { except?: ProfileDescriptionComponent } = {}) { const childrenToCollapse = this.children.filter((child) => child !== except) for (const child of childrenToCollapse) { child.collapse() diff --git a/src/app/about/profile/profile.component.html b/src/app/about/profile/profile.component.html index 10bd42d5..8c2f0285 100644 --- a/src/app/about/profile/profile.component.html +++ b/src/app/about/profile/profile.component.html @@ -9,10 +9,10 @@ {{ title }}
    - - + +
    - + diff --git a/src/app/about/profile/profile.component.spec.ts b/src/app/about/profile/profile.component.spec.ts index 73d6850e..8a24f2e9 100644 --- a/src/app/about/profile/profile.component.spec.ts +++ b/src/app/about/profile/profile.component.spec.ts @@ -4,9 +4,9 @@ import { ProfileComponent } from './profile.component' import { Metadata } from '../../metadata' import { MockComponents, MockProvider } from 'ng-mocks' import { ProfilePictureComponent } from './profile-picture/profile-picture.component' -import { ContactTraditionalIconsComponent } from './contact-traditional-icons/contact-traditional-icons.component' -import { ContactSocialIconsComponent } from './contact-social-icons/contact-social-icons.component' -import { DescriptionComponent } from './description/description.component' +import { ProfileContactTraditionalIconsComponent } from './profile-contact-traditional-icons/profile-contact-traditional-icons.component' +import { ProfileContactSocialIconsComponent } from './profile-contact-social-icons/profile-contact-social-icons.component' +import { ProfileDescriptionComponent } from './profile-description/profile-description.component' import { METADATA } from '../../common/injection-tokens' import { By } from '@angular/platform-browser' import { ensureHasComponents } from '../../../test/helpers/component-testers' @@ -28,9 +28,9 @@ describe('ProfileComponent', () => { MockComponents( H2Component, ProfilePictureComponent, - ContactTraditionalIconsComponent, - ContactSocialIconsComponent, - DescriptionComponent, + ProfileContactTraditionalIconsComponent, + ProfileContactSocialIconsComponent, + ProfileDescriptionComponent, ), ], providers: [MockProvider(METADATA, fakeMetadata)], @@ -67,8 +67,8 @@ describe('ProfileComponent', () => { () => fixture, H2Component, ProfilePictureComponent, - ContactTraditionalIconsComponent, - ContactSocialIconsComponent, - DescriptionComponent, + ProfileContactTraditionalIconsComponent, + ProfileContactSocialIconsComponent, + ProfileDescriptionComponent, ) }) diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 2e59fe60..859a4292 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -6,9 +6,9 @@ import { FontAwesomeModule } from '@fortawesome/angular-fontawesome' import { SeoModule } from '@ngaox/seo' import { environment } from '../environments' import { AboutComponent } from './about/about.component' -import { ContactSocialIconsComponent } from './about/profile/contact-social-icons/contact-social-icons.component' -import { ContactTraditionalIconsComponent } from './about/profile/contact-traditional-icons/contact-traditional-icons.component' -import { DescriptionComponent } from './about/profile/description/description.component' +import { ProfileContactSocialIconsComponent } from './about/profile/profile-contact-social-icons/profile-contact-social-icons.component' +import { ProfileContactTraditionalIconsComponent } from './about/profile/profile-contact-traditional-icons/profile-contact-traditional-icons.component' +import { ProfileDescriptionComponent } from './about/profile/profile-description/profile-description.component' import { ProfilePictureComponent } from './about/profile/profile-picture/profile-picture.component' import { AppRoutingModule } from './app-routing.module' @@ -56,9 +56,9 @@ import { EducationItemCoursesComponent } from './about/education/education-item/ JsonldMetadataComponent, ReleaseInfoComponent, ProfilePictureComponent, - ContactTraditionalIconsComponent, - ContactSocialIconsComponent, - DescriptionComponent, + ProfileContactTraditionalIconsComponent, + ProfileContactSocialIconsComponent, + ProfileDescriptionComponent, NotFoundComponent, ProfileComponent, ExperienceComponent,