Display changelog from current version to latest upon clicking the update link

This commit is contained in:
adityachandelgit
2025-04-19 00:07:13 -06:00
committed by Aditya Chandel
parent b708976c1b
commit 6af3ee7019
15 changed files with 320 additions and 60 deletions
@@ -8,6 +8,13 @@ export interface AppVersion {
latest: string;
}
export interface ReleaseNote {
version: string;
name: string;
changelog: string;
url: string;
}
@Injectable({
providedIn: 'root'
})
@@ -19,4 +26,8 @@ export class VersionService {
getVersion(): Observable<AppVersion> {
return this.http.get<AppVersion>(this.versionUrl);
}
getChangelog(): Observable<ReleaseNote[]> {
return this.http.get<ReleaseNote[]>(`${this.versionUrl}/changelog`);
}
}
@@ -42,10 +42,8 @@
</div>
<div *ngIf="versionInfo.latest && versionInfo.latest !== versionInfo.current">
<a
[href]="getVersionUrl(versionInfo.latest)"
target="_blank"
rel="noopener noreferrer"
class="text-orange-400 hover:underline hover:text-orange-300 text-xs"
(click)="openChangelogDialog()"
class="cursor-pointer text-orange-400 hover:underline hover:text-orange-300 text-xs"
>
(Update)
</a>
@@ -9,6 +9,8 @@ import {ShelfService} from '../../../book/service/shelf.service';
import {BookService} from '../../../book/service/book.service';
import {LibraryShelfMenuService} from '../../../book/service/library-shelf-menu.service';
import {AppVersion, VersionService} from '../../../core/service/version.service';
import {DialogService, DynamicDialogRef} from 'primeng/dynamicdialog';
import {VersionChangelogDialogComponent} from './version-changelog-dialog/version-changelog-dialog.component';
@Component({
selector: 'app-menu',
@@ -21,12 +23,15 @@ export class AppMenuComponent implements OnInit {
homeMenu$: Observable<any> | undefined;
versionInfo: AppVersion | null = null;
dynamicDialogRef: DynamicDialogRef | undefined;
private libraryService = inject(LibraryService);
private shelfService = inject(ShelfService);
private bookService = inject(BookService);
private versionService = inject(VersionService);
private libraryShelfMenuService = inject(LibraryShelfMenuService);
private dialogService = inject(DialogService);
ngOnInit(): void {
@@ -94,6 +99,20 @@ export class AppMenuComponent implements OnInit {
);
}
openChangelogDialog() {
this.dynamicDialogRef = this.dialogService.open(VersionChangelogDialogComponent, {
header: 'What’s New',
modal: true,
closable: true,
style: {
position: 'absolute',
top: '10%',
bottom: '10%',
minWidth: '800px',
},
});
}
getVersionUrl(version: string | undefined): string {
if (!version) return '#';
if (version.startsWith('v')) {
@@ -0,0 +1,18 @@
<div *ngIf="loading" class="p-4 text-center text-gray-400">
Loading changelog...
</div>
<div *ngIf="!loading && changelog.length === 0" class="p-4 text-center text-gray-400">
No updates available.
</div>
<div *ngIf="!loading && changelog.length > 0" class="space-y-6 p-4 max-h-[70vh] overflow-auto">
<div *ngFor="let release of changelog" class="border-b pb-4">
<p class="font-bold text-2xl pb-2">
<a [href]="release.url" target="_blank" rel="noopener noreferrer" class="text-blue-400 hover:underline">
{{ release.name }}
</a>
</p>
<div [innerHTML]="markdownToHtml(release.changelog)" class="prose prose-invert w-full max-w-full"></div>
</div>
</div>
@@ -0,0 +1,3 @@
:host ::ng-deep .prose h3 {
margin-top: 0px;
}
@@ -0,0 +1,41 @@
import { Component, inject, OnInit } from '@angular/core';
import { ReleaseNote, VersionService } from '../../../../core/service/version.service';
import { NgForOf, NgIf } from '@angular/common';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
import showdown from 'showdown';
@Component({
selector: 'app-version-changelog-dialog',
standalone: true,
imports: [NgIf, NgForOf],
templateUrl: './version-changelog-dialog.component.html',
styleUrl: './version-changelog-dialog.component.scss'
})
export class VersionChangelogDialogComponent implements OnInit {
private versionService = inject(VersionService);
private sanitizer = inject(DomSanitizer);
changelog: ReleaseNote[] = [];
loading = true;
private converter = new showdown.Converter({ tables: true, emoji: true });
ngOnInit(): void {
this.versionService.getChangelog().subscribe({
next: (data) => {
this.changelog = data;
this.loading = false;
},
error: () => {
this.loading = false;
}
});
}
markdownToHtml(markdown: string): SafeHtml {
let html = this.converter.makeHtml(markdown);
html = html.replace(/<h2\b([^>]*)>/g, '<h3$1>').replace(/<\/h2>/g, '</h3>');
return this.sanitizer.bypassSecurityTrustHtml(html);
}
}
+14 -14
View File
@@ -1,18 +1,18 @@
import { provideHttpClient, withInterceptors } from '@angular/common/http';
import { DialogService } from 'primeng/dynamicdialog';
import { ConfirmationService, MessageService } from 'primeng/api';
import { RxStompService } from './app/shared/websocket/rx-stomp.service';
import { rxStompServiceFactory } from './app/shared/websocket/rx-stomp-service-factory';
import { provideRouter, RouteReuseStrategy } from '@angular/router';
import { CustomReuseStrategy } from './app/custom-reuse-strategy';
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
import { providePrimeNG } from 'primeng/config';
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app/app.component';
import {provideHttpClient, withInterceptors} from '@angular/common/http';
import {DialogService} from 'primeng/dynamicdialog';
import {ConfirmationService, MessageService} from 'primeng/api';
import {RxStompService} from './app/shared/websocket/rx-stomp.service';
import {rxStompServiceFactory} from './app/shared/websocket/rx-stomp-service-factory';
import {provideRouter, RouteReuseStrategy} from '@angular/router';
import {CustomReuseStrategy} from './app/custom-reuse-strategy';
import {provideAnimationsAsync} from '@angular/platform-browser/animations/async';
import {providePrimeNG} from 'primeng/config';
import {bootstrapApplication} from '@angular/platform-browser';
import {AppComponent} from './app/app.component';
import Aura from '@primeng/themes/aura';
import { routes } from './app/app.routes';
import { AuthInterceptorService } from './app/auth-interceptor.service';
import { AuthService } from './app/core/service/auth.service';
import {routes} from './app/app.routes';
import {AuthInterceptorService} from './app/auth-interceptor.service';
import {AuthService} from './app/core/service/auth.service';
bootstrapApplication(AppComponent, {
providers: [