Various front optimizations

This commit is contained in:
Chocobozzz 2020-11-27 15:31:09 +01:00
parent acfa2e300d
commit 68f6c87a27
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
8 changed files with 69 additions and 49 deletions

View File

@ -1,6 +1,6 @@
import { Hotkey, HotkeysService } from 'angular2-hotkeys'
import { concat } from 'rxjs'
import { filter, first, map, pairwise } from 'rxjs/operators'
import { filter, first, map, pairwise, tap } from 'rxjs/operators'
import { DOCUMENT, PlatformLocation, ViewportScroller } from '@angular/common'
import { AfterViewInit, Component, Inject, LOCALE_ID, OnInit, ViewChild } from '@angular/core'
import { DomSanitizer, SafeHtml } from '@angular/platform-browser'

View File

@ -1,11 +1,10 @@
import 'focus-visible'
import { APP_BASE_HREF, registerLocaleData } from '@angular/common'
import { LOCALE_ID, NgModule, TRANSLATIONS, TRANSLATIONS_FORMAT } from '@angular/core'
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { ServerService } from '@app/core'
import localeOc from '@app/helpers/locales/oc'
import { MetaLoader, MetaModule, MetaStaticLoader, PageTitlePositioning } from '@ngx-meta/core'
import { buildFileLocale, getCompleteLocale, isDefaultLocale } from '@shared/core-utils/i18n'
import { AppRoutingModule } from './app-routing.module'
import { AppComponent } from './app.component'
import { CoreModule } from './core'

View File

