diff options
author | Chocobozzz <me@florianbigard.com> | 2019-03-21 16:49:46 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-04-02 11:45:02 +0200 |
commit | 489290b8b16bede6ddfb773adad55dee6471ccfd (patch) | |
tree | 8d3bb73c80df18f1e4d15b23a7e4080a6bc5985e /client/src/app/+my-account/my-account-videos/my-account-videos.component.ts | |
parent | 7ccddd7b5250bd25a917a6e77e58b87b9484a2a4 (diff) | |
download | PeerTube-489290b8b16bede6ddfb773adad55dee6471ccfd.tar.gz PeerTube-489290b8b16bede6ddfb773adad55dee6471ccfd.tar.zst PeerTube-489290b8b16bede6ddfb773adad55dee6471ccfd.zip |
Restore videos list components
Diffstat (limited to 'client/src/app/+my-account/my-account-videos/my-account-videos.component.ts')
-rw-r--r-- | client/src/app/+my-account/my-account-videos/my-account-videos.component.ts | 47 |
1 files changed, 14 insertions, 33 deletions
diff --git a/client/src/app/+my-account/my-account-videos/my-account-videos.component.ts b/client/src/app/+my-account/my-account-videos/my-account-videos.component.ts index 41608f796..eb5096a5e 100644 --- a/client/src/app/+my-account/my-account-videos/my-account-videos.component.ts +++ b/client/src/app/+my-account/my-account-videos/my-account-videos.component.ts | |||
@@ -1,11 +1,10 @@ | |||
1 | import { from as observableFrom, Observable } from 'rxjs' | 1 | import { concat, Observable } from 'rxjs' |
2 | import { concatAll, tap } from 'rxjs/operators' | 2 | import { tap, toArray } from 'rxjs/operators' |
3 | import { Component, OnDestroy, OnInit, Inject, LOCALE_ID, ViewChild } from '@angular/core' | 3 | import { Component, Inject, LOCALE_ID, OnDestroy, OnInit, ViewChild } from '@angular/core' |
4 | import { ActivatedRoute, Router } from '@angular/router' | 4 | import { ActivatedRoute, Router } from '@angular/router' |
5 | import { Location } from '@angular/common' | ||
6 | import { immutableAssign } from '@app/shared/misc/utils' | 5 | import { immutableAssign } from '@app/shared/misc/utils' |
7 | import { ComponentPagination } from '@app/shared/rest/component-pagination.model' | 6 | import { ComponentPagination } from '@app/shared/rest/component-pagination.model' |
8 | import { Notifier } from '@app/core' | 7 | import { Notifier, ServerService } from '@app/core' |
9 | import { AuthService } from '../../core/auth' | 8 | import { AuthService } from '../../core/auth' |
10 | import { ConfirmService } from '../../core/confirm' | 9 | import { ConfirmService } from '../../core/confirm' |
11 | import { AbstractVideoList } from '../../shared/video/abstract-video-list' | 10 | import { AbstractVideoList } from '../../shared/video/abstract-video-list' |
@@ -22,8 +21,9 @@ import { VideoChangeOwnershipComponent } from './video-change-ownership/video-ch | |||
22 | styleUrls: [ './my-account-videos.component.scss' ] | 21 | styleUrls: [ './my-account-videos.component.scss' ] |
23 | }) | 22 | }) |
24 | export class MyAccountVideosComponent extends AbstractVideoList implements OnInit, OnDestroy { | 23 | export class MyAccountVideosComponent extends AbstractVideoList implements OnInit, OnDestroy { |
24 | @ViewChild('videoChangeOwnershipModal') videoChangeOwnershipModal: VideoChangeOwnershipComponent | ||
25 | |||
25 | titlePage: string | 26 | titlePage: string |
26 | currentRoute = '/my-account/videos' | ||
27 | checkedVideos: { [ id: number ]: boolean } = {} | 27 | checkedVideos: { [ id: number ]: boolean } = {} |
28 | pagination: ComponentPagination = { | 28 | pagination: ComponentPagination = { |
29 | currentPage: 1, | 29 | currentPage: 1, |
@@ -31,19 +31,14 @@ export class MyAccountVideosComponent extends AbstractVideoList implements OnIni | |||
31 | totalItems: null | 31 | totalItems: null |
32 | } | 32 | } |
33 | 33 | ||
34 | protected baseVideoWidth = -1 | ||
35 | protected baseVideoHeight = 155 | ||
36 | |||
37 | @ViewChild('videoChangeOwnershipModal') videoChangeOwnershipModal: VideoChangeOwnershipComponent | ||
38 | |||
39 | constructor ( | 34 | constructor ( |
40 | protected router: Router, | 35 | protected router: Router, |
36 | protected serverService: ServerService, | ||
41 | protected route: ActivatedRoute, | 37 | protected route: ActivatedRoute, |
42 | protected authService: AuthService, | 38 | protected authService: AuthService, |
43 | protected notifier: Notifier, | 39 | protected notifier: Notifier, |
44 | protected location: Location, | ||
45 | protected screenService: ScreenService, | 40 | protected screenService: ScreenService, |
46 | protected i18n: I18n, | 41 | private i18n: I18n, |
47 | private confirmService: ConfirmService, | 42 | private confirmService: ConfirmService, |
48 | private videoService: VideoService, | 43 | private videoService: VideoService, |
49 | @Inject(LOCALE_ID) private localeId: string | 44 | @Inject(LOCALE_ID) private localeId: string |
@@ -93,19 +88,18 @@ export class MyAccountVideosComponent extends AbstractVideoList implements OnIni | |||
93 | const observables: Observable<any>[] = [] | 88 | const observables: Observable<any>[] = [] |
94 | for (const videoId of toDeleteVideosIds) { | 89 | for (const videoId of toDeleteVideosIds) { |
95 | const o = this.videoService.removeVideo(videoId) | 90 | const o = this.videoService.removeVideo(videoId) |
96 | .pipe(tap(() => this.spliceVideosById(videoId))) | 91 | .pipe(tap(() => this.removeVideoFromArray(videoId))) |
97 | 92 | ||
98 | observables.push(o) | 93 | observables.push(o) |
99 | } | 94 | } |
100 | 95 | ||
101 | observableFrom(observables) | 96 | concat(...observables) |
102 | .pipe(concatAll()) | 97 | .pipe(toArray()) |
103 | .subscribe( | 98 | .subscribe( |
104 | res => { | 99 | () => { |
105 | this.notifier.success(this.i18n('{{deleteLength}} videos deleted.', { deleteLength: toDeleteVideosIds.length })) | 100 | this.notifier.success(this.i18n('{{deleteLength}} videos deleted.', { deleteLength: toDeleteVideosIds.length })) |
106 | 101 | ||
107 | this.abortSelectionMode() | 102 | this.abortSelectionMode() |
108 | this.reloadVideos() | ||
109 | }, | 103 | }, |
110 | 104 | ||
111 | err => this.notifier.error(err.message) | 105 | err => this.notifier.error(err.message) |
@@ -156,20 +150,7 @@ export class MyAccountVideosComponent extends AbstractVideoList implements OnIni | |||
156 | return ' - ' + suffix | 150 | return ' - ' + suffix |
157 | } | 151 | } |
158 | 152 | ||
159 | protected buildVideoHeight () { | 153 | private removeVideoFromArray (id: number) { |
160 | // In account videos, the video height is fixed | 154 | this.videos = this.videos.filter(v => v.id !== id) |
161 | return this.baseVideoHeight | ||
162 | } | ||
163 | |||
164 | private spliceVideosById (id: number) { | ||
165 | for (const key of Object.keys(this.loadedPages)) { | ||
166 | const videos: Video[] = this.loadedPages[ key ] | ||
167 | const index = videos.findIndex(v => v.id === id) | ||
168 | |||
169 | if (index !== -1) { | ||
170 | videos.splice(index, 1) | ||
171 | return | ||
172 | } | ||
173 | } | ||
174 | } | 155 | } |
175 | } | 156 | } |