Store last selected search plugin and retrieve it after loading.

This commit is contained in:
Exkywor 2020-10-14 12:43:34 -06:00
parent 5169db2d0d
commit 2d45c33dc7

View File

@ -1,4 +1,4 @@
import { Component, OnInit, ViewChild } from '@angular/core'; import { AfterViewInit, ChangeDetectorRef, Component, OnInit, ViewChild } from '@angular/core';
import { OpenLPService } from '../../openlp.service'; import { OpenLPService } from '../../openlp.service';
import { PageTitleService } from '../../page-title.service'; import { PageTitleService } from '../../page-title.service';
@ -11,16 +11,17 @@ import { SearchOptionsComponent } from './search-options/search-options.componen
styleUrls: ['./search.component.scss'], styleUrls: ['./search.component.scss'],
providers: [OpenLPService] providers: [OpenLPService]
}) })
export class SearchComponent implements OnInit { export class SearchComponent implements OnInit, AfterViewInit {
public searchPlugins: PluginDescription[] = []; public searchPlugins: PluginDescription[] = [];
public searchText = null; public searchText = null;
public searchResults = null; public searchResults = null;
public selectedPlugin = 'songs'; public selectedPlugin: string;
public currentPlugin: string; public currentPlugin: string;
public displaySearchOptions: Boolean = false; public displaySearchOptions: Boolean = false;
@ViewChild(SearchOptionsComponent, {static: false}) searchOptions: SearchOptionsComponent; @ViewChild(SearchOptionsComponent, {static: false}) searchOptions: SearchOptionsComponent;
constructor(private pageTitleService: PageTitleService, private openlpService: OpenLPService) { constructor(private pageTitleService: PageTitleService, private openlpService: OpenLPService,
private cdr: ChangeDetectorRef) {
pageTitleService.changePageTitle('Search'); pageTitleService.changePageTitle('Search');
} }
@ -40,6 +41,7 @@ export class SearchComponent implements OnInit {
this.displaySearchOptions = false; this.displaySearchOptions = false;
} }
} }
localStorage.setItem('selectedPlugin', this.selectedPlugin);
} }
sendLive(id) { sendLive(id) {
@ -52,5 +54,16 @@ export class SearchComponent implements OnInit {
ngOnInit() { ngOnInit() {
this.openlpService.getSearchablePlugins().subscribe(items => this.searchPlugins = items); this.openlpService.getSearchablePlugins().subscribe(items => this.searchPlugins = items);
// Retrieve the last selected plugin. Set to 'songs' if it isn't set.
if (localStorage.getItem('selectedPlugin') === null) {
localStorage.setItem('selectedPlugin', 'songs');
}
this.selectedPlugin = localStorage.getItem('selectedPlugin');
}
ngAfterViewInit() {
this.onPluginChange();
this.cdr.detectChanges();
} }
} }