mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-04-09 12:21:28 +03:00
Made file card deletion much more reliable by finding out the index of the file on deletion rather than attempting to maintain a valid index
This commit is contained in:
@@ -131,7 +131,6 @@ export class RecentVideosComponent implements OnInit {
|
|||||||
for (let i = 0; i < this.files.length; i++) {
|
for (let i = 0; i < this.files.length; i++) {
|
||||||
const file = this.files[i];
|
const file = this.files[i];
|
||||||
file.duration = typeof file.duration !== 'string' ? file.duration : this.durationStringToNumber(file.duration);
|
file.duration = typeof file.duration !== 'string' ? file.duration : this.durationStringToNumber(file.duration);
|
||||||
file.index = i;
|
|
||||||
}
|
}
|
||||||
if (this.search_mode) {
|
if (this.search_mode) {
|
||||||
this.filterFiles(this.search_text);
|
this.filterFiles(this.search_text);
|
||||||
@@ -239,22 +238,17 @@ export class RecentVideosComponent implements OnInit {
|
|||||||
const blacklistMode = args.blacklistMode;
|
const blacklistMode = args.blacklistMode;
|
||||||
|
|
||||||
if (file.sub_id) {
|
if (file.sub_id) {
|
||||||
this.deleteSubscriptionFile(file, index, blacklistMode);
|
this.deleteSubscriptionFile(file, blacklistMode);
|
||||||
} else {
|
} else {
|
||||||
this.deleteNormalFile(file, index, blacklistMode);
|
this.deleteNormalFile(file, blacklistMode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteNormalFile(file, index, blacklistMode = false) {
|
deleteNormalFile(file, blacklistMode = false) {
|
||||||
this.postsService.deleteFile(file.uid, file.isAudio ? 'audio' : 'video', blacklistMode).subscribe(result => {
|
this.postsService.deleteFile(file.uid, file.isAudio ? 'audio' : 'video', blacklistMode).subscribe(result => {
|
||||||
if (result) {
|
if (result) {
|
||||||
this.postsService.openSnackBar('Delete success!', 'OK.');
|
this.postsService.openSnackBar('Delete success!', 'OK.');
|
||||||
this.files.splice(file.index, 1);
|
this.removeFileCard(file);
|
||||||
for (let i = 0; i < this.files.length; i++) { this.files[i].index = i }
|
|
||||||
if (this.search_mode) {
|
|
||||||
this.filterFiles(this.search_text);
|
|
||||||
}
|
|
||||||
this.filterByProperty(this.filterProperty['property']);
|
|
||||||
} else {
|
} else {
|
||||||
this.postsService.openSnackBar('Delete failed!', 'OK.');
|
this.postsService.openSnackBar('Delete failed!', 'OK.');
|
||||||
}
|
}
|
||||||
@@ -263,30 +257,40 @@ export class RecentVideosComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteSubscriptionFile(file, index, blacklistMode = false) {
|
deleteSubscriptionFile(file, blacklistMode = false) {
|
||||||
if (blacklistMode) {
|
if (blacklistMode) {
|
||||||
this.deleteForever(file, index);
|
this.deleteForever(file);
|
||||||
} else {
|
} else {
|
||||||
this.deleteAndRedownload(file, index);
|
this.deleteAndRedownload(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteAndRedownload(file, index) {
|
deleteAndRedownload(file) {
|
||||||
const sub = this.postsService.getSubscriptionByID(file.sub_id);
|
const sub = this.postsService.getSubscriptionByID(file.sub_id);
|
||||||
this.postsService.deleteSubscriptionFile(sub, file.id, false, file.uid).subscribe(res => {
|
this.postsService.deleteSubscriptionFile(sub, file.id, false, file.uid).subscribe(res => {
|
||||||
this.postsService.openSnackBar(`Successfully deleted file: '${file.id}'`);
|
this.postsService.openSnackBar(`Successfully deleted file: '${file.id}'`);
|
||||||
this.files.splice(index, 1);
|
this.removeFileCard(file);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteForever(file, index) {
|
deleteForever(file) {
|
||||||
const sub = this.postsService.getSubscriptionByID(file.sub_id);
|
const sub = this.postsService.getSubscriptionByID(file.sub_id);
|
||||||
this.postsService.deleteSubscriptionFile(sub, file.id, true, file.uid).subscribe(res => {
|
this.postsService.deleteSubscriptionFile(sub, file.id, true, file.uid).subscribe(res => {
|
||||||
this.postsService.openSnackBar(`Successfully deleted file: '${file.id}'`);
|
this.postsService.openSnackBar(`Successfully deleted file: '${file.id}'`);
|
||||||
this.files.splice(index, 1);
|
this.removeFileCard(file);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
removeFileCard(file_to_remove) {
|
||||||
|
console.log(file_to_remove.uid);
|
||||||
|
const index = this.files.map(e => e.uid).indexOf(file_to_remove.uid);
|
||||||
|
this.files.splice(index, 1);
|
||||||
|
if (this.search_mode) {
|
||||||
|
this.filterFiles(this.search_text);
|
||||||
|
}
|
||||||
|
this.filterByProperty(this.filterProperty['property']);
|
||||||
|
}
|
||||||
|
|
||||||
// sorting and filtering
|
// sorting and filtering
|
||||||
|
|
||||||
sortFiles(a, b) {
|
sortFiles(a, b) {
|
||||||
|
|||||||
Reference in New Issue
Block a user