refactor: always navigate, rm edit/add scren from history stack
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import { Location } from '@angular/common';
|
||||
import { Router } from '@angular/router';
|
||||
|
||||
import { ChainDAO } from '../dao/ChainDAO';
|
||||
import { ImageStorage } from './image-storage';
|
||||
import { Router } from '@angular/router';
|
||||
import { Chain } from '../models/Chain';
|
||||
|
||||
@Injectable({
|
||||
@@ -11,6 +13,7 @@ export class ChainSettings {
|
||||
private readonly chainDAO = inject(ChainDAO);
|
||||
private readonly imageStorage = inject(ImageStorage);
|
||||
private readonly router = inject(Router);
|
||||
private readonly location = inject(Location);
|
||||
|
||||
async save(chain: Chain, img: File | null) {
|
||||
try {
|
||||
@@ -19,11 +22,12 @@ export class ChainSettings {
|
||||
chain.image = imgFileName;
|
||||
}
|
||||
await this.chainDAO.insert(chain);
|
||||
this.router.navigate(['settings', 'chains']);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
//TODO: report problem
|
||||
}
|
||||
this.router.navigate(['settings', 'chains']);
|
||||
this.location.replaceState('settings');
|
||||
}
|
||||
|
||||
async update(prevChain: Chain, updatedChain: Chain, img: File | null) {
|
||||
@@ -39,10 +43,11 @@ export class ChainSettings {
|
||||
}
|
||||
}
|
||||
await this.chainDAO.update(updatedChain, { id: updatedChain.id });
|
||||
this.router.navigate(['settings', 'chains']);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
//TODO: report problem
|
||||
}
|
||||
this.router.navigate(['settings', 'chains']);
|
||||
this.location.replaceState('settings');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user