From ac266e77cea71d4a4691925a1af89b287c859a2c Mon Sep 17 00:00:00 2001
From: Phan Huy Tran
Date: Wed, 20 Nov 2024 12:47:12 +0100
Subject: [PATCH] Edit and delete
---
src/app/components/show-list/show-list.component.ts | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/src/app/components/show-list/show-list.component.ts b/src/app/components/show-list/show-list.component.ts
index 398397b..4b61511 100644
--- a/src/app/components/show-list/show-list.component.ts
+++ b/src/app/components/show-list/show-list.component.ts
@@ -4,6 +4,7 @@ import {FormsModule} from '@angular/forms';
import {ShowService} from '../../services/show.service';
import {Observable} from 'rxjs';
import {AsyncPipe} from '@angular/common';
+import {deleteDoc, doc, Firestore, updateDoc} from '@angular/fire/firestore';
@Component({
selector: 'app-show-list',
@@ -17,6 +18,8 @@ import {AsyncPipe} from '@angular/common';
})
export class ShowListComponent {
showService: ShowService = inject(ShowService);
+ fireStore: Firestore = inject(Firestore);
+ private seriesCollection = 'table_show';
shows: Observable = this.showService.getShows();
@Output() selectedShow = new EventEmitter();
@@ -37,13 +40,13 @@ export class ShowListComponent {
}
updateShow(show: Show) {
- // this.shows = this.shows.filter(s => s !== show);
- // this.shows.push(show);
- // this.shows.sort((a, b) => (a.uid ?? 0) - (b.uid ?? 0));
+ const showDocRef = doc(this.fireStore, `${this.seriesCollection}/${show.uid}`);
+ updateDoc(showDocRef, {id: show.uid, title: show.title,});
}
delete(show: Show) {
- // this.shows = this.shows.filter(s => s !== show);
+ const showDocRef = doc(this.fireStore, `${this.seriesCollection}/${show.uid}`);
+ deleteDoc(showDocRef);
}
isToEdit(show: Show): boolean {