Skip to content

Commit 42683e3

Browse files
ert78gbmondalaci
authored andcommitted
feat(notification): Add undoable notification, close #318 (#338)
* feat(notification): Add undoable notification * feat(notification): Add undoable notification * feat(notification): Use uhk-header to the notification * half ready solution * - fix: "Keymap has been deleted" is displayed for macros. - When a keymap/macro deletion gets undone, please set the route of the restored keymap/macro. - When the user switches to another route, please make the undo notification disappear. * fix(keymap): Store prev user configuration in the application reducer Store the previous state in application reducer, because refactoring the user-config reducer is not easy * feat(keymap): Fix review request
1 parent ce55cac commit 42683e3

File tree

19 files changed

+295
-64
lines changed

19 files changed

+295
-64
lines changed

electron/src/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ import { AppUpdateRendererService } from './services/app-update-renderer.service
106106
import { reducer } from './store';
107107
import { AutoUpdateSettings } from './shared/components/auto-update-settings/auto-update-settings';
108108
import { angularNotifierConfig } from './shared/models/angular-notifier-config';
109+
import { UndoableNotifierComponent } from './shared/components/undoable-notifier';
109110
import { UhkHeader } from './shared/components/uhk-header/uhk-header';
110111
import { AppRendererService } from './services/app-renderer.service';
111112

@@ -166,6 +167,7 @@ import { AppRendererService } from './services/app-renderer.service';
166167
SafeStylePipe,
167168
UpdateAvailableComponent,
168169
AutoUpdateSettings,
170+
UndoableNotifierComponent,
169171
UhkHeader
170172
],
171173
imports: [

shared/src/components/macro/edit/macro-edit.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414

1515
<div *ngIf="!macro" class="not-found">
1616
There is no macro with id {{ route.params.select('id') | async }}.
17-
</div>
17+
</div>
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
<uhk-header></uhk-header>
2-
<div class="not-found">
3-
You don't have any macros. Try to add one!
1+
<div class="container-fluid">
2+
<uhk-header>
3+
<h1>&nbsp;</h1>
4+
</uhk-header>
5+
<div class="not-found">
6+
You don't have any macros. Try to add one!
7+
</div>
48
</div>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
<div>
22
<ng-content></ng-content>
33
</div>
4+
<div class="row">
5+
<div class="col-xs-12">
6+
<undoable-notifier [notification]="undoableNotification$ | async"
7+
(close)="onDismissLastNotification()"
8+
(undo)="onUndoLastNotification($event)">
9+
</undoable-notifier>
10+
</div>
11+
</div>
12+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
11
import { ChangeDetectionStrategy, Component } from '@angular/core';
2+
import { Store } from '@ngrx/store';
3+
import { Observable } from 'rxjs/Observable';
4+
5+
import { Notification } from '../../models/notification';
6+
import { AppState, getUndoableNotification } from '../../store/index';
7+
import { DismissUndoNotificationAction, UndoLastAction } from '../../store/actions/app.action';
28

39
@Component({
410
selector: 'uhk-header',
511
templateUrl: './uhk-header.html',
612
changeDetection: ChangeDetectionStrategy.OnPush
713
})
814
export class UhkHeader {
15+
undoableNotification$: Observable<Notification>;
16+
17+
constructor(private store: Store<AppState>) {
18+
this.undoableNotification$ = this.store.select(getUndoableNotification);
19+
}
20+
21+
onUndoLastNotification(data: any): void {
22+
this.store.dispatch(new UndoLastAction(data));
23+
}
24+
25+
onDismissLastNotification(): void {
26+
this.store.dispatch(new DismissUndoNotificationAction());
27+
}
28+
929
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './undoable-notifier.component';
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<div class="pull-right">
2+
<div class="alert alert-warning alert-dismissible" role="alert" [@slideInOut]="slideInOut">
3+
<button type="button"
4+
class="close"
5+
aria-label="Close"
6+
(click)="clickOnClose()">
7+
<span aria-hidden="true">&times;</span>
8+
</button>
9+
{{text}}
10+
<a *ngIf="undoable" (click)="clickOnUndo()" class="undo-button">Undo</a>
11+
</div>
12+
</div>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.alert {
2+
padding: 5px 10px 5px 5px;
3+
4+
margin-bottom: 0.25em;
5+
margin-top: -2em;
6+
7+
.close {
8+
right: -5px;
9+
}
10+
.undo-button {
11+
cursor: pointer;
12+
}
13+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnChanges, Output, SimpleChanges } from '@angular/core';
2+
import { animate, state, style, transition, trigger } from '@angular/animations';
3+
4+
import { Notification } from '../../models/notification';
5+
6+
@Component({
7+
selector: 'undoable-notifier',
8+
templateUrl: './undoable-notifier.component.html',
9+
styleUrls: ['./undoable-notifier.component.scss'],
10+
changeDetection: ChangeDetectionStrategy.OnPush,
11+
animations: [
12+
trigger('slideInOut', [
13+
state('in', style({
14+
transform: 'translate3d(0, 0, 0)'
15+
})),
16+
state('out', style({
17+
transform: 'translate3d(200%, 0, 0)'
18+
})),
19+
transition('in => out', animate('400ms ease-in-out')),
20+
transition('out => in', animate('400ms ease-in-out'))
21+
])
22+
]
23+
})
24+
export class UndoableNotifierComponent implements OnChanges {
25+
text: string;
26+
undoable: boolean;
27+
@Input() notification: Notification;
28+
@Output() close = new EventEmitter();
29+
@Output() undo = new EventEmitter();
30+
31+
get slideInOut() {
32+
return this.notification ? 'in' : 'out';
33+
}
34+
35+
ngOnChanges(changes: SimpleChanges): void {
36+
if (changes['notification']) {
37+
const not: Notification = changes['notification'].currentValue;
38+
if (not) {
39+
this.text = not.message;
40+
this.undoable = !!not.extra;
41+
}
42+
}
43+
}
44+
45+
clickOnClose(): void {
46+
this.close.emit();
47+
}
48+
49+
clickOnUndo(): void {
50+
this.undo.emit(this.notification.extra);
51+
}
52+
}

shared/src/models/notification.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1+
import { Action } from '@ngrx/store';
2+
13
export enum NotificationType {
2-
Default,
3-
Success,
4-
Error,
5-
Warning,
6-
Info
4+
Default = 'default',
5+
Success = 'success',
6+
Error = 'error',
7+
Warning = 'warning',
8+
Info = 'info',
9+
Undoable = 'undoable'
710
}
811

912
export interface Notification {
1013
type: NotificationType;
1114
title?: string;
1215
message: string;
13-
extra?: any;
16+
extra?: Action;
1417
}

0 commit comments

Comments
 (0)