From 8f581725651c4b2c213d75fc028e306bbf239d3e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 27 Aug 2021 10:15:55 +0200 Subject: Allow accounts to skip account setup modal --- .../src/app/modal/admin-welcome-modal.component.ts | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 client/src/app/modal/admin-welcome-modal.component.ts (limited to 'client/src/app/modal/admin-welcome-modal.component.ts') diff --git a/client/src/app/modal/admin-welcome-modal.component.ts b/client/src/app/modal/admin-welcome-modal.component.ts new file mode 100644 index 000000000..3679f0847 --- /dev/null +++ b/client/src/app/modal/admin-welcome-modal.component.ts @@ -0,0 +1,50 @@ +import { Component, ElementRef, ViewChild } from '@angular/core' +import { Notifier, User, UserService } from '@app/core' +import { NgbModal } from '@ng-bootstrap/ng-bootstrap' +import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' + +@Component({ + selector: 'my-admin-welcome-modal', + templateUrl: './admin-welcome-modal.component.html', + styleUrls: [ './admin-welcome-modal.component.scss' ] +}) +export class AdminWelcomeModalComponent { + @ViewChild('modal', { static: true }) modal: ElementRef + + private LOCAL_STORAGE_KEYS = { + NO_WELCOME_MODAL: 'no_welcome_modal' + } + + constructor ( + private userService: UserService, + private modalService: NgbModal, + private notifier: Notifier + ) { } + + shouldOpen (user: User) { + if (user.noWelcomeModal === true) return false + if (peertubeLocalStorage.getItem(this.LOCAL_STORAGE_KEYS.NO_WELCOME_MODAL) === 'true') return false + + return true + } + + show () { + this.modalService.open(this.modal, { + centered: true, + backdrop: 'static', + keyboard: false, + size: 'lg' + }) + } + + doNotOpenAgain () { + peertubeLocalStorage.setItem(this.LOCAL_STORAGE_KEYS.NO_WELCOME_MODAL, 'true') + + this.userService.updateMyProfile({ noWelcomeModal: true }) + .subscribe({ + next: () => console.log('We will not open the welcome modal again.'), + + error: err => this.notifier.error(err.message) + }) + } +} -- cgit v1.2.3