Refactor issue detail editing: streamline input handling and remove editing mode logic
This commit is contained in:
@@ -13,10 +13,9 @@ export class IssueDetail {
|
||||
private readonly route = inject(ActivatedRoute);
|
||||
private readonly router = inject(Router);
|
||||
private readonly issuesStore = inject(IssuesStore);
|
||||
private readonly isNewIssueRoute = this.route.snapshot.routeConfig?.path === 'issues/new';
|
||||
|
||||
protected issue: IssueEntity = this.buildIssue();
|
||||
protected isEditing = this.route.snapshot.queryParamMap.get('mode') === 'edit';
|
||||
private issueBeforeEdit: IssueEntity | null = null;
|
||||
protected readonly issues = this.issuesStore.issues;
|
||||
protected moreMenuOpen = false;
|
||||
|
||||
@@ -60,30 +59,11 @@ export class IssueDetail {
|
||||
this.issue.type = value;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
if (this.isEditing) {
|
||||
this.issueBeforeEdit = this.cloneIssue(this.issue);
|
||||
}
|
||||
}
|
||||
|
||||
protected startEdit(): void {
|
||||
this.issueBeforeEdit = this.cloneIssue(this.issue);
|
||||
this.isEditing = true;
|
||||
this.closeMoreMenu();
|
||||
}
|
||||
|
||||
protected cancelEdit(): void {
|
||||
if (this.issueBeforeEdit) {
|
||||
this.issue = this.cloneIssue(this.issueBeforeEdit);
|
||||
}
|
||||
this.isEditing = false;
|
||||
}
|
||||
|
||||
protected saveIssue(): void {
|
||||
this.issuesStore.upsert(this.issue);
|
||||
this.issueBeforeEdit = this.cloneIssue(this.issue);
|
||||
this.isEditing = false;
|
||||
this.router.navigate(['/issues', this.issue.id]);
|
||||
if (this.isNewIssueRoute) {
|
||||
this.router.navigate(['/issues', this.issue.id]);
|
||||
}
|
||||
}
|
||||
|
||||
protected deleteIssue(): void {
|
||||
@@ -120,9 +100,6 @@ export class IssueDetail {
|
||||
return this.issues().filter((issue) => issue.id !== this.issue.id);
|
||||
}
|
||||
|
||||
private cloneIssue(issue: IssueEntity): IssueEntity {
|
||||
return { ...issue };
|
||||
}
|
||||
|
||||
private buildIssue(): IssueEntity {
|
||||
const idParam = this.route.snapshot.paramMap.get('id');
|
||||
|
||||
Reference in New Issue
Block a user