Various front optimizations
This commit is contained in:
parent
acfa2e300d
commit
68f6c87a27
|
@ -1,6 +1,6 @@
|
||||||
import { Hotkey, HotkeysService } from 'angular2-hotkeys'
|
import { Hotkey, HotkeysService } from 'angular2-hotkeys'
|
||||||
import { concat } from 'rxjs'
|
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 { DOCUMENT, PlatformLocation, ViewportScroller } from '@angular/common'
|
||||||
import { AfterViewInit, Component, Inject, LOCALE_ID, OnInit, ViewChild } from '@angular/core'
|
import { AfterViewInit, Component, Inject, LOCALE_ID, OnInit, ViewChild } from '@angular/core'
|
||||||
import { DomSanitizer, SafeHtml } from '@angular/platform-browser'
|
import { DomSanitizer, SafeHtml } from '@angular/platform-browser'
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
import 'focus-visible'
|
import 'focus-visible'
|
||||||
import { APP_BASE_HREF, registerLocaleData } from '@angular/common'
|
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 { BrowserModule } from '@angular/platform-browser'
|
||||||
import { ServerService } from '@app/core'
|
import { ServerService } from '@app/core'
|
||||||
import localeOc from '@app/helpers/locales/oc'
|
import localeOc from '@app/helpers/locales/oc'
|
||||||
import { MetaLoader, MetaModule, MetaStaticLoader, PageTitlePositioning } from '@ngx-meta/core'
|
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 { AppRoutingModule } from './app-routing.module'
|
||||||
import { AppComponent } from './app.component'
|
import { AppComponent } from './app.component'
|
||||||
import { CoreModule } from './core'
|
import { CoreModule } from './core'
|
||||||
|
|
|
@ -11,6 +11,8 @@ export class RedirectService {
|
||||||
private previousUrl: string
|
private previousUrl: string
|
||||||
private currentUrl: string
|
private currentUrl: string
|
||||||
|
|
||||||
|
private redirectingToHomepage = false
|
||||||
|
|
||||||
constructor (
|
constructor (
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private serverService: ServerService
|
private serverService: ServerService
|
||||||
|
@ -56,10 +58,17 @@ export class RedirectService {
|
||||||
}
|
}
|
||||||
|
|
||||||
redirectToHomepage (skipLocationChange = false) {
|
redirectToHomepage (skipLocationChange = false) {
|
||||||
|
if (this.redirectingToHomepage) return
|
||||||
|
|
||||||
|
this.redirectingToHomepage = true
|
||||||
|
|
||||||
console.log('Redirecting to %s...', RedirectService.DEFAULT_ROUTE)
|
console.log('Redirecting to %s...', RedirectService.DEFAULT_ROUTE)
|
||||||
|
|
||||||
this.router.navigate([ RedirectService.DEFAULT_ROUTE ], { skipLocationChange })
|
this.router.navigate([ RedirectService.DEFAULT_ROUTE ], { skipLocationChange })
|
||||||
|
.then(() => this.redirectingToHomepage = false)
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
|
this.redirectingToHomepage = false
|
||||||
|
|
||||||
console.error(
|
console.error(
|
||||||
'Cannot navigate to %s, resetting default route to %s.',
|
'Cannot navigate to %s, resetting default route to %s.',
|
||||||
RedirectService.DEFAULT_ROUTE,
|
RedirectService.DEFAULT_ROUTE,
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
<div class="logged-in-username">@{{ user.username }}</div>
|
<div class="logged-in-username">@{{ user.username }}</div>
|
||||||
</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>
|
<my-global-icon iconName="more-vertical" ngbDropdownToggle role="button"></my-global-icon>
|
||||||
|
|
||||||
<div ngbDropdownMenu>
|
<div ngbDropdownMenu>
|
||||||
|
@ -32,7 +32,7 @@
|
||||||
<a ngbDropdownItem ngbDropdownToggle class="dropdown-item" (click)="openLanguageChooser()">
|
<a ngbDropdownItem ngbDropdownToggle class="dropdown-item" (click)="openLanguageChooser()">
|
||||||
<my-global-icon iconName="language" aria-hidden="true"></my-global-icon>
|
<my-global-icon iconName="language" aria-hidden="true"></my-global-icon>
|
||||||
<span i18n>Interface:</span>
|
<span i18n>Interface:</span>
|
||||||
<span class="ml-auto text-muted">{{ language }}</span>
|
<span class="ml-auto text-muted">{{ currentInterfaceLanguage }}</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a ngbDropdownItem ngbDropdownToggle class="dropdown-item" routerLink="/my-account/settings" fragment="video-languages-subtitles"
|
<a ngbDropdownItem ngbDropdownToggle class="dropdown-item" routerLink="/my-account/settings" fragment="video-languages-subtitles"
|
||||||
|
@ -168,7 +168,7 @@
|
||||||
|
|
||||||
<div class="footer-links">
|
<div class="footer-links">
|
||||||
<div *ngIf="isLoggedIn === false">
|
<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>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
|
|
@ -28,6 +28,11 @@ export class MenuComponent implements OnInit {
|
||||||
helpVisible = false
|
helpVisible = false
|
||||||
|
|
||||||
videoLanguages: string[] = []
|
videoLanguages: string[] = []
|
||||||
|
nsfwPolicy: string
|
||||||
|
|
||||||
|
loggedInMorePlacement: string
|
||||||
|
|
||||||
|
currentInterfaceLanguage: string
|
||||||
|
|
||||||
private languages: VideoConstant<string>[] = []
|
private languages: VideoConstant<string>[] = []
|
||||||
private serverConfig: ServerConfig
|
private serverConfig: ServerConfig
|
||||||
|
@ -52,37 +57,6 @@ export class MenuComponent implements OnInit {
|
||||||
private router: Router
|
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 () {
|
get instanceName () {
|
||||||
return this.serverConfig.instance.name
|
return this.serverConfig.instance.name
|
||||||
}
|
}
|
||||||
|
@ -95,11 +69,19 @@ export class MenuComponent implements OnInit {
|
||||||
this.isLoggedIn = this.authService.isLoggedIn()
|
this.isLoggedIn = this.authService.isLoggedIn()
|
||||||
if (this.isLoggedIn === true) {
|
if (this.isLoggedIn === true) {
|
||||||
this.user = this.authService.getUser()
|
this.user = this.authService.getUser()
|
||||||
|
|
||||||
|
this.computeNSFWPolicy()
|
||||||
this.computeVideosLink()
|
this.computeVideosLink()
|
||||||
}
|
}
|
||||||
|
|
||||||
this.computeAdminAccess()
|
this.computeAdminAccess()
|
||||||
|
|
||||||
|
this.loggedInMorePlacement = this.screenService.isInMobileView()
|
||||||
|
? 'left-top auto'
|
||||||
|
: 'right-top auto'
|
||||||
|
|
||||||
|
this.currentInterfaceLanguage = this.languageChooserModal.getCurrentLanguage()
|
||||||
|
|
||||||
this.authService.loginChangedSource.subscribe(
|
this.authService.loginChangedSource.subscribe(
|
||||||
status => {
|
status => {
|
||||||
if (status === AuthStatus.LoggedIn) {
|
if (status === AuthStatus.LoggedIn) {
|
||||||
|
@ -252,4 +234,25 @@ export class MenuComponent implements OnInit {
|
||||||
else logger('User cannot see videos link.')
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<span
|
<span
|
||||||
class="date-toggle"
|
class="date-toggle"
|
||||||
[title]="getTitle()"
|
[title]="getTitle()"
|
||||||
[innerHtml]="getContent()"
|
|
||||||
(click)="toggle()"
|
(click)="toggle()"
|
||||||
></span>
|
>
|
||||||
|
{{ getContent() }}
|
||||||
|
</span>
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { FromNowPipe } from '../angular/from-now.pipe'
|
||||||
templateUrl: './date-toggle.component.html',
|
templateUrl: './date-toggle.component.html',
|
||||||
styleUrls: [ './date-toggle.component.scss' ]
|
styleUrls: [ './date-toggle.component.scss' ]
|
||||||
})
|
})
|
||||||
export class DateToggleComponent implements OnInit, OnChanges {
|
export class DateToggleComponent implements OnChanges {
|
||||||
@Input() date: Date
|
@Input() date: Date
|
||||||
@Input() toggled = false
|
@Input() toggled = false
|
||||||
|
|
||||||
|
@ -19,10 +19,6 @@ export class DateToggleComponent implements OnInit, OnChanges {
|
||||||
private fromNowPipe: FromNowPipe
|
private fromNowPipe: FromNowPipe
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
ngOnInit () {
|
|
||||||
this.updateDates()
|
|
||||||
}
|
|
||||||
|
|
||||||
ngOnChanges () {
|
ngOnChanges () {
|
||||||
this.updateDates()
|
this.updateDates()
|
||||||
}
|
}
|
||||||
|
@ -32,15 +28,19 @@ export class DateToggleComponent implements OnInit, OnChanges {
|
||||||
}
|
}
|
||||||
|
|
||||||
getTitle () {
|
getTitle () {
|
||||||
return this.toggled ? this.dateRelative : this.dateAbsolute
|
return this.toggled
|
||||||
|
? this.dateRelative
|
||||||
|
: this.dateAbsolute
|
||||||
}
|
}
|
||||||
|
|
||||||
getContent () {
|
getContent () {
|
||||||
return this.toggled ? this.dateAbsolute : this.dateRelative
|
return this.toggled
|
||||||
|
? this.dateAbsolute
|
||||||
|
: this.dateRelative
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateDates () {
|
private updateDates () {
|
||||||
this.dateRelative = this.fromNowPipe.transform(this.date)
|
this.dateRelative = this.fromNowPipe.transform(this.date)
|
||||||
this.dateAbsolute = this.datePipe.transform(this.date, 'long')
|
this.dateAbsolute = this.date.toLocaleDateString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 { platformBrowserDynamic } from '@angular/platform-browser-dynamic'
|
||||||
|
|
||||||
import { AppModule } from './app/app.module'
|
import { AppModule } from './app/app.module'
|
||||||
import { environment } from './environments/environment'
|
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
|
return bootstrapModule
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
|
|
Loading…
Reference in New Issue