From c38a56514333aafbd30c329b5f48eb260f79739c Mon Sep 17 00:00:00 2001 From: Nikolai Sukhanov Date: Wed, 13 Mar 2024 12:53:07 +0400 Subject: [PATCH] refactor: provide changelog via injector --- .../src/lib/changelog/changelog.component.html | 2 +- .../ui/src/lib/changelog/changelog.component.ts | 9 ++++++--- .../shared/ui/src/lib/changelog/i-changelog.ts | 8 ++++++++ modules/shared/ui/src/lib/changelog/index.ts | 1 + .../ui/src/lib/changelog => src}/changelog.ts | 16 ++-------------- src/main.ts | 5 ++++- 6 files changed, 22 insertions(+), 19 deletions(-) create mode 100644 modules/shared/ui/src/lib/changelog/i-changelog.ts rename {modules/shared/ui/src/lib/changelog => src}/changelog.ts (86%) diff --git a/modules/shared/ui/src/lib/changelog/changelog.component.html b/modules/shared/ui/src/lib/changelog/changelog.component.html index 36dacb8e..314b63ac 100644 --- a/modules/shared/ui/src/lib/changelog/changelog.component.html +++ b/modules/shared/ui/src/lib/changelog/changelog.component.html @@ -1,5 +1,5 @@
    - @for(versionRecord of log; track versionRecord; let last = $last; let first = $first) { + @for(versionRecord of changelog; track versionRecord; let last = $last; let first = $first) {
  1. diff --git a/modules/shared/ui/src/lib/changelog/changelog.component.ts b/modules/shared/ui/src/lib/changelog/changelog.component.ts index aa09b7aa..2ac3094b 100644 --- a/modules/shared/ui/src/lib/changelog/changelog.component.ts +++ b/modules/shared/ui/src/lib/changelog/changelog.component.ts @@ -1,8 +1,8 @@ -import { ChangeDetectionStrategy, Component } from '@angular/core'; +import { ChangeDetectionStrategy, Component, Inject } from '@angular/core'; import { TranslocoPipe } from '@ngneat/transloco'; import { MatDivider } from '@angular/material/divider'; -import { CHANGELOG } from './changelog'; +import { CHANGELOG_TOKEN, IChangelog } from './i-changelog'; @Component({ standalone: true, @@ -16,5 +16,8 @@ import { CHANGELOG } from './changelog'; changeDetection: ChangeDetectionStrategy.OnPush }) export class ChangelogComponent { - public readonly log = CHANGELOG; + constructor( + @Inject(CHANGELOG_TOKEN) public readonly changelog: IChangelog + ) { + } } diff --git a/modules/shared/ui/src/lib/changelog/i-changelog.ts b/modules/shared/ui/src/lib/changelog/i-changelog.ts new file mode 100644 index 00000000..c954fa1d --- /dev/null +++ b/modules/shared/ui/src/lib/changelog/i-changelog.ts @@ -0,0 +1,8 @@ +import { InjectionToken } from '@angular/core'; + +export interface IChangelog extends Array<{ + version: string; + changeL10nKeys: Array; +}> { } + +export const CHANGELOG_TOKEN = new InjectionToken('CHANGELOG'); diff --git a/modules/shared/ui/src/lib/changelog/index.ts b/modules/shared/ui/src/lib/changelog/index.ts index 2d462ad3..727932f8 100644 --- a/modules/shared/ui/src/lib/changelog/index.ts +++ b/modules/shared/ui/src/lib/changelog/index.ts @@ -1 +1,2 @@ export * from './changelog.component'; +export * from './i-changelog'; diff --git a/modules/shared/ui/src/lib/changelog/changelog.ts b/src/changelog.ts similarity index 86% rename from modules/shared/ui/src/lib/changelog/changelog.ts rename to src/changelog.ts index 4cf6ad8a..f3385b41 100644 --- a/modules/shared/ui/src/lib/changelog/changelog.ts +++ b/src/changelog.ts @@ -1,18 +1,6 @@ -export type Changelog = Array<{ - version: string; - changeL10nKeys: Array; -}>; +import { IChangelog } from '@app/shared-ui'; -export const CHANGELOG: Changelog = [ - { - version: '1.2.6', - changeL10nKeys: [ - 'changelog.1-2-6.fixServoCalibrationForRangesGraterThan360', - 'changelog.1-2-6.fixServoCalibrationResultsNotBeingRound', - 'changelog.1-2-6.fixMultipleServoCalibrationOnStartup', - 'changelog.1-2-6.featMotorStrainingReduction', - ] - }, +export const CHANGELOG: IChangelog = [ { version: '1.2.5', changeL10nKeys: [ diff --git a/src/main.ts b/src/main.ts index a1f87bc0..131caef1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -11,9 +11,11 @@ import { ShowOnTouchedErrorStateMatcher } from '@app/shared-misc'; import { provideI18n } from '@app/shared-i18n'; import { provideApplicationStore } from '@app/store'; import { provideBindings } from '@app/bindings'; +import { CHANGELOG_TOKEN } from '@app/shared-ui'; import { RootComponent } from './app'; import { ROUTES } from './routes'; +import { CHANGELOG } from './changelog'; bootstrapApplication(RootComponent, { providers: [ @@ -29,6 +31,7 @@ bootstrapApplication(RootComponent, { provideServiceWorker('ngsw-worker.js', { enabled: !isDevMode(), registrationStrategy: 'registerWhenStable:30000' - }) + }), + { provide: CHANGELOG_TOKEN, useValue: CHANGELOG } ] });