PeerTube_original/client/src/app/modal/account-setup-warning-modal.component.ts
kontrollanten d0800f7661
Implement avatar miniatures (#4639)
* client: remove unused file

* refactor(client/my-actor-avatar): size from input

Read size from component input instead of scss, to make it possible to
use smaller avatar images when implemented.

* implement avatar miniatures

close #4560

* fix(test): max file size

* fix(search-index): normalize res acc to avatarMini

* refactor avatars to an array

* client/search: resize channel avatar to 120

* refactor(client/videos): remove unused function

* client(actor-avatar): set default size

* fix tests and avatars full result

When findOne is used only an array containting one avatar is returned.

* update migration version and version notations

* server/search: harmonize normalizing

* Cleanup avatar miniature PR

Co-authored-by: Chocobozzz <me@florianbigard.com>
2022-02-28 08:34:43 +01:00

80 lines
2.2 KiB
TypeScript

import { Component, ElementRef, ViewChild } from '@angular/core'
import { Notifier, ServerService, User, UserService } from '@app/core'
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'
import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'
@Component({
selector: 'my-account-setup-warning-modal',
templateUrl: './account-setup-warning-modal.component.html',
styleUrls: [ './account-setup-warning-modal.component.scss' ]
})
export class AccountSetupWarningModalComponent {
@ViewChild('modal', { static: true }) modal: ElementRef
stopDisplayModal = false
ref: NgbModalRef
user: User
private LOCAL_STORAGE_KEYS = {
NO_ACCOUNT_SETUP_WARNING_MODAL: 'no_account_setup_warning_modal'
}
constructor (
private userService: UserService,
private modalService: NgbModal,
private notifier: Notifier,
private serverService: ServerService
) { }
get instanceName () {
return this.serverService.getHTMLConfig().instance.name
}
hasAccountAvatar (user: User) {
return user.account.avatars.length !== 0
}
hasAccountDescription (user: User) {
return !!user.account.description
}
shouldOpen (user: User) {
if (user.noAccountSetupWarningModal === true) return false
if (peertubeLocalStorage.getItem(this.LOCAL_STORAGE_KEYS.NO_ACCOUNT_SETUP_WARNING_MODAL) === 'true') return false
if (this.hasAccountAvatar(user) && this.hasAccountDescription(user)) return false
if (this.userService.hasSignupInThisSession()) return false
return true
}
show (user: User) {
this.user = user
if (this.ref) return
this.ref = this.modalService.open(this.modal, {
centered: true,
backdrop: 'static',
keyboard: false,
size: 'md'
})
this.ref.result.finally(() => {
if (this.stopDisplayModal === true) this.doNotOpenAgain()
})
}
private doNotOpenAgain () {
peertubeLocalStorage.setItem(this.LOCAL_STORAGE_KEYS.NO_ACCOUNT_SETUP_WARNING_MODAL, 'true')
this.userService.updateMyProfile({ noAccountSetupWarningModal: true })
.subscribe({
next: () => console.log('We will not open the account setup modal again.'),
error: err => this.notifier.error(err.message)
})
}
}