From 789ba349318e7ff012590491e76087a1204cccd4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 19 Jan 2023 14:52:27 +0100 Subject: Support mailto links for custom markup --- .../about-instance/about-instance.component.html | 40 ++++++++++----------- .../about-instance/about-instance.component.ts | 41 ++++++++-------------- .../about-instance/about-instance.resolver.ts | 25 ++++++++++--- .../custom-markup-container.component.ts | 20 +++++++---- .../app/shared/shared-instance/instance.service.ts | 7 +++- 5 files changed, 74 insertions(+), 59 deletions(-) (limited to 'client/src') diff --git a/client/src/app/+about/about-instance/about-instance.component.html b/client/src/app/+about/about-instance/about-instance.component.html index b113df82f..fdd6157e5 100644 --- a/client/src/app/+about/about-instance/about-instance.component.html +++ b/client/src/app/+about/about-instance/about-instance.component.html @@ -21,7 +21,7 @@
-
+ -
+ -
+ -
-
+ -
+
@@ -169,14 +169,14 @@

Terms

-
+
diff --git a/client/src/app/+about/about-instance/about-instance.component.ts b/client/src/app/+about/about-instance/about-instance.component.ts index 0826bbc5a..e1501d7de 100644 --- a/client/src/app/+about/about-instance/about-instance.component.ts +++ b/client/src/app/+about/about-instance/about-instance.component.ts @@ -2,7 +2,7 @@ import { ViewportScroller } from '@angular/common' import { AfterViewChecked, Component, ElementRef, OnInit, ViewChild } from '@angular/core' import { ActivatedRoute } from '@angular/router' import { Notifier, ServerService } from '@app/core' -import { InstanceService } from '@app/shared/shared-instance' +import { AboutHTML } from '@app/shared/shared-instance' import { copyToClipboard } from '@root-helpers/utils' import { HTMLServerConfig } from '@shared/models/server' import { ResolverData } from './about-instance.resolver' @@ -17,22 +17,12 @@ export class AboutInstanceComponent implements OnInit, AfterViewChecked { @ViewChild('descriptionWrapper') descriptionWrapper: ElementRef @ViewChild('contactAdminModal', { static: true }) contactAdminModal: ContactAdminModalComponent - shortDescription = '' - descriptionContent: string - - html = { - terms: '', - codeOfConduct: '', - moderationInformation: '', - administrator: '', - creationReason: '', - maintenanceLifetime: '', - businessModel: '', - hardwareInformation: '' - } + aboutHTML: AboutHTML + descriptionElement: HTMLDivElement languages: string[] = [] categories: string[] = [] + shortDescription = '' initialized = false @@ -44,8 +34,7 @@ export class AboutInstanceComponent implements OnInit, AfterViewChecked { private viewportScroller: ViewportScroller, private route: ActivatedRoute, private notifier: Notifier, - private serverService: ServerService, - private instanceService: InstanceService + private serverService: ServerService ) {} get instanceName () { @@ -60,8 +49,16 @@ export class AboutInstanceComponent implements OnInit, AfterViewChecked { return this.serverConfig.instance.isNSFW } - async ngOnInit () { - const { about, languages, categories }: ResolverData = this.route.snapshot.data.instanceData + ngOnInit () { + const { about, languages, categories, aboutHTML, descriptionElement }: ResolverData = this.route.snapshot.data.instanceData + + this.aboutHTML = aboutHTML + this.descriptionElement = descriptionElement + + this.languages = languages + this.categories = categories + + this.shortDescription = about.instance.shortDescription this.serverConfig = this.serverService.getHTMLConfig() @@ -73,14 +70,6 @@ export class AboutInstanceComponent implements OnInit, AfterViewChecked { this.contactAdminModal.show(prefill) }) - this.languages = languages - this.categories = categories - - this.shortDescription = about.instance.shortDescription - this.descriptionContent = about.instance.description - - this.html = await this.instanceService.buildHtml(about) - this.initialized = true } diff --git a/client/src/app/+about/about-instance/about-instance.resolver.ts b/client/src/app/+about/about-instance/about-instance.resolver.ts index ee0219df0..8818fc582 100644 --- a/client/src/app/+about/about-instance/about-instance.resolver.ts +++ b/client/src/app/+about/about-instance/about-instance.resolver.ts @@ -2,16 +2,25 @@ import { forkJoin } from 'rxjs' import { map, switchMap } from 'rxjs/operators' import { Injectable } from '@angular/core' import { Resolve } from '@angular/router' -import { InstanceService } from '@app/shared/shared-instance' +import { CustomMarkupService } from '@app/shared/shared-custom-markup' +import { AboutHTML, InstanceService } from '@app/shared/shared-instance' import { About } from '@shared/models/server' -export type ResolverData = { about: About, languages: string[], categories: string[] } +export type ResolverData = { + about: About + languages: string[] + categories: string[] + aboutHTML: AboutHTML + descriptionElement: HTMLDivElement +} @Injectable() export class AboutInstanceResolver implements Resolve { constructor ( - private instanceService: InstanceService + private instanceService: InstanceService, + private customMarkupService: CustomMarkupService + ) {} resolve () { @@ -19,9 +28,15 @@ export class AboutInstanceResolver implements Resolve { .pipe( switchMap(about => { return forkJoin([ + Promise.resolve(about), this.instanceService.buildTranslatedLanguages(about), - this.instanceService.buildTranslatedCategories(about) - ]).pipe(map(([ languages, categories ]) => ({ about, languages, categories }) as ResolverData)) + this.instanceService.buildTranslatedCategories(about), + this.instanceService.buildHtml(about), + this.customMarkupService.buildElement(about.instance.description) + ]) + }), + map(([ about, languages, categories, aboutHTML, { rootElement } ]) => { + return { about, languages, categories, aboutHTML, descriptionElement: rootElement } as ResolverData }) ) } diff --git a/client/src/app/shared/shared-custom-markup/custom-markup-container.component.ts b/client/src/app/shared/shared-custom-markup/custom-markup-container.component.ts index 4e802b14d..b2ee2d8f2 100644 --- a/client/src/app/shared/shared-custom-markup/custom-markup-container.component.ts +++ b/client/src/app/shared/shared-custom-markup/custom-markup-container.component.ts @@ -6,9 +6,9 @@ import { CustomMarkupService } from './custom-markup.service' templateUrl: './custom-markup-container.component.html' }) export class CustomMarkupContainerComponent implements OnChanges { - @ViewChild('contentWrapper') contentWrapper: ElementRef + @ViewChild('contentWrapper', { static: true }) contentWrapper: ElementRef - @Input() content: string + @Input() content: string | HTMLDivElement displayed = false @@ -17,17 +17,23 @@ export class CustomMarkupContainerComponent implements OnChanges { ) { } async ngOnChanges () { - await this.buildElement() + await this.rebuild() } - private async buildElement () { - if (!this.content) return + private async rebuild () { + if (this.content instanceof HTMLDivElement) { + return this.loadElement(this.content) + } const { rootElement, componentsLoaded } = await this.customMarkupService.buildElement(this.content) - this.contentWrapper.nativeElement.appendChild(rootElement) - await componentsLoaded + return this.loadElement(rootElement) + } + + private loadElement (el: HTMLDivElement) { + this.contentWrapper.nativeElement.appendChild(el) + this.displayed = true } } diff --git a/client/src/app/shared/shared-instance/instance.service.ts b/client/src/app/shared/shared-instance/instance.service.ts index 89f47db24..f5b2e05db 100644 --- a/client/src/app/shared/shared-instance/instance.service.ts +++ b/client/src/app/shared/shared-instance/instance.service.ts @@ -7,6 +7,11 @@ import { peertubeTranslate } from '@shared/core-utils/i18n' import { About } from '@shared/models' import { environment } from '../../../environments/environment' +export type AboutHTML = Pick + @Injectable() export class InstanceService { private static BASE_CONFIG_URL = environment.apiUrl + '/api/v1/config' @@ -39,7 +44,7 @@ export class InstanceService { } async buildHtml (about: About) { - const html = { + const html: AboutHTML = { terms: '', codeOfConduct: '', moderationInformation: '', -- cgit v1.2.3