From 27ec473f5306621643fcb169be7cfe6b15136265 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Apr 2021 12:09:54 +0200 Subject: Set channel banner/avatar in creation form --- .../my-video-channel-create.component.ts | 70 +++++++++++++++++----- .../my-video-channel-edit.component.html | 28 ++++----- .../+my-video-channels/my-video-channel-edit.ts | 9 +-- .../my-video-channel-update.component.ts | 22 +++---- 4 files changed, 82 insertions(+), 47 deletions(-) (limited to 'client/src/app/+my-library/+my-video-channels') diff --git a/client/src/app/+my-library/+my-video-channels/my-video-channel-create.component.ts b/client/src/app/+my-library/+my-video-channels/my-video-channel-create.component.ts index a625493de..b3265210f 100644 --- a/client/src/app/+my-library/+my-video-channels/my-video-channel-create.component.ts +++ b/client/src/app/+my-library/+my-video-channels/my-video-channel-create.component.ts @@ -8,10 +8,12 @@ import { VIDEO_CHANNEL_SUPPORT_VALIDATOR } from '@app/shared/form-validators/video-channel-validators' import { FormValidatorService } from '@app/shared/shared-forms' -import { VideoChannelService } from '@app/shared/shared-main' +import { VideoChannel, VideoChannelService } from '@app/shared/shared-main' import { VideoChannelCreate } from '@shared/models' import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' import { MyVideoChannelEdit } from './my-video-channel-edit' +import { switchMap } from 'rxjs/operators' +import { of } from 'rxjs' @Component({ templateUrl: './my-video-channel-edit.component.html', @@ -19,6 +21,10 @@ import { MyVideoChannelEdit } from './my-video-channel-edit' }) export class MyVideoChannelCreateComponent extends MyVideoChannelEdit implements OnInit { error: string + videoChannel = new VideoChannel({}) + + private avatar: FormData + private banner: FormData constructor ( protected formValidatorService: FormValidatorService, @@ -50,23 +56,43 @@ export class MyVideoChannelCreateComponent extends MyVideoChannelEdit implements support: body.support || null } - this.videoChannelService.createVideoChannel(videoChannelCreate).subscribe( - () => { - this.authService.refreshUserInformation() + this.videoChannelService.createVideoChannel(videoChannelCreate) + .pipe( + switchMap(() => this.uploadAvatar()), + switchMap(() => this.uploadBanner()) + ).subscribe( + () => { + this.authService.refreshUserInformation() + + this.notifier.success($localize`Video channel ${videoChannelCreate.displayName} created.`) + this.router.navigate(['/my-library', 'video-channels']) + }, - this.notifier.success($localize`Video channel ${videoChannelCreate.displayName} created.`) - this.router.navigate([ '/my-library', 'video-channels' ]) - }, + err => { + if (err.status === HttpStatusCode.CONFLICT_409) { + this.error = $localize`This name already exists on this instance.` + return + } - err => { - if (err.status === HttpStatusCode.CONFLICT_409) { - this.error = $localize`This name already exists on this instance.` - return + this.error = err.message } + ) + } + + onAvatarChange (formData: FormData) { + this.avatar = formData + } + + onAvatarDelete () { + this.avatar = null + } + + onBannerChange (formData: FormData) { + this.banner = formData + } - this.error = err.message - } - ) + onBannerDelete () { + this.banner = null } isCreation () { @@ -76,4 +102,20 @@ export class MyVideoChannelCreateComponent extends MyVideoChannelEdit implements getFormButtonTitle () { return $localize`Create` } + + getUsername () { + return this.form.value.name + } + + private uploadAvatar () { + if (!this.avatar) return of(undefined) + + return this.videoChannelService.changeVideoChannelImage(this.getUsername(), this.avatar, 'avatar') + } + + private uploadBanner () { + if (!this.banner) return of(undefined) + + return this.videoChannelService.changeVideoChannelImage(this.getUsername(), this.banner, 'banner') + } } diff --git a/client/src/app/+my-library/+my-video-channels/my-video-channel-edit.component.html b/client/src/app/+my-library/+my-video-channels/my-video-channel-edit.component.html index 7b8928907..2910dffad 100644 --- a/client/src/app/+my-library/+my-video-channels/my-video-channel-edit.component.html +++ b/client/src/app/+my-library/+my-video-channels/my-video-channel-edit.component.html @@ -10,7 +10,7 @@ @@ -23,10 +23,22 @@
NEW CHANNEL
-
CHANNEL
+
CHANNEL
+
Banner image of your channel
+ + + +
@@ -44,18 +56,6 @@
-
Banner image of your channel
- - - - -
{ - this.videoChannelToUpdate = videoChannelToUpdate + this.videoChannel = videoChannelToUpdate this.oldSupportField = videoChannelToUpdate.support @@ -87,7 +87,7 @@ export class MyVideoChannelUpdateComponent extends MyVideoChannelEdit implements bulkVideosSupportUpdate: body.bulkVideosSupportUpdate || false } - this.videoChannelService.updateVideoChannel(this.videoChannelToUpdate.name, videoChannelUpdate).subscribe( + this.videoChannelService.updateVideoChannel(this.videoChannel.name, videoChannelUpdate).subscribe( () => { this.authService.refreshUserInformation() @@ -101,12 +101,12 @@ export class MyVideoChannelUpdateComponent extends MyVideoChannelEdit implements } onAvatarChange (formData: FormData) { - this.videoChannelService.changeVideoChannelImage(this.videoChannelToUpdate.name, formData, 'avatar') + this.videoChannelService.changeVideoChannelImage(this.videoChannel.name, formData, 'avatar') .subscribe( data => { this.notifier.success($localize`Avatar changed.`) - this.videoChannelToUpdate.updateAvatar(data.avatar) + this.videoChannel.updateAvatar(data.avatar) }, (err: HttpErrorResponse) => uploadErrorHandler({ @@ -118,12 +118,12 @@ export class MyVideoChannelUpdateComponent extends MyVideoChannelEdit implements } onAvatarDelete () { - this.videoChannelService.deleteVideoChannelImage(this.videoChannelToUpdate.name, 'avatar') + this.videoChannelService.deleteVideoChannelImage(this.videoChannel.name, 'avatar') .subscribe( data => { this.notifier.success($localize`Avatar deleted.`) - this.videoChannelToUpdate.resetAvatar() + this.videoChannel.resetAvatar() }, err => this.notifier.error(err.message) @@ -131,12 +131,12 @@ export class MyVideoChannelUpdateComponent extends MyVideoChannelEdit implements } onBannerChange (formData: FormData) { - this.videoChannelService.changeVideoChannelImage(this.videoChannelToUpdate.name, formData, 'banner') + this.videoChannelService.changeVideoChannelImage(this.videoChannel.name, formData, 'banner') .subscribe( data => { this.notifier.success($localize`Banner changed.`) - this.videoChannelToUpdate.updateBanner(data.banner) + this.videoChannel.updateBanner(data.banner) }, (err: HttpErrorResponse) => uploadErrorHandler({ @@ -148,12 +148,12 @@ export class MyVideoChannelUpdateComponent extends MyVideoChannelEdit implements } onBannerDelete () { - this.videoChannelService.deleteVideoChannelImage(this.videoChannelToUpdate.name, 'banner') + this.videoChannelService.deleteVideoChannelImage(this.videoChannel.name, 'banner') .subscribe( data => { this.notifier.success($localize`Banner deleted.`) - this.videoChannelToUpdate.resetBanner() + this.videoChannel.resetBanner() }, err => this.notifier.error(err.message) -- cgit v1.2.3