Add theme selector

This commit is contained in:
aditya.chandel
2024-12-16 21:53:25 -07:00
parent 696649a24f
commit 61e9580409
13 changed files with 144 additions and 21 deletions
@@ -76,7 +76,7 @@ export class BookMetadataComponent implements OnInit, OnDestroy {
openEditDialog(bookId: number | undefined, libraryId: number | undefined) {
this.dialogRef = this.dialogService.open(BooksMetadataDialogComponent, {
header: 'Metadata: Google Books',
modal: false,
modal: true,
width: '65%',
height: '85%',
data: {
@@ -1,5 +1,6 @@
<div class="dashboard">
<div *ngIf="isLibrariesEmpty; else dashboardScroller">
<div class="dashboard-no-library" *ngIf="isLibrariesEmpty; else dashboardScroller">
<h1 class="no-library-header">
Looks like you haven't added a library yet. Let's add one!
</h1>
@@ -12,6 +12,10 @@
color: var(--text-color);
}
.dashboard-no-library {
margin-top: 3rem;
}
.dashboard .p-dialog {
max-width: 90%;
}
@@ -10,12 +10,12 @@ import {DashboardScrollerComponent} from '../dashboard-scroller/dashboard-scroll
@Component({
selector: 'app-home-page',
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.scss'],
imports: [
Button,
NgIf,
DashboardScrollerComponent
],
styleUrls: ['./dashboard.component.scss'],
providers: [DialogService],
})
export class DashboardComponent {
@@ -30,10 +30,9 @@
<i class="pi pi-upload"></i>
<span>Profile</span>
</button>
<button class="p-link layout-topbar-button" [routerLink]="'/documentation'">
<i class="pi pi-cog"></i>
<span>Settings</span>
</button>
<app-notification></app-notification>
<div class="top-bar-app-theme-switcher">
<app-theme-switcher></app-theme-switcher>
</div>
</div>
</div>
@@ -4,6 +4,7 @@ import {LayoutService} from './service/app.layout.service';
import {RouterLink} from '@angular/router';
import {DialogService as PrimeDialogService, DynamicDialogRef} from 'primeng/dynamicdialog';
import {LibraryCreatorComponent} from '../library-creator/library-creator.component';
import {ThemeSwitcherComponent} from '../../../theme-switcher/theme-switcher.component';
import {TooltipModule} from 'primeng/tooltip';
import {FormsModule} from '@angular/forms';
import {InputTextModule} from 'primeng/inputtext';
@@ -19,7 +20,8 @@ import {FileUploadComponent} from '../file-upload/file-upload.component';
FormsModule,
InputTextModule,
SearchComponent,
NotificationComponent
NotificationComponent,
ThemeSwitcherComponent
],
templateUrl: './app.topbar.component.html',
})
@@ -37,9 +39,20 @@ export class AppTopBarComponent implements OnDestroy {
openLibraryCreatorDialog(): void {
this.ref = this.dialogService.open(LibraryCreatorComponent, {
header: 'Create New Library',
modal: false,
modal: true,
width: '50%',
height: '50%',
style: {bottom: '15%'}
});
}
openFileUploadDialog() {
this.ref = this.dialogService.open(FileUploadComponent, {
header: 'Upload Book',
modal: true,
width: '45%',
height: '40%',
style: {bottom: '20%'}
});
}
@@ -48,14 +61,4 @@ export class AppTopBarComponent implements OnDestroy {
this.ref.close();
}
}
openFileUploadDialog() {
this.ref = this.dialogService.open(FileUploadComponent, {
header: 'Upload Book',
modal: false,
width: '45%',
height: '40%',
style: { bottom: '20%' }
});
}
}
@@ -29,7 +29,7 @@ export class LibraryCreatorComponent {
show() {
this.ref = this.dialogService.open(DirectoryPickerComponent, {
header: 'Select Media Directory',
modal: false,
modal: true,
width: '50%',
height: '75%',
contentStyle: {overflow: 'auto'},
@@ -0,0 +1,11 @@
<div>
<p-dropdown
[options]="themes"
[(ngModel)]="currentTheme"
(onChange)="changeTheme($event)"
id="theme"
optionLabel="label"
optionValue="value"
placeholder="Choose a theme">
</p-dropdown>
</div>
@@ -0,0 +1,59 @@
import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import {DropdownChangeEvent, DropdownModule} from 'primeng/dropdown';
import {FormsModule} from '@angular/forms';
@Component({
selector: 'app-theme-switcher',
templateUrl: './theme-switcher.component.html',
standalone: true,
imports: [
FormsModule,
DropdownModule
],
styleUrl: './theme-switcher.component.scss'
})
export class ThemeSwitcherComponent implements OnInit {
themes: { value: string; label: string }[] = [];
currentTheme: string = '';
constructor(private http: HttpClient) {}
ngOnInit(): void {
this.http
.get<{ value: string; label: string }[]>('assets/themes/themes.json')
.subscribe(
(data) => {
this.themes = data;
const savedTheme = localStorage.getItem('selected-theme');
if (savedTheme) {
this.currentTheme = savedTheme;
this.applyTheme(savedTheme);
} else if (this.themes.length > 0) {
this.currentTheme = this.themes[0].value;
this.applyTheme(this.currentTheme);
}
},
(error) => {
console.error('Error loading themes:', error);
}
);
}
changeTheme(event: DropdownChangeEvent) {
const selectedTheme = event.value;
this.currentTheme = selectedTheme;
this.applyTheme(selectedTheme);
localStorage.setItem('selected-theme', selectedTheme);
}
private applyTheme(theme: string) {
const themeLink = document.getElementById('theme-link') as HTMLLinkElement;
if (themeLink) {
themeLink.href = `assets/layout/styles/theme/${theme}/theme.css`;
console.log(`Theme applied: ${theme}`);
} else {
console.error('Theme link element not found!');
}
}
}