1
0
Fork 0

Improve theme label

This commit is contained in:
Chocobozzz 2022-06-16 14:36:51 +02:00
parent 3256771725
commit 5e93a6d142
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
5 changed files with 48 additions and 26 deletions

View File

@ -15,7 +15,7 @@
<div class="peertube-select-container"> <div class="peertube-select-container">
<select formControlName="default" id="themeDefault" class="form-control"> <select formControlName="default" id="themeDefault" class="form-control">
<option i18n value="default">default</option> <option i18n value="default">{{ getDefaultThemeLabel() }}</option>
<option *ngFor="let theme of getAvailableThemes()" [value]="theme">{{ theme }}</option> <option *ngFor="let theme of getAvailableThemes()" [value]="theme">{{ theme }}</option>
</select> </select>

View File

@ -2,7 +2,7 @@ import { pairwise } from 'rxjs/operators'
import { SelectOptionsItem } from 'src/types/select-options-item.model' import { SelectOptionsItem } from 'src/types/select-options-item.model'
import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core' import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core'
import { FormGroup } from '@angular/forms' import { FormGroup } from '@angular/forms'
import { MenuService } from '@app/core' import { MenuService, ThemeService } from '@app/core'
import { HTMLServerConfig } from '@shared/models' import { HTMLServerConfig } from '@shared/models'
import { ConfigService } from '../shared/config.service' import { ConfigService } from '../shared/config.service'
@ -22,7 +22,8 @@ export class EditBasicConfigurationComponent implements OnInit, OnChanges {
constructor ( constructor (
private configService: ConfigService, private configService: ConfigService,
private menuService: MenuService private menuService: MenuService,
private themeService: ThemeService
) { } ) { }
ngOnInit () { ngOnInit () {
@ -49,8 +50,7 @@ export class EditBasicConfigurationComponent implements OnInit, OnChanges {
} }
getAvailableThemes () { getAvailableThemes () {
return this.serverConfig.theme.registered return this.themeService.getAvailableThemeLabels()
.map(t => t.name)
} }
doesTrendingVideosAlgorithmsEnabledInclude (algorithm: string) { doesTrendingVideosAlgorithmsEnabledInclude (algorithm: string) {
@ -94,6 +94,10 @@ export class EditBasicConfigurationComponent implements OnInit, OnChanges {
})) }))
} }
getDefaultThemeLabel () {
return this.themeService.getDefaultThemeLabel()
}
private checkSignupField () { private checkSignupField () {
const signupControl = this.form.get('signup.enabled') const signupControl = this.form.get('signup.enabled')

View File

@ -1,4 +1,5 @@
import { Injectable } from '@angular/core' import { Injectable } from '@angular/core'
import { capitalizeFirstLetter } from '@root-helpers/string'
import { UserLocalStorageKeys } from '@root-helpers/users' import { UserLocalStorageKeys } from '@root-helpers/users'
import { HTMLServerConfig, ServerConfigTheme } from '@shared/models' import { HTMLServerConfig, ServerConfigTheme } from '@shared/models'
import { environment } from '../../../environments/environment' import { environment } from '../../../environments/environment'
@ -40,6 +41,19 @@ export class ThemeService {
this.listenUserTheme() this.listenUserTheme()
} }
getDefaultThemeLabel () {
if (this.hasDarkTheme()) {
return $localize`Light/Orange or Dark`
}
return $localize`Light/Orange`
}
getAvailableThemeLabels () {
return this.serverConfig.theme.registered
.map(t => capitalizeFirstLetter(t.name))
}
private injectThemes (themes: ServerConfigTheme[], fromLocalStorage = false) { private injectThemes (themes: ServerConfigTheme[], fromLocalStorage = false) {
this.themes = themes this.themes = themes
@ -81,10 +95,7 @@ export class ThemeService {
if (instanceTheme !== 'default') return instanceTheme if (instanceTheme !== 'default') return instanceTheme
// Default to dark theme if available and wanted by the user // Default to dark theme if available and wanted by the user
if ( if (this.hasDarkTheme() && window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
this.themes.find(t => t.name === 'dark') &&
window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
) {
return 'dark' return 'dark'
} }
@ -193,4 +204,8 @@ export class ThemeService {
private getTheme (name: string) { private getTheme (name: string) {
return this.themes.find(t => t.name === name) return this.themes.find(t => t.name === name)
} }
private hasDarkTheme () {
return this.serverConfig.theme.registered.some(t => t.name === 'dark')
}
} }

View File

@ -5,10 +5,10 @@
<div class="peertube-select-container"> <div class="peertube-select-container">
<select formControlName="theme" id="theme" class="form-control"> <select formControlName="theme" id="theme" class="form-control">
<option i18n value="instance-default">Instance default theme ({{ getDefaultThemeLabel() }})</option> <option i18n value="instance-default">{{ instanceName }} default theme ({{ getDefaultInstanceThemeLabel() }})</option>
<option i18n value="default">{{ defaultThemeLabel }}</option> <option i18n value="default">{{ getDefaultThemeLabel() }}</option>
<option *ngFor="let theme of availableThemes" [value]="theme">{{ capitalizeFirstLetter(theme) }}</option> <option *ngFor="let theme of getAvailableThemes()" [value]="theme">{{ theme }}</option>
</select> </select>
</div> </div>
</div> </div>

View File

@ -1,8 +1,7 @@
import { Subject, Subscription } from 'rxjs' import { Subject, Subscription } from 'rxjs'
import { Component, Input, OnDestroy, OnInit } from '@angular/core' import { Component, Input, OnDestroy, OnInit } from '@angular/core'
import { AuthService, Notifier, ServerService, UserService } from '@app/core' import { AuthService, Notifier, ServerService, ThemeService, UserService } from '@app/core'
import { FormReactive, FormValidatorService } from '@app/shared/shared-forms' import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
import { capitalizeFirstLetter } from '@root-helpers/string'
import { HTMLServerConfig, User, UserUpdateMe } from '@shared/models' import { HTMLServerConfig, User, UserUpdateMe } from '@shared/models'
@Component({ @Component({
@ -18,8 +17,6 @@ export class UserInterfaceSettingsComponent extends FormReactive implements OnIn
formValuesWatcher: Subscription formValuesWatcher: Subscription
defaultThemeLabel = $localize`Light/Orange`
private serverConfig: HTMLServerConfig private serverConfig: HTMLServerConfig
constructor ( constructor (
@ -27,14 +24,14 @@ export class UserInterfaceSettingsComponent extends FormReactive implements OnIn
private authService: AuthService, private authService: AuthService,
private notifier: Notifier, private notifier: Notifier,
private userService: UserService, private userService: UserService,
private themeService: ThemeService,
private serverService: ServerService private serverService: ServerService
) { ) {
super() super()
} }
get availableThemes () { get instanceName () {
return this.serverConfig.theme.registered return this.serverConfig.instance.name
.map(t => t.name)
} }
ngOnInit () { ngOnInit () {
@ -61,15 +58,21 @@ export class UserInterfaceSettingsComponent extends FormReactive implements OnIn
} }
getDefaultThemeLabel () { getDefaultThemeLabel () {
const theme = this.serverConfig.theme.default return this.themeService.getDefaultThemeLabel()
if (theme === 'default') return this.defaultThemeLabel
return theme
} }
capitalizeFirstLetter (str: string) { getAvailableThemes () {
return capitalizeFirstLetter(str) return this.themeService.getAvailableThemeLabels()
}
getDefaultInstanceThemeLabel () {
const theme = this.serverConfig.theme.default
if (theme === 'default') {
return this.getDefaultThemeLabel()
}
return theme
} }
updateInterfaceSettings () { updateInterfaceSettings () {