Skip to content

Commit 93e18ff

Browse files
committed
feat(web): UpdateModule for letting the user to be notified about new app version
1 parent 10392d8 commit 93e18ff

14 files changed

Lines changed: 179 additions & 3 deletions

apps/web/ngsw-config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
"index": "/index.html",
3+
"appData": {
4+
"version": "",
5+
"changelog": ""
6+
},
37
"assetGroups": [
48
{
59
"name": "app",

apps/web/src/app/app.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<div style="text-align:center">
22
<h1>Welcome to {{title}}!</h1>
3+
<h2>4</h2>
34
<img
45
width="300"
56
src="https://slackmap.com/assets/logo.svg"

apps/web/src/app/app.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ import { RouterModule } from '@angular/router';
66
import { ServiceWorkerModule } from '@angular/service-worker';
77
import { environment } from '../environments/environment';
88
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
9+
import { UpdateModule } from './update';
910

1011
@NgModule({
1112
declarations: [AppComponent],
1213
imports: [
1314
BrowserModule.withServerTransition({ appId: 'serverApp' }),
1415
RouterModule.forRoot([], { initialNavigation: 'enabled' }),
1516
ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production }),
16-
BrowserAnimationsModule
17+
BrowserAnimationsModule,
18+
UpdateModule
1719
],
1820
providers: [],
1921
bootstrap: [AppComponent]

apps/web/src/app/update/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './update.module';
2+
export * from './update.service';
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<h2 mat-dialog-title>New version available</h2>
2+
<mat-dialog-content class="mat-typography">
3+
<h3>Update now ??</h3>
4+
<p>
5+
Your version <b>{{data.current?.appData?.version || 0}}</b> available <b>{{data.available?.appData?.version || 0}}</b>
6+
</p>
7+
<p *ngIf="data.current?.appData?.changelog">
8+
Changes: {{data.current?.appData?.changelog}}
9+
</p>
10+
</mat-dialog-content>
11+
<mat-dialog-actions align="end">
12+
<button mat-button mat-dialog-close>Not now, later</button>
13+
<button mat-button [mat-dialog-close]="true" cdkFocusInitial>Install & Reload</button>
14+
</mat-dialog-actions>

tools/schematics/.gitkeep renamed to apps/web/src/app/update/update-dialog/update-dialog.component.scss

File renamed without changes.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { UpdateDialogComponent } from './update-dialog.component';
4+
5+
describe('UpdateDialogComponent', () => {
6+
let component: UpdateDialogComponent;
7+
let fixture: ComponentFixture<UpdateDialogComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ UpdateDialogComponent ]
12+
})
13+
.compileComponents();
14+
}));
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(UpdateDialogComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { Component, OnInit, Inject } from '@angular/core';
2+
import {MatDialogRef, MAT_DIALOG_DATA} from '@angular/material';
3+
4+
export interface Version {
5+
hash: string;
6+
appData?: any;
7+
}
8+
export interface UpdateAvailableEvent {
9+
type: 'UPDATE_AVAILABLE';
10+
current: Version;
11+
available: Version;
12+
}
13+
14+
@Component({
15+
selector: 'sm-update-dialog',
16+
templateUrl: './update-dialog.component.html',
17+
styleUrls: ['./update-dialog.component.scss']
18+
})
19+
export class UpdateDialogComponent implements OnInit {
20+
21+
constructor(
22+
public dialogRef: MatDialogRef<UpdateDialogComponent>,
23+
@Inject(MAT_DIALOG_DATA) public data: UpdateAvailableEvent) {}
24+
25+
onNoClick(): void {
26+
this.dialogRef.close();
27+
}
28+
ngOnInit() {
29+
}
30+
31+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { NgModule } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
3+
import { UpdateService } from './update.service';
4+
import { UpdateDialogComponent } from './update-dialog/update-dialog.component';
5+
import { MatDialogModule } from '@angular/material';
6+
7+
@NgModule({
8+
imports: [
9+
CommonModule,
10+
MatDialogModule
11+
],
12+
declarations: [UpdateDialogComponent],
13+
entryComponents: [UpdateDialogComponent]
14+
})
15+
export class UpdateModule {
16+
constructor(service: UpdateService) {
17+
18+
}
19+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { TestBed } from '@angular/core/testing';
2+
3+
import { UpdateService } from './update.service';
4+
5+
describe('UpdateService', () => {
6+
beforeEach(() => TestBed.configureTestingModule({}));
7+
8+
it('should be created', () => {
9+
const service: UpdateService = TestBed.get(UpdateService);
10+
expect(service).toBeTruthy();
11+
});
12+
});

0 commit comments

Comments
 (0)