Fix default trending algorithm in admin config

This commit is contained in:
Chocobozzz
2023-02-20 10:17:03 +01:00
parent 5471449f99
commit 15825ef18d
7 changed files with 30 additions and 25 deletions

View File

@@ -44,9 +44,6 @@
<div class="peertube-select-container">
<select id="trendingVideosAlgorithmsDefault" formControlName="default" class="form-control">
<option i18n value="publishedAt">Recently added videos</option>
<option i18n value="originallyPublishedAt">Original publication date</option>
<option i18n value="name">Name</option>
<option i18n value="hot">Hot videos</option>
<option i18n value="most-viewed">Recent views</option>
<option i18n value="most-liked">Most liked videos</option>

View File

@@ -177,9 +177,6 @@ export class VideosListCommonPageComponent implements OnInit, OnDestroy, Disable
case 'best':
return '-hot'
case 'name':
return 'name'
default:
return '-' + algorithm as VideoSortField
}

View File

@@ -8,7 +8,7 @@ import { ServiceWorkerModule } from '@angular/service-worker'
import localeOc from '@app/helpers/locales/oc'
import { AppRoutingModule } from './app-routing.module'
import { AppComponent } from './app.component'
import { CoreModule, PluginService, ServerService } from './core'
import { CoreModule, PluginService, RedirectService, ServerService } from './core'
import { EmptyComponent } from './empty.component'
import { HeaderComponent, SearchTypeaheadComponent, SuggestionComponent } from './header'
import { HighlightPipe } from './header/highlight.pipe'
@@ -28,13 +28,17 @@ import { SharedUserInterfaceSettingsModule } from './shared/shared-user-settings
registerLocaleData(localeOc, 'oc')
export function loadConfigFactory (server: ServerService, pluginService: PluginService) {
export function loadConfigFactory (server: ServerService, pluginService: PluginService, redirectService: RedirectService) {
const initializeServices = () => {
redirectService.init()
pluginService.initializePlugins()
}
return () => {
const result = server.loadHTMLConfig()
if (result) return result.pipe(tap(() => initializeServices()))
if (result) return result.pipe(tap(() => pluginService.initializePlugins()))
return pluginService.initializePlugins()
initializeServices()
}
}
@@ -84,7 +88,7 @@ export function loadConfigFactory (server: ServerService, pluginService: PluginS
{
provide: APP_INITIALIZER,
useFactory: loadConfigFactory,
deps: [ ServerService, PluginService ],
deps: [ ServerService, PluginService, RedirectService ],
multi: true
}
]

View File

@@ -31,12 +31,15 @@ export class RedirectService {
private serverService: ServerService,
private storage: SessionStorageService
) {
// The config is first loaded from the cache so try to get the default route
}
init () {
const config = this.serverService.getHTMLConfig()
if (config?.instance?.defaultClientRoute) {
if (config.instance.defaultClientRoute) {
this.defaultRoute = config.instance.defaultClientRoute
}
if (config?.trending?.videos?.algorithms?.default) {
if (config.trending.videos.algorithms.default) {
this.defaultTrendingAlgorithm = config.trending.videos.algorithms.default
}
@@ -47,7 +50,7 @@ export class RedirectService {
// Track previous url
this.currentUrl = this.router.url
router.events.subscribe(event => {
this.router.events.subscribe(event => {
if (event instanceof NavigationEnd || event instanceof NavigationCancel) {
if ([ '/401', '/404' ].includes(event.url)) return

View File

@@ -40,7 +40,7 @@ export class ServerService {
loadHTMLConfig () {
try {
return this.loadHTMLConfigLocally()
this.loadHTMLConfigLocally()
} catch (err) {
// Expected in dev mode since we can't inject the config in the HTML
if (environment.production !== false) {