Skip to content

Commit f6141fb

Browse files
authored
Fix UI not refreshing on delete decision (#40)
* fix(workspace): resolve loading/spinning issue on workspace creation * Fix UI not refreshing on delete decision and add error handling
1 parent 46be505 commit f6141fb

3 files changed

Lines changed: 82 additions & 7 deletions

File tree

src/app/components/decision-list/decision-list.component.css

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,45 @@
129129
padding: 2px 6px;
130130
border-radius: 4px;
131131
}
132+
133+
.error-banner {
134+
background-color: #fee2e2;
135+
color: #b91c1c;
136+
padding: 12px 16px;
137+
border-radius: 8px;
138+
margin-bottom: 16px;
139+
border: 1px solid #fecaca;
140+
font-size: 14px;
141+
}
142+
143+
.empty-state {
144+
padding: 48px;
145+
text-align: center;
146+
background: #f9f9f9;
147+
border-radius: 12px;
148+
border: 2px dashed #e5e5e5;
149+
color: #666;
150+
}
151+
152+
.loading-state {
153+
padding: 40px;
154+
text-align: center;
155+
color: #666;
156+
display: flex;
157+
flex-direction: column;
158+
align-items: center;
159+
gap: 12px;
160+
}
161+
162+
.spinner {
163+
width: 24px;
164+
height: 24px;
165+
border: 2px solid #e5e5e5;
166+
border-top-color: #0a0a0a;
167+
border-radius: 50%;
168+
animation: spin 0.8s linear infinite;
169+
}
170+
171+
@keyframes spin {
172+
to { transform: rotate(360deg); }
173+
}

src/app/components/decision-list/decision-list.component.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ <h2>Decisions</h2>
77
</div>
88
</div>
99

10+
<div *ngIf="error" class="error-banner">
11+
{{ error }}
12+
</div>
13+
14+
<div *ngIf="!(decisions$ | async) && !error" class="loading-state">
15+
<span class="spinner"></span> Loading decisions...
16+
</div>
17+
1018
<div class="decision-list" *ngIf="decisions$ | async as decisions">
1119
<div *ngIf="decisions.length === 0" class="empty-state">
1220
No decisions found. Create one to get started!

src/app/components/decision-list/decision-list.component.ts

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component, OnInit, OnDestroy } from '@angular/core';
22
import { CommonModule } from '@angular/common';
33
import { ActivatedRoute, RouterModule } from '@angular/router';
44
import { Decision } from '../../models/decision.model';
55
import { DecisionService } from '../../services/decision.service';
6-
import { Observable } from 'rxjs';
6+
import { Observable, Subject, takeUntil, startWith, switchMap, catchError, of } from 'rxjs';
77

88
@Component({
99
selector: 'app-decision-list',
@@ -12,8 +12,11 @@ import { Observable } from 'rxjs';
1212
templateUrl: './decision-list.component.html',
1313
styleUrls: ['./decision-list.component.css']
1414
})
15-
export class DecisionListComponent implements OnInit {
15+
export class DecisionListComponent implements OnInit, OnDestroy {
1616
decisions$: Observable<Decision[]> | undefined;
17+
error: string | null = null;
18+
private refresh$ = new Subject<void>();
19+
private destroy$ = new Subject<void>();
1720
private workspaceId: string | null = null;
1821

1922
constructor(
@@ -24,15 +27,37 @@ export class DecisionListComponent implements OnInit {
2427
ngOnInit(): void {
2528
this.workspaceId = this.getWorkspaceIdFromRoute();
2629
if (this.workspaceId) {
27-
this.decisions$ = this.decisionService.getDecisions(this.workspaceId);
30+
this.decisions$ = this.refresh$.pipe(
31+
startWith(undefined),
32+
switchMap(() => this.decisionService.getDecisions(this.workspaceId!).pipe(
33+
catchError(err => {
34+
this.error = 'Failed to load decisions. Please try again.';
35+
return of([]);
36+
})
37+
))
38+
);
2839
}
2940
}
3041

42+
ngOnDestroy(): void {
43+
this.destroy$.next();
44+
this.destroy$.complete();
45+
}
46+
3147
deleteDecision(id: string): void {
3248
if (confirm('Are you sure you want to delete this decision?') && this.workspaceId) {
33-
this.decisionService.deleteDecision(this.workspaceId, id).subscribe(() => {
34-
this.decisions$ = this.decisionService.getDecisions(this.workspaceId!);
35-
});
49+
this.error = null;
50+
this.decisionService.deleteDecision(this.workspaceId, id)
51+
.pipe(takeUntil(this.destroy$))
52+
.subscribe({
53+
next: () => {
54+
this.refresh$.next();
55+
},
56+
error: (err) => {
57+
console.error('Delete failed', err);
58+
this.error = 'Failed to delete decision. Please try again.';
59+
}
60+
});
3661
}
3762
}
3863

0 commit comments

Comments
 (0)