Edit and delete
This commit is contained in:
parent
5f7968a756
commit
ac266e77ce
@ -4,6 +4,7 @@ import {FormsModule} from '@angular/forms';
|
|||||||
import {ShowService} from '../../services/show.service';
|
import {ShowService} from '../../services/show.service';
|
||||||
import {Observable} from 'rxjs';
|
import {Observable} from 'rxjs';
|
||||||
import {AsyncPipe} from '@angular/common';
|
import {AsyncPipe} from '@angular/common';
|
||||||
|
import {deleteDoc, doc, Firestore, updateDoc} from '@angular/fire/firestore';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-show-list',
|
selector: 'app-show-list',
|
||||||
@ -17,6 +18,8 @@ import {AsyncPipe} from '@angular/common';
|
|||||||
})
|
})
|
||||||
export class ShowListComponent {
|
export class ShowListComponent {
|
||||||
showService: ShowService = inject(ShowService);
|
showService: ShowService = inject(ShowService);
|
||||||
|
fireStore: Firestore = inject(Firestore);
|
||||||
|
private seriesCollection = 'table_show';
|
||||||
shows: Observable<Show[]> = this.showService.getShows();
|
shows: Observable<Show[]> = this.showService.getShows();
|
||||||
|
|
||||||
@Output() selectedShow = new EventEmitter<Show>();
|
@Output() selectedShow = new EventEmitter<Show>();
|
||||||
@ -37,13 +40,13 @@ export class ShowListComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateShow(show: Show) {
|
updateShow(show: Show) {
|
||||||
// this.shows = this.shows.filter(s => s !== show);
|
const showDocRef = doc(this.fireStore, `${this.seriesCollection}/${show.uid}`);
|
||||||
// this.shows.push(show);
|
updateDoc(showDocRef, {id: show.uid, title: show.title,});
|
||||||
// this.shows.sort((a, b) => (a.uid ?? 0) - (b.uid ?? 0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
delete(show: Show) {
|
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 {
|
isToEdit(show: Show): boolean {
|
||||||
|
Reference in New Issue
Block a user