Commit 6890774c authored by Ben Hayward's avatar Ben Hayward Committed by Mark Harding

[Spring/HipsterHedgehog](feat) Discard changes when creating and editing blogs #349

parent 11d489fa
......@@ -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 || !window.Minds.user) {
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