Commit a2859ce2 authored by Ben Hayward's avatar Ben Hayward

added confirmation of leave on blog editing

1 merge request!398[Spring/HipsterHedgehog](feat) Discard changes when creating and editing blogs #349
Pipeline #69007693 failed with stages
in 8 minutes and 11 seconds
......@@ -17,8 +17,7 @@ export class DialogService {
* Returns observable resolving to `true`=confirm or `false`=cancel
*/
confirm(message?: string): Observable<boolean> {
const confirmation = window.confirm(message || 'Is it OK?');
return of(confirmation);
const confirmation = window.confirm(message || 'Is it OK?');
return of(confirmation);
};
}
......@@ -17,11 +17,12 @@ import { BlogTileComponent } from './tile/tile.component';
import { WireModule } from '../wire/wire.module';
import { CommentsModule } from '../comments/comments.module';
import { HashtagsModule } from '../hashtags/hashtags.module';
import { CanDeactivateGuardService } from '../../services/can-deactivate-guard';
const routes: Routes = [
{ path: 'blog/view/:guid/:title', component: BlogViewInfinite },
{ path: 'blog/view/:guid', component: BlogViewInfinite },
{ path: 'blog/edit/:guid', component: BlogEdit },
{ path: 'blog/edit/:guid', component: BlogEdit, canDeactivate: [CanDeactivateGuardService]},
{ path: 'blog/:filter', component: BlogListComponent },
{ path: 'blog', redirectTo: '/blog/top', pathMatch: 'full' },
{ path: ':username/blog/:slugid', component: BlogViewInfinite },
......
import { Component, ViewChild } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Subscription } from 'rxjs';
import { Subscription, Observable } from 'rxjs';
import { MindsTitle } from '../../../services/ux/title';
import { ACCESS, LICENSES } from '../../../services/list-options';
......@@ -12,6 +12,7 @@ import { WireThresholdInputComponent } from '../../wire/threshold-input/threshol
import { HashtagsSelectorComponent } from '../../hashtags/selector/selector.component';
import { Tag } from '../../hashtags/types/tag';
import { InMemoryStorageService } from "../../../services/in-memory-storage.service";
import { DialogService } from "../../../common/services/confirm-leave-dialog.service";
@Component({
moduleId: module.id,
......@@ -74,7 +75,8 @@ export class BlogEdit {
public router: Router,
public route: ActivatedRoute,
public title: MindsTitle,
protected inMemoryStorageService: InMemoryStorageService
protected inMemoryStorageService: InMemoryStorageService,
private dialogService: DialogService,
) {
this.getCategories();
......@@ -148,6 +150,14 @@ export class BlogEdit {
});
}
canDeactivate(): Observable<boolean> | boolean {
if (!this.editing) {
return true;
}
return this.dialogService.confirm('Discard changes?');
}
ngOnDestroy() {
if (this.paramsSubscription) {
this.paramsSubscription.unsubscribe();
......@@ -232,6 +242,7 @@ export class BlogEdit {
blog.mature = blog.mature ? 1: 0;
blog.monetization = blog.monetization ? 1: 0;
blog.monetized = blog.monetized ? 1: 0;
this.editing = false;
this.inProgress = true;
this.canSave = false;
this.check_for_banner().then(() => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment