refactor: always navigate, rm edit/add scren from history stack

This commit is contained in:
2026-02-16 17:25:58 -03:00
parent 7de993a765
commit 836c6652ec

View File

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