From 8c7b2dfc79b4e1eaaf7f6074bd3888c35b1dc754 Mon Sep 17 00:00:00 2001 From: Isaac Abadi Date: Sun, 9 Aug 2020 14:08:22 -0400 Subject: [PATCH] Added ability to delete files in the recent videos component w/ archive support --- .../recent-videos.component.html | 4 +- .../recent-videos/recent-videos.component.ts | 49 ++++++++++++++----- .../unified-file-card.component.html | 8 +-- .../unified-file-card.component.ts | 12 +++-- 4 files changed, 50 insertions(+), 23 deletions(-) diff --git a/src/app/components/recent-videos/recent-videos.component.html b/src/app/components/recent-videos/recent-videos.component.html index 88a276b..48da02b 100644 --- a/src/app/components/recent-videos/recent-videos.component.html +++ b/src/app/components/recent-videos/recent-videos.component.html @@ -1,8 +1,8 @@
-
- +
+
diff --git a/src/app/components/recent-videos/recent-videos.component.ts b/src/app/components/recent-videos/recent-videos.component.ts index 9555507..7f13961 100644 --- a/src/app/components/recent-videos/recent-videos.component.ts +++ b/src/app/components/recent-videos/recent-videos.component.ts @@ -110,24 +110,23 @@ export class RecentVideosComponent implements OnInit { // deleting - deleteAndRedownload(file) { - const sub = this.postsService.getSubscriptionByID(file.sub_id); - this.postsService.deleteSubscriptionFile(sub, file.id, false, file.uid).subscribe(res => { - this.postsService.openSnackBar(`Successfully deleted file: '${file.id}'`); - }); + deleteFile(args) { + const file = args.file; + const index = args.index; + const blacklistMode = args.blacklistMode; + + if (file.sub_id) { + this.deleteSubscriptionFile(file, index, blacklistMode); + } else { + this.deleteNormalFile(file, index, blacklistMode); + } } - deleteForever(file) { - const sub = this.postsService.getSubscriptionByID(file.sub_id); - this.postsService.deleteSubscriptionFile(sub, file.id, true, file.uid).subscribe(res => { - this.postsService.openSnackBar(`Successfully deleted file: '${file.id}'`); - }); - } - - deleteNormalFile(file, blacklistMode = false) { + deleteNormalFile(file, index, blacklistMode = false) { this.postsService.deleteFile(file.uid, file.isAudio, blacklistMode).subscribe(result => { if (result) { this.postsService.openSnackBar('Delete success!', 'OK.'); + this.files.splice(index, 1); } else { this.postsService.openSnackBar('Delete failed!', 'OK.'); } @@ -136,6 +135,30 @@ export class RecentVideosComponent implements OnInit { }); } + deleteSubscriptionFile(file, index, blacklistMode = false) { + if (blacklistMode) { + this.deleteForever(file, index); + } else { + this.deleteAndRedownload(file, index); + } + } + + deleteAndRedownload(file, index) { + const sub = this.postsService.getSubscriptionByID(file.sub_id); + this.postsService.deleteSubscriptionFile(sub, file.id, false, file.uid).subscribe(res => { + this.postsService.openSnackBar(`Successfully deleted file: '${file.id}'`); + this.files.splice(index, 1); + }); + } + + deleteForever(file, index) { + const sub = this.postsService.getSubscriptionByID(file.sub_id); + this.postsService.deleteSubscriptionFile(sub, file.id, true, file.uid).subscribe(res => { + this.postsService.openSnackBar(`Successfully deleted file: '${file.id}'`); + this.files.splice(index, 1); + }); + } + // sorting and filtering sortFiles(a, b) { diff --git a/src/app/components/unified-file-card/unified-file-card.component.html b/src/app/components/unified-file-card/unified-file-card.component.html index e61e082..520eeaf 100644 --- a/src/app/components/unified-file-card/unified-file-card.component.html +++ b/src/app/components/unified-file-card/unified-file-card.component.html @@ -5,14 +5,14 @@ - - - - + +
diff --git a/src/app/components/unified-file-card/unified-file-card.component.ts b/src/app/components/unified-file-card/unified-file-card.component.ts index 7c27721..f401f88 100644 --- a/src/app/components/unified-file-card/unified-file-card.component.ts +++ b/src/app/components/unified-file-card/unified-file-card.component.ts @@ -19,8 +19,10 @@ export class UnifiedFileCardComponent implements OnInit { @Input() file_obj = null; @Input() card_size = 'medium'; @Input() use_youtubedl_archive = false; + @Input() index: number; @Output() goToFile = new EventEmitter(); @Output() goToSubscription = new EventEmitter(); + @Output() deleteFile = new EventEmitter(); /* Planned sizes: @@ -35,10 +37,12 @@ export class UnifiedFileCardComponent implements OnInit { this.file_length = fancyTimeFormat(this.file_obj.duration); } - deleteFile(blacklistMode = false) { - if (this.file_obj.sub_id) { - - } + emitDeleteFile(blacklistMode = false) { + this.deleteFile.emit({ + file: this.file_obj, + index: this.index, + blacklistMode: blacklistMode + }); } navigateToFile() {