-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add changelogs, back buttons. closes #8
- Loading branch information
Showing
18 changed files
with
335 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface IChangelogEntry { | ||
date: string; | ||
text: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './carddata'; | ||
export * from './cardhelp'; | ||
export * from './changelog'; | ||
export * from './faq'; | ||
export * from './product'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { inject, Injectable, signal, type WritableSignal } from '@angular/core'; | ||
import { sortBy } from 'lodash'; | ||
import type { IChangelogEntry } from '../../interfaces'; | ||
import { environment } from '../environments/environment'; | ||
import { LocaleService } from './locale.service'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class ChangelogService { | ||
private localeService = inject(LocaleService); | ||
|
||
private changelogByProductIdAndLocale: WritableSignal< | ||
Record<string, Record<string, IChangelogEntry[]>> | ||
> = signal({}); | ||
|
||
public async init() { | ||
const faqData = await fetch(`${environment.baseUrl}/changelog.json`); | ||
const realData = await faqData.json(); | ||
|
||
this.parseLocaleFAQs(realData); | ||
} | ||
|
||
private parseLocaleFAQs( | ||
faqData: Record<string, Record<string, IChangelogEntry[]>> | ||
) { | ||
const baseChangelogs = this.changelogByProductIdAndLocale(); | ||
|
||
Object.keys(faqData).forEach((productId) => { | ||
baseChangelogs[productId] ??= {}; | ||
|
||
Object.keys(faqData[productId]).forEach((locale) => { | ||
baseChangelogs[productId][locale] = sortBy( | ||
faqData[productId][locale], | ||
'date' | ||
); | ||
}); | ||
}); | ||
|
||
this.changelogByProductIdAndLocale.set(baseChangelogs); | ||
} | ||
|
||
public getChangelogs(): Array<{ | ||
productId: string; | ||
locale: string; | ||
changelog: IChangelogEntry[]; | ||
}> { | ||
const changelogData = this.changelogByProductIdAndLocale(); | ||
const locale = this.localeService.currentLocale(); | ||
|
||
return Object.keys(changelogData) | ||
.map((productId) => ({ | ||
productId, | ||
locale, | ||
changelog: changelogData[productId][locale], | ||
})) | ||
.filter((p) => p.changelog) | ||
.flat(); | ||
} | ||
|
||
public getProductChangelog( | ||
productId: string, | ||
locale: string | ||
): IChangelogEntry[] | undefined { | ||
const changelog = this.changelogByProductIdAndLocale(); | ||
return changelog?.[productId]?.[locale]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { type Routes, RouterModule } from '@angular/router'; | ||
|
||
import { ChangelogPage } from './changelog.page'; | ||
|
||
const routes: Routes = [ | ||
{ | ||
path: '', | ||
component: ChangelogPage, | ||
}, | ||
]; | ||
|
||
@NgModule({ | ||
imports: [RouterModule.forChild(routes)], | ||
exports: [RouterModule], | ||
}) | ||
export class ChangelogPageRoutingModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { NgModule } from '@angular/core'; | ||
import { FormsModule } from '@angular/forms'; | ||
|
||
import { IonicModule } from '@ionic/angular'; | ||
|
||
import { ChangelogPageRoutingModule } from './changelog-routing.module'; | ||
|
||
import { SharedModule } from '../_shared/shared.module'; | ||
import { ChangelogPage } from './changelog.page'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
CommonModule, | ||
FormsModule, | ||
IonicModule, | ||
SharedModule, | ||
ChangelogPageRoutingModule, | ||
], | ||
declarations: [ChangelogPage], | ||
}) | ||
export class ChangelogPageModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<ion-header> | ||
<app-topbar [searchOnEnter]="true" [showBackButton]="!!productId()" [defaultBackLocation]="'/changelog'"></app-topbar> | ||
</ion-header> | ||
|
||
<header class="print-only print-header"> | ||
{{ changelogProductName() }} Changelog | ||
</header> | ||
|
||
<ion-content> | ||
<div class="page-container printable"> | ||
|
||
@if(productId()) { | ||
<header class="print-hide print-header"> | ||
{{ changelogProductName() }} Changelog | ||
</header> | ||
} | ||
|
||
@if(currentChangelog(); as changelog) { | ||
<ion-grid> | ||
<ion-row> | ||
<ion-col> | ||
<ion-list> | ||
@for(entry of changelog; track $index) { | ||
<ion-item> | ||
<ion-label text-wrap class="print-only"> | ||
<h3>{{ entry.date | dateTimeFromIso | dateTimeToFormat:'DDD' }}</h3> | ||
<p [innerText]="(entry.text | faq)"></p> | ||
</ion-label> | ||
|
||
<ion-label text-wrap class="print-hide"> | ||
<h3>{{ entry.date | dateTimeFromIso | dateTimeToFormat:'DDD' }}</h3> | ||
<p [innerHTML]="(entry.text | faq:productId())"></p> | ||
</ion-label> | ||
</ion-item> | ||
} | ||
</ion-list> | ||
</ion-col> | ||
</ion-row> | ||
</ion-grid> | ||
} | ||
|
||
@else { | ||
<ion-grid> | ||
<ion-row> | ||
@for(changelog of changelogs(); track $index) { | ||
<ion-col size-lg="3" size-md="4" size-sm="6" size-xs="12"> | ||
<ion-card class="changelog-tile" (click)="loadChangelog(changelog)"> | ||
<ion-card-header> | ||
<ion-card-title>{{ metaService.getProductNameByProductId(changelog.productId) }}</ion-card-title> | ||
</ion-card-header> | ||
|
||
<ion-card-content> | ||
{{ changelog.changelog.length | number }} Change(s) | ||
</ion-card-content> | ||
</ion-card> | ||
</ion-col> | ||
} | ||
</ion-row> | ||
</ion-grid> | ||
} | ||
</div> | ||
|
||
<app-below-the-fold></app-below-the-fold> | ||
</ion-content> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
.changelog-tile { | ||
min-height: 200px; | ||
padding: 4px; | ||
|
||
border: 2px solid #000; | ||
|
||
cursor: pointer; | ||
user-select: none; | ||
|
||
&:hover { | ||
border: 2px solid var(--ion-color-primary); | ||
} | ||
|
||
ion-card-content { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
|
||
font-size: 2em; | ||
padding: 1em; | ||
} | ||
} | ||
|
||
.page-container .print-header { | ||
text-align: center; | ||
|
||
margin-top: 24px; | ||
margin-bottom: 24px; | ||
|
||
font-size: 3em; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { Component, computed, inject, signal } from '@angular/core'; | ||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; | ||
import { ActivatedRoute, EventType, Router } from '@angular/router'; | ||
import { filter } from 'rxjs'; | ||
import type { IChangelogEntry } from '../../../interfaces'; | ||
import { ChangelogService } from '../changelog.service'; | ||
import { MetaService } from '../meta.service'; | ||
|
||
@Component({ | ||
selector: 'app-changelog', | ||
templateUrl: './changelog.page.html', | ||
styleUrls: ['./changelog.page.scss'], | ||
}) | ||
export class ChangelogPage { | ||
private router = inject(Router); | ||
private route = inject(ActivatedRoute); | ||
private changelogService = inject(ChangelogService); | ||
public metaService = inject(MetaService); | ||
|
||
private locale = signal<string>(''); | ||
public productId = signal<string>(''); | ||
|
||
public changelogs = computed(() => this.changelogService.getChangelogs()); | ||
public currentChangelog = computed(() => | ||
this.changelogService.getProductChangelog(this.productId(), this.locale()) | ||
); | ||
public changelogProductName = computed(() => | ||
this.metaService.getProductNameByProductId(this.productId()) | ||
); | ||
|
||
constructor() { | ||
this.router.events | ||
.pipe(takeUntilDestroyed()) | ||
.pipe(filter((evt) => evt.type === EventType.NavigationEnd)) | ||
.subscribe(() => this.parseQueryParams()); | ||
} | ||
|
||
ionViewDidEnter() { | ||
this.parseQueryParams(); | ||
|
||
if (!this.locale() || !this.productId()) { | ||
this.router.navigate(['/changelog']); | ||
return; | ||
} | ||
} | ||
|
||
loadChangelog(faq: { | ||
productId: string; | ||
locale: string; | ||
changelog: IChangelogEntry[]; | ||
}) { | ||
this.router.navigate([], { | ||
relativeTo: this.route, | ||
queryParams: { locale: faq.locale, productId: faq.productId }, | ||
queryParamsHandling: 'merge', | ||
}); | ||
|
||
this.locale.set(faq.locale); | ||
this.productId.set(faq.productId); | ||
|
||
this.parseQueryParams(); | ||
} | ||
|
||
private parseQueryParams() { | ||
const urlParams = new URLSearchParams(window.location.search); | ||
|
||
this.locale.set(urlParams.get('locale') ?? ''); | ||
this.productId.set(urlParams.get('productId') ?? ''); | ||
} | ||
} |
Oops, something went wrong.