add: saving library view mode to settings

This commit is contained in:
X4Lo committed 2024-06-23 16:59:34 +01:00
1 parent f50cf0ae31
commit 8d9a6a5da1
3 files changed
+61 -40

No files matched your search

@@ -61,4 +61,4 @@ a.clear-filter-link {
.select2 .select2-container .select2-container--default .selection span .select2-selection .select2-selection--multiple { .select2 .select2-container .select2-container--default .selection span .select2-selection .select2-selection--multiple {
padding: 0 !important; padding: 0 !important;
} }
@@ -55,25 +55,25 @@
</div> </div>
<!-- Clear Filter Link --> <!-- Clear Filter Link -->
<a href="javascript:;" class="clear-filter-link" (click)="clearFilter()">Clear Filter</a> <a class="clear-filter-link" (click)="clearFilter()">Clear Filter</a>
</div>
<div class="col-1 justify-content-end" role="status" aria-live="polite">
<button class="btn btn-outline-primary" *ngIf="viewMode == 'grid'" (click)="setViewMode('table')"> <div class="button-container justify-content-end align-items-end">
<span class="material-symbols-outlined"> <button class="btn btn-link align-content-center justify-content-end p-0" *ngIf="viewMode == 'grid'"
table_rows_narrow (click)="setViewMode('table')">
</span> <span class="material-symbols-outlined link-primary">
</button> table_rows_narrow
<button class="btn btn-outline-primary align-content-center align-items-center" *ngIf="viewMode == 'table'" (click)="setViewMode('grid')"> </span>
<span class="material-symbols-outlined"> </button>
grid_on</span> <button class="btn btn-link align-items-center m-0 p-0" *ngIf="viewMode == 'table'" (click)="setViewMode('grid')">
</button> <span class="material-symbols-outlined link-primary">
</div> grid_on
</span>
</button>
</div> </div>
<!-- filter switches END --> <!-- filter switches END -->
</div> </div>
<div class="containder"> <div class="containder">
<div class="row"> <div class="row">
<!-- Search Input for Title --> <!-- Search Input for Title -->
@@ -102,6 +102,7 @@
</select> </select>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<!-- filter end --> <!-- filter end -->
@@ -3,6 +3,8 @@ import { Entry } from '../../../shared/models/entry.model';
import { LibraryService } from '../../../core/services/library.service'; import { LibraryService } from '../../../core/services/library.service';
import { ActivatedRoute, Event, NavigationEnd, Router } from '@angular/router'; import { ActivatedRoute, Event, NavigationEnd, Router } from '@angular/router';
import { LibraryQueryParams } from '../../../shared/models/LibraryQueryParams'; import { LibraryQueryParams } from '../../../shared/models/LibraryQueryParams';
import { SettingsService } from '../../../core/services/settings.service';
import { Settings } from '../../../shared/models/settings.model';
declare var $: any; declare var $: any;
@Component({ @Component({
@@ -77,7 +79,8 @@ export class LibraryPageComponent implements OnInit, AfterViewInit {
constructor( constructor(
private router: Router, private router: Router,
private route: ActivatedRoute, private route: ActivatedRoute,
private libraryService: LibraryService private libraryService: LibraryService,
private settingsService: SettingsService
) {} ) {}
async ngOnInit() { async ngOnInit() {
@@ -94,6 +97,28 @@ export class LibraryPageComponent implements OnInit, AfterViewInit {
await this.populateYears(); await this.populateYears();
} }
ngAfterViewInit() {
$('#year-select')
.select2({
placeholder: 'Year(s)...',
allowClear: true,
closeOnSelect: false,
})
.on('change', (event: { target: any }) => {
this.onYearsChange(event);
});
$('#genre-select')
.select2({
placeholder: 'Genre(s)...',
allowClear: true,
closeOnSelect: false,
})
.on('change', (event: { target: any }) => {
this.onGenresChange(event);
});
}
// ? uses libraryService to get library all entries // ? uses libraryService to get library all entries
getEntries(forceFetch: boolean = false) { getEntries(forceFetch: boolean = false) {
this.libraryService.getAllEntries(forceFetch).subscribe({ this.libraryService.getAllEntries(forceFetch).subscribe({
@@ -110,13 +135,30 @@ export class LibraryPageComponent implements OnInit, AfterViewInit {
} }
getDefaultViewMode() { getDefaultViewMode() {
return 'grid'; this.settingsService.getSettings().subscribe({
next: (s) => {
this.viewMode = s.libraryViewMode || 'grid';
},
error: (error) => {
console.log(`Couldn't get settings information, `, error);
},
});
} }
setViewMode(mode: string) { setViewMode(mode: string) {
this.viewMode = mode; this.viewMode = mode;
const newSettings = { libraryViewMode: this.viewMode } as Settings;
this.settingsService.updateSettings(newSettings).subscribe({
next: (s) => {
// ? view mode updated
},
error: (error) => {
// error updating view mode
},
});
} }
// ! FILTER // ! FILTER
getQueryParameters() { getQueryParameters() {
this.route.queryParams.subscribe((params) => { this.route.queryParams.subscribe((params) => {
@@ -187,28 +229,6 @@ export class LibraryPageComponent implements OnInit, AfterViewInit {
}); });
} }
ngAfterViewInit() {
$('#year-select')
.select2({
placeholder: 'Year(s)...',
allowClear: true,
closeOnSelect: false,
})
.on('change', (event: { target: any }) => {
this.onYearsChange(event);
});
$('#genre-select')
.select2({
placeholder: 'Genre(s)...',
allowClear: true,
closeOnSelect: false,
})
.on('change', (event: { target: any }) => {
this.onGenresChange(event);
});
}
/* /*
* This function will generate a bunch of years starting from 1950 to the current year * This function will generate a bunch of years starting from 1950 to the current year
*/ */