From cbdd1a6253df654237bf0fdedb19c60ea083b9a8 Mon Sep 17 00:00:00 2001 From: Isaac Abadi Date: Mon, 20 Jun 2022 16:25:55 -0400 Subject: [PATCH] Improved snackbar translations support --- .../custom-playlists.component.ts | 6 ++-- .../downloads/downloads.component.ts | 30 ++++++++----------- .../logs-viewer/logs-viewer.component.ts | 12 ++++---- .../recent-videos/recent-videos.component.ts | 6 ++-- .../twitch-chat/twitch-chat.component.ts | 6 ++-- .../create-playlist.component.ts | 11 ++++++- .../cookies-uploader-dialog.component.ts | 2 +- .../restore-db-dialog.component.ts | 6 ++-- src/app/main/main.component.ts | 4 +-- src/app/player/player.component.ts | 6 ++-- src/app/settings/settings.component.ts | 28 ++++++++--------- 11 files changed, 60 insertions(+), 57 deletions(-) diff --git a/src/app/components/custom-playlists/custom-playlists.component.ts b/src/app/components/custom-playlists/custom-playlists.component.ts index 1a2faa3..c2905c9 100644 --- a/src/app/components/custom-playlists/custom-playlists.component.ts +++ b/src/app/components/custom-playlists/custom-playlists.component.ts @@ -53,9 +53,9 @@ export class CustomPlaylistsComponent implements OnInit { dialogRef.afterClosed().subscribe(result => { if (result) { this.getAllPlaylists(); - this.postsService.openSnackBar('Successfully created playlist!', ''); + this.postsService.openSnackBar($localize`Successfully created playlist!', '`); } else if (result === false) { - this.postsService.openSnackBar('ERROR: failed to create playlist!', ''); + this.postsService.openSnackBar($localize`ERROR: failed to create playlist!', '`); } }); } @@ -96,7 +96,7 @@ export class CustomPlaylistsComponent implements OnInit { this.postsService.removePlaylist(playlistID).subscribe(res => { if (res['success']) { this.playlists.splice(index, 1); - this.postsService.openSnackBar('Playlist successfully removed.', ''); + this.postsService.openSnackBar($localize`Playlist successfully removed.', '`); } this.getAllPlaylists(); }); diff --git a/src/app/components/downloads/downloads.component.ts b/src/app/components/downloads/downloads.component.ts index 81cdd8c..45f1e7a 100644 --- a/src/app/components/downloads/downloads.component.ts +++ b/src/app/components/downloads/downloads.component.ts @@ -8,6 +8,7 @@ import { MatDialog } from '@angular/material/dialog'; import { ConfirmDialogComponent } from 'app/dialogs/confirm-dialog/confirm-dialog.component'; import { MatSort } from '@angular/material/sort'; import { Clipboard } from '@angular/cdk/clipboard'; +import { Download } from 'api-types'; @Component({ selector: 'app-downloads', @@ -68,7 +69,7 @@ export class DownloadsComponent implements OnInit, OnDestroy { @ViewChild(MatPaginator) paginator: MatPaginator; @ViewChild(MatSort) sort: MatSort; - sort_downloads = (a, b) => { + sort_downloads = (a: Download, b: Download): number => { const result = b.timestamp_start - a.timestamp_start; return result; } @@ -166,7 +167,7 @@ export class DownloadsComponent implements OnInit, OnDestroy { pauseDownload(download_uid: string): void { this.postsService.pauseDownload(download_uid).subscribe(res => { if (!res['success']) { - this.postsService.openSnackBar('Failed to pause download! See server logs for more info.'); + this.postsService.openSnackBar($localize`Failed to pause download! See server logs for more info.`); } }); } @@ -174,7 +175,7 @@ export class DownloadsComponent implements OnInit, OnDestroy { pauseAllDownloads(): void { this.postsService.pauseAllDownloads().subscribe(res => { if (!res['success']) { - this.postsService.openSnackBar('Failed to pause all downloads! See server logs for more info.'); + this.postsService.openSnackBar($localize`Failed to pause all downloads! See server logs for more info.`); } }); } @@ -182,7 +183,7 @@ export class DownloadsComponent implements OnInit, OnDestroy { resumeDownload(download_uid: string): void { this.postsService.resumeDownload(download_uid).subscribe(res => { if (!res['success']) { - this.postsService.openSnackBar('Failed to resume download! See server logs for more info.'); + this.postsService.openSnackBar($localize`Failed to resume download! See server logs for more info.`); } }); } @@ -190,7 +191,7 @@ export class DownloadsComponent implements OnInit, OnDestroy { resumeAllDownloads(): void { this.postsService.resumeAllDownloads().subscribe(res => { if (!res['success']) { - this.postsService.openSnackBar('Failed to resume all downloads! See server logs for more info.'); + this.postsService.openSnackBar($localize`Failed to resume all downloads! See server logs for more info.`); } }); } @@ -198,7 +199,7 @@ export class DownloadsComponent implements OnInit, OnDestroy { restartDownload(download_uid: string): void { this.postsService.restartDownload(download_uid).subscribe(res => { if (!res['success']) { - this.postsService.openSnackBar('Failed to restart download! See server logs for more info.'); + this.postsService.openSnackBar($localize`Failed to restart download! See server logs for more info.`); } }); } @@ -206,7 +207,7 @@ export class DownloadsComponent implements OnInit, OnDestroy { cancelDownload(download_uid: string): void { this.postsService.cancelDownload(download_uid).subscribe(res => { if (!res['success']) { - this.postsService.openSnackBar('Failed to cancel download! See server logs for more info.'); + this.postsService.openSnackBar($localize`Failed to cancel download! See server logs for more info.`); } }); } @@ -214,12 +215,12 @@ export class DownloadsComponent implements OnInit, OnDestroy { clearDownload(download_uid: string): void { this.postsService.clearDownload(download_uid).subscribe(res => { if (!res['success']) { - this.postsService.openSnackBar('Failed to pause download! See server logs for more info.'); + this.postsService.openSnackBar($localize`Failed to pause download! See server logs for more info.`); } }); } - watchContent(download): void { + watchContent(download: Download): void { const container = download['container']; localStorage.setItem('player_navigator', this.router.url.split(';')[0]); const is_playlist = container['uids']; // hacky, TODO: fix @@ -230,7 +231,7 @@ export class DownloadsComponent implements OnInit, OnDestroy { } } - combineDownloads(downloads_old, downloads_new) { + combineDownloads(downloads_old: Download[], downloads_new: Download[]): Download[] { // only keeps downloads that exist in the new set downloads_old = downloads_old.filter(download_old => downloads_new.some(download_new => download_new.uid === download_old.uid)); @@ -251,7 +252,7 @@ export class DownloadsComponent implements OnInit, OnDestroy { return downloads_old; } - showError(download) { + showError(download: Download): void { const copyToClipboardEmitter = new EventEmitter(); this.dialog.open(ConfirmDialogComponent, { data: { @@ -272,10 +273,3 @@ export class DownloadsComponent implements OnInit, OnDestroy { }); } } - -export interface Download { - timestamp_start: number; - title: string; - step_index: number; - progress: string; -} \ No newline at end of file diff --git a/src/app/components/logs-viewer/logs-viewer.component.ts b/src/app/components/logs-viewer/logs-viewer.component.ts index 5a218cc..c05c9f9 100644 --- a/src/app/components/logs-viewer/logs-viewer.component.ts +++ b/src/app/components/logs-viewer/logs-viewer.component.ts @@ -43,17 +43,17 @@ export class LogsViewerComponent implements OnInit { }) }); } else { - this.postsService.openSnackBar('Failed to retrieve logs!'); + this.postsService.openSnackBar($localize`Failed to retrieve logs!`); } }, err => { this.logs_loading = false; console.error(err); - this.postsService.openSnackBar('Failed to retrieve logs!'); + this.postsService.openSnackBar($localize`Failed to retrieve logs!`); }); } copiedLogsToClipboard() { - this.postsService.openSnackBar('Logs copied to clipboard!'); + this.postsService.openSnackBar($localize`Logs copied to clipboard!`); } clearLogs() { @@ -72,12 +72,12 @@ export class LogsViewerComponent implements OnInit { this.logs = []; this.logs_text = ''; this.getLogs(); - this.postsService.openSnackBar('Logs successfully cleared!'); + this.postsService.openSnackBar($localize`Logs successfully cleared!`); } else { - this.postsService.openSnackBar('Failed to clear logs!'); + this.postsService.openSnackBar($localize`Failed to clear logs!`); } }, err => { - this.postsService.openSnackBar('Failed to clear logs!'); + this.postsService.openSnackBar($localize`Failed to clear logs!`); }); } }); diff --git a/src/app/components/recent-videos/recent-videos.component.ts b/src/app/components/recent-videos/recent-videos.component.ts index 0463140..b930379 100644 --- a/src/app/components/recent-videos/recent-videos.component.ts +++ b/src/app/components/recent-videos/recent-videos.component.ts @@ -297,13 +297,13 @@ export class RecentVideosComponent implements OnInit { deleteNormalFile(file, blacklistMode = false) { this.postsService.deleteFile(file.uid, blacklistMode).subscribe(result => { if (result) { - this.postsService.openSnackBar('Delete success!', 'OK.'); + this.postsService.openSnackBar($localize`Delete success!', 'OK.`); this.removeFileCard(file); } else { - this.postsService.openSnackBar('Delete failed!', 'OK.'); + this.postsService.openSnackBar($localize`Delete failed!', 'OK.`); } }, err => { - this.postsService.openSnackBar('Delete failed!', 'OK.'); + this.postsService.openSnackBar($localize`Delete failed!', 'OK.`); }); } diff --git a/src/app/components/twitch-chat/twitch-chat.component.ts b/src/app/components/twitch-chat/twitch-chat.component.ts index bbeb7de..8208b84 100644 --- a/src/app/components/twitch-chat/twitch-chat.component.ts +++ b/src/app/components/twitch-chat/twitch-chat.component.ts @@ -96,18 +96,18 @@ export class TwitchChatComponent implements OnInit, OnDestroy { let vodId = this.db_file.url.split('videos/').length > 1 && this.db_file.url.split('videos/')[1]; vodId = vodId.split('?')[0]; if (!vodId) { - this.postsService.openSnackBar('VOD url for this video is not supported. VOD ID must be after "twitch.tv/videos/"'); + this.postsService.openSnackBar($localize`VOD url for this video is not supported. VOD ID must be after "twitch.tv/videos/"`); } this.postsService.downloadTwitchChat(this.db_file.id, this.db_file.isAudio ? 'audio' : 'video', vodId, null, this.sub).subscribe(res => { if (res['chat']) { this.initializeChatCheck(res['chat']); } else { this.downloading_chat = false; - this.postsService.openSnackBar('Download failed.') + this.postsService.openSnackBar($localize`Download failed.`) } }, err => { this.downloading_chat = false; - this.postsService.openSnackBar('Chat could not be downloaded.') + this.postsService.openSnackBar($localize`Chat could not be downloaded.`) }); } diff --git a/src/app/create-playlist/create-playlist.component.ts b/src/app/create-playlist/create-playlist.component.ts index 1a5c40a..8688166 100644 --- a/src/app/create-playlist/create-playlist.component.ts +++ b/src/app/create-playlist/create-playlist.component.ts @@ -53,17 +53,26 @@ export class CreatePlaylistComponent implements OnInit { } else { this.dialogRef.close(false); } + }, err => { + this.create_in_progress = false; + console.error(err); }); } updatePlaylist(): void { + this.create_in_progress = true; this.playlist['name'] = this.name; this.playlist['uids'] = this.filesSelect.value; this.playlist_updated = true; this.postsService.updatePlaylist(this.playlist).subscribe(() => { - this.postsService.openSnackBar('Playlist updated successfully.'); + this.create_in_progress = false; + this.postsService.openSnackBar($localize`Playlist updated successfully.`); this.getPlaylist(); this.postsService.playlists_changed.next(true); + }, err => { + this.create_in_progress = false; + console.error(err) + this.postsService.openSnackBar($localize`Playlist updated successfully.`); }); } diff --git a/src/app/dialogs/cookies-uploader-dialog/cookies-uploader-dialog.component.ts b/src/app/dialogs/cookies-uploader-dialog/cookies-uploader-dialog.component.ts index 327a870..fc17a64 100644 --- a/src/app/dialogs/cookies-uploader-dialog/cookies-uploader-dialog.component.ts +++ b/src/app/dialogs/cookies-uploader-dialog/cookies-uploader-dialog.component.ts @@ -39,7 +39,7 @@ export class CookiesUploaderDialogComponent implements OnInit { this.uploading = false; if (res['success']) { this.uploaded = true; - this.postsService.openSnackBar('Cookies successfully uploaded!'); + this.postsService.openSnackBar($localize`Cookies successfully uploaded!`); } }, err => { this.uploading = false; diff --git a/src/app/dialogs/restore-db-dialog/restore-db-dialog.component.ts b/src/app/dialogs/restore-db-dialog/restore-db-dialog.component.ts index 204a8c1..6c14543 100644 --- a/src/app/dialogs/restore-db-dialog/restore-db-dialog.component.ts +++ b/src/app/dialogs/restore-db-dialog/restore-db-dialog.component.ts @@ -36,14 +36,14 @@ export class RestoreDbDialogComponent implements OnInit { this.postsService.restoreDBBackup(this.selected_backup[0]).subscribe(res => { this.restoring = false; if (res['success']) { - this.postsService.openSnackBar('Database successfully restored!'); + this.postsService.openSnackBar($localize`Database successfully restored!`); this.dialogRef.close(); } else { - this.postsService.openSnackBar('Failed to restore database! See logs for more info.'); + this.postsService.openSnackBar($localize`Failed to restore database! See logs for more info.`); } }, err => { this.restoring = false; - this.postsService.openSnackBar('Failed to restore database! See browser console for more info.'); + this.postsService.openSnackBar($localize`Failed to restore database! See browser console for more info.`); console.error(err); }); } diff --git a/src/app/main/main.component.ts b/src/app/main/main.component.ts index 372ed1b..baac9b4 100644 --- a/src/app/main/main.component.ts +++ b/src/app/main/main.component.ts @@ -390,7 +390,7 @@ export class MainComponent implements OnInit { }, () => { // can't access server this.downloadingfile = false; this.current_download = null; - this.postsService.openSnackBar('Download failed!', 'OK.'); + this.postsService.openSnackBar($localize`Download failed!', 'OK.`); }); if (!this.autoplay && urls.length === 1) { @@ -776,7 +776,7 @@ export class MainComponent implements OnInit { } else if (this.current_download['finished'] && this.current_download['error']) { this.downloadingfile = false; this.current_download = null; - this.postsService.openSnackBar('Download failed!', 'OK.'); + this.postsService.openSnackBar($localize`Download failed!', 'OK.`); } } else { // console.log('failed to get new download'); diff --git a/src/app/player/player.component.ts b/src/app/player/player.component.ts index a0676e4..4dbaa8c 100644 --- a/src/app/player/player.component.ts +++ b/src/app/player/player.component.ts @@ -147,7 +147,7 @@ export class PlayerComponent implements OnInit, AfterViewInit, OnDestroy { this.postsService.getFile(this.uid, this.uuid).subscribe(res => { this.db_file = res['file']; if (!this.db_file) { - this.postsService.openSnackBar('Failed to get file information from the server.', 'Dismiss'); + this.postsService.openSnackBar($localize`Failed to get file information from the server.', 'Dismiss`); return; } this.postsService.incrementViewCount(this.db_file['uid'], null, this.uuid).subscribe(() => undefined, err => { @@ -183,10 +183,10 @@ export class PlayerComponent implements OnInit, AfterViewInit, OnDestroy { this.show_player = true; this.parseFileNames(); } else { - this.postsService.openSnackBar('Failed to load playlist!', ''); + this.postsService.openSnackBar($localize`Failed to load playlist!', '`); } }, () => { - this.postsService.openSnackBar('Failed to load playlist!', ''); + this.postsService.openSnackBar($localize`Failed to load playlist!', '`); }); } diff --git a/src/app/settings/settings.component.ts b/src/app/settings/settings.component.ts index ce0c3fd..f46709f 100644 --- a/src/app/settings/settings.component.ts +++ b/src/app/settings/settings.component.ts @@ -131,7 +131,7 @@ export class SettingsComponent implements OnInit { this.postsService.updateCategories(this.postsService.categories).subscribe(res => { }, () => { - this.postsService.openSnackBar('Failed to update categories!'); + this.postsService.openSnackBar($localize`Failed to update categories!`); }); } @@ -205,7 +205,7 @@ export class SettingsComponent implements OnInit { localeSelectChanged(new_val: string): void { localStorage.setItem('locale', new_val); - this.postsService.openSnackBar('Language successfully changed! Reload to update the page.') + this.postsService.openSnackBar($localize`Language successfully changed! Reload to update the page.`) } generateBookmarklet(): void { @@ -233,7 +233,7 @@ export class SettingsComponent implements OnInit { window['external']['AddFavorite'](url, title); } else if (window['chrome']) { // Google Chrome - this.postsService.openSnackBar('Chrome users must drag the \'Alternate URL\' link to your bookmarks.'); + this.postsService.openSnackBar($localize`Chrome users must drag the \'Alternate URL\' link to your bookmarks.`); } else if (window['sidebar']) { // Firefox window['sidebar'].addPanel(title, url, ''); @@ -288,14 +288,14 @@ export class SettingsComponent implements OnInit { this.postsService.killAllDownloads().subscribe(res => { if (res['success']) { dialogRef.close(); - this.postsService.openSnackBar('Successfully killed all downloads!'); + this.postsService.openSnackBar($localize`Successfully killed all downloads!`); } else { dialogRef.close(); - this.postsService.openSnackBar('Failed to kill all downloads! Check logs for details.'); + this.postsService.openSnackBar($localize`Failed to kill all downloads! Check logs for details.`); } }, () => { dialogRef.close(); - this.postsService.openSnackBar('Failed to kill all downloads! Check logs for details.'); + this.postsService.openSnackBar($localize`Failed to kill all downloads! Check logs for details.`); }); } }); @@ -303,9 +303,9 @@ export class SettingsComponent implements OnInit { restartServer(): void { this.postsService.restartServer().subscribe(() => { - this.postsService.openSnackBar('Restarting!'); + this.postsService.openSnackBar($localize`Restarting!`); }, () => { - this.postsService.openSnackBar('Failed to restart the server.'); + this.postsService.openSnackBar($localize`Failed to restart the server.`); }); } @@ -336,14 +336,14 @@ export class SettingsComponent implements OnInit { this.db_transferring = false; const success = res['success']; if (success) { - this.postsService.openSnackBar('Successfully transfered DB! Reloading info...'); + this.postsService.openSnackBar($localize`Successfully transfered DB! Reloading info...`); this.getDBInfo(); } else { - this.postsService.openSnackBar('Failed to transfer DB -- transfer was aborted. Error: ' + res['error']); + this.postsService.openSnackBar($localize`Failed to transfer DB -- transfer was aborted. Error: ` + res['error']); } }, err => { this.db_transferring = false; - this.postsService.openSnackBar('Failed to transfer DB -- API call failed. See browser logs for details.'); + this.postsService.openSnackBar($localize`Failed to transfer DB -- API call failed. See browser logs for details.`); console.error(err); }); } @@ -353,13 +353,13 @@ export class SettingsComponent implements OnInit { this.postsService.testConnectionString(connection_string).subscribe(res => { this.testing_connection_string = false; if (res['success']) { - this.postsService.openSnackBar('Connection successful!'); + this.postsService.openSnackBar($localize`Connection successful!`); } else { - this.postsService.openSnackBar('Connection failed! Error: ' + res['error']); + this.postsService.openSnackBar($localize`Connection failed! Error: ` + res['error']); } }, () => { this.testing_connection_string = false; - this.postsService.openSnackBar('Connection failed! Error: Server error. See logs for more info.'); + this.postsService.openSnackBar($localize`Connection failed! Error: Server error. See logs for more info.`); }); } }