aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+my-account
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/+my-account')
-rw-r--r--client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-elements.component.ts35
1 files changed, 25 insertions, 10 deletions
diff --git a/client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-elements.component.ts b/client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-elements.component.ts
index 6434b9e50..6f307a058 100644
--- a/client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-elements.component.ts
+++ b/client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-elements.component.ts
@@ -63,24 +63,26 @@ export class MyAccountVideoPlaylistElementsComponent implements OnInit, OnDestro
63 63
64 if (oldPosition > insertAfter) insertAfter-- 64 if (oldPosition > insertAfter) insertAfter--
65 65
66 this.videoPlaylistService.reorderPlaylist(this.playlist.id, oldPosition, insertAfter)
67 .subscribe(
68 () => { /* nothing to do */ },
69
70 err => this.notifier.error(err.message)
71 )
72
73 const element = this.playlistElements[previousIndex] 66 const element = this.playlistElements[previousIndex]
74 67
75 this.playlistElements.splice(previousIndex, 1) 68 this.playlistElements.splice(previousIndex, 1)
76 this.playlistElements.splice(newIndex, 0, element) 69 this.playlistElements.splice(newIndex, 0, element)
77 70
78 this.reorderClientPositions() 71 this.videoPlaylistService.reorderPlaylist(this.playlist.id, oldPosition, insertAfter)
72 .subscribe(
73 () => {
74 this.reorderClientPositions()
75 },
76
77 err => this.notifier.error(err.message)
78 )
79 } 79 }
80 80
81 onElementRemoved (element: VideoPlaylistElement) { 81 onElementRemoved (element: VideoPlaylistElement) {
82 const oldFirst = this.findFirst()
83
82 this.playlistElements = this.playlistElements.filter(v => v.id !== element.id) 84 this.playlistElements = this.playlistElements.filter(v => v.id !== element.id)
83 this.reorderClientPositions() 85 this.reorderClientPositions(oldFirst)
84 } 86 }
85 87
86 onNearOfBottom () { 88 onNearOfBottom () {
@@ -110,12 +112,25 @@ export class MyAccountVideoPlaylistElementsComponent implements OnInit, OnDestro
110 }) 112 })
111 } 113 }
112 114
113 private reorderClientPositions () { 115 private reorderClientPositions (first?: VideoPlaylistElement) {
116 if (this.playlistElements.length === 0) return
117
118 const oldFirst = first || this.findFirst()
114 let i = 1 119 let i = 1
115 120
116 for (const element of this.playlistElements) { 121 for (const element of this.playlistElements) {
117 element.position = i 122 element.position = i
118 i++ 123 i++
119 } 124 }
125
126 // Reload playlist thumbnail if the first element changed
127 const newFirst = this.findFirst()
128 if (oldFirst && newFirst && oldFirst.id !== newFirst.id) {
129 this.playlist.refreshThumbnail()
130 }
131 }
132
133 private findFirst () {
134 return this.playlistElements.find(e => e.position === 1)
120 } 135 }
121} 136}