@ -11,6 +11,8 @@ export class RedirectService {
private previousUrl: string
private currentUrl: string
private redirectingToHomepage = false
constructor (
private router: Router,
private serverService: ServerService
@ -56,10 +58,17 @@ export class RedirectService {
}
redirectToHomepage (skipLocationChange = false) {
if (this.redirectingToHomepage) return
this.redirectingToHomepage = true
console.log('Redirecting to %s...', RedirectService.DEFAULT_ROUTE)
this.router.navigate([ RedirectService.DEFAULT_ROUTE ], { skipLocationChange })
.then(() => this.redirectingToHomepage = false)
.catch(() => {
this.redirectingToHomepage = false
console.error(
'Cannot navigate to %s, resetting default route to %s.',
RedirectService.DEFAULT_ROUTE,

View File

@ -12,7 +12,7 @@
<div class="logged-in-username">@{{ user.username }}</div>
</div>
<div class="logged-in-more" ngbDropdown [placement]="placement" container="body" autoClose="outside">
<div class="logged-in-more" ngbDropdown [placement]="loggedInMorePlacement" container="body" autoClose="outside">
<my-global-icon iconName="more-vertical" ngbDropdownToggle role="button"></my-global-icon>
<div ngbDropdownMenu>
@ -32,7 +32,7 @@
<a ngbDropdownItem ngbDropdownToggle class="dropdown-item" (click)="openLanguageChooser()">
<my-global-icon iconName="language" aria-hidden="true"></my-global-icon>
<span i18n>Interface:</span>
<span class="ml-auto text-muted">{{ language }}</span>
<span class="ml-auto text-muted">{{ currentInterfaceLanguage }}</span>
</a>
<a ngbDropdownItem ngbDropdownToggle class="dropdown-item" routerLink="/my-account/settings" fragment="video-languages-subtitles"
@ -168,7 +168,7 @@
<div class="footer-links">
<div *ngIf="isLoggedIn === false">
<span role="button" (click)="openLanguageChooser()" class="c-hand" i18n>Interface: {{ language }}</span>
<span role="button" (click)="openLanguageChooser()" class="c-hand" i18n>Interface: {{ currentInterfaceLanguage }}</span>
</div>
<div>

View File

@ -28,6 +28,11 @@ export class MenuComponent implements OnInit {
helpVisible = false
videoLanguages: string[] = []
nsfwPolicy: string
loggedInMorePlacement: string
currentInterfaceLanguage: string
private languages: VideoConstant<string>[] = []
private serverConfig: ServerConfig
@ -52,37 +57,6 @@ export class MenuComponent implements OnInit {
private router: Router
) { }
get isInMobileView () {
return this.screenService.isInMobileView()
}
get placement () {
if (this.isInMobileView) {
return 'left-top auto'
} else {
return 'right-top auto'
}
}
get language () {
return this.languageChooserModal.getCurrentLanguage()
}
get nsfwPolicy () {
if (!this.user) return
switch (this.user.nsfwPolicy) {
case 'do_not_list':
return $localize`hide`
case 'blur':
return $localize`blur`
case 'display':
return $localize`display`
}
}
get instanceName () {
return this.serverConfig.instance.name
}
@ -95,11 +69,19 @@ export class MenuComponent implements OnInit {
this.isLoggedIn = this.authService.isLoggedIn()
if (this.isLoggedIn === true) {
this.user = this.authService.getUser()
this.computeNSFWPolicy()
this.computeVideosLink()
}
this.computeAdminAccess()
this.loggedInMorePlacement = this.screenService.isInMobileView()
? 'left-top auto'
: 'right-top auto'
this.currentInterfaceLanguage = this.languageChooserModal.getCurrentLanguage()
this.authService.loginChangedSource.subscribe(
status => {
if (status === AuthStatus.LoggedIn) {
@ -252,4 +234,25 @@ export class MenuComponent implements OnInit {
else logger('User cannot see videos link.')
})
}
private computeNSFWPolicy () {
if (!this.user) {
this.nsfwPolicy = null
return
}
switch (this.user.nsfwPolicy) {
case 'do_not_list':
this.nsfwPolicy = $localize`hide`
break
case 'blur':
this.nsfwPolicy = $localize`blur`
break
case 'display':
this.nsfwPolicy = $localize`display`
break
}
}
}

View File

@ -1,6 +1,7 @@
<span
class="date-toggle"
[title]="getTitle()"
[innerHtml]="getContent()"
(click)="toggle()"
></span>
>
{{ getContent() }}
</span>

View File

@ -7,7 +7,7 @@ import { FromNowPipe } from '../angular/from-now.pipe'
templateUrl: './date-toggle.component.html',
styleUrls: [ './date-toggle.component.scss' ]
})
export class DateToggleComponent implements OnInit, OnChanges {
export class DateToggleComponent implements OnChanges {
@Input() date: Date
@Input() toggled = false
@ -19,10 +19,6 @@ export class DateToggleComponent implements OnInit, OnChanges {
private fromNowPipe: FromNowPipe
) { }
ngOnInit () {
this.updateDates()
}
ngOnChanges () {
this.updateDates()
}
@ -32,15 +28,19 @@ export class DateToggleComponent implements OnInit, OnChanges {
}
getTitle () {
return this.toggled ? this.dateRelative : this.dateAbsolute
return this.toggled
? this.dateRelative
: this.dateAbsolute
}
getContent () {
return this.toggled ? this.dateAbsolute : this.dateRelative
return this.toggled
? this.dateAbsolute
: this.dateRelative
}
private updateDates () {
this.dateRelative = this.fromNowPipe.transform(this.date)
this.dateAbsolute = this.datePipe.transform(this.date, 'long')
this.dateAbsolute = this.date.toLocaleDateString()
}
}

View File

@ -1,6 +1,6 @@
import { enableProdMode } from '@angular/core'
import { ApplicationRef, enableProdMode } from '@angular/core'
import { enableDebugTools } from '@angular/platform-browser'
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'
import { AppModule } from './app/app.module'
import { environment } from './environments/environment'
@ -27,6 +27,14 @@ const bootstrap = () => platformBrowserDynamic()
})
}
if (!environment.production) {
const applicationRef = bootstrapModule.injector.get(ApplicationRef)
const componentRef = applicationRef.components[0]
// allows to run `ng.profiler.timeChangeDetection();`
enableDebugTools(componentRef)
}
return bootstrapModule
})
.catch(err => {