Improve Angular project structure and code organization (#1328)

This commit is contained in:
Aditya Chandel
2025-10-12 02:01:59 -06:00
committed by GitHub
parent 54a8bacccd
commit 7c9bd56f63
405 changed files with 463 additions and 727 deletions
@@ -0,0 +1,38 @@
<div class="dashboard-scroller-container">
<h2 class="dashboard-scroller-title">{{ title }}</h2>
@if (!books || books.length === 0) {
<div class="dashboard-scroller-no-books">
<div class="empty-state-icon">
<i class="pi pi-book"></i>
</div>
<p>
{{ bookListType === 'lastRead' ? "You haven't read any books yet! Start your reading journey." : "No books have been added to BookLore yet! Add your first book to get started." }}
</p>
</div>
}
@if (books) {
<div class="dashboard-scroller-infinite"
infiniteScroll
[infiniteScrollDistance]="2"
[infiniteScrollThrottle]="50"
#scrollContainer
[horizontal]="true">
@for (book of books; track book) {
<div class="dashboard-scroller-card">
<app-book-card [book]="book" [isCheckboxEnabled]="false"></app-book-card>
</div>
}
</div>
}
@if (books === null) {
<div class="dashboard-scroller-error">
<div class="error-icon">
<i class="pi pi-exclamation-triangle"></i>
</div>
<p>Failed to load books! Please try refreshing the page.</p>
</div>
}
</div>
@@ -0,0 +1,173 @@
.dashboard-scroller-container {
border-radius: 20px;
padding: 1rem 2rem 0rem 2rem;
margin-bottom: 2rem;
position: relative;
overflow: hidden;
backdrop-filter: blur(20px);
border: color-mix(in srgb, var(--p-surface-500), transparent 50%) 1px solid;
}
.dashboard-scroller-title {
text-align: left;
font-size: 1.5rem;
font-weight: 800;
margin-bottom: 1rem;
padding: 0;
background: linear-gradient(135deg, #ffffff, #e2e8f0, #3b82f6);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
position: relative;
z-index: 2;
letter-spacing: -0.02em;
&::after {
content: '';
position: absolute;
bottom: -6px;
left: 0;
width: 80px;
height: 4px;
background: linear-gradient(90deg, var(--primary-color), var(--primary-color));
border-radius: 2px;
}
}
.dashboard-scroller-no-books {
padding: 3rem 2rem;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
position: relative;
z-index: 2;
.empty-state-icon {
width: 25px;
height: 25px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 2rem;
position: relative;
i {
font-size: 2rem;
color: white;
filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}
}
p {
color: #e2e8f0;
font-size: 1rem;
font-weight: 500;
max-width: 400px;
line-height: 1.7;
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}
}
.dashboard-scroller-infinite {
display: flex;
overflow-x: auto;
overflow-y: hidden;
scroll-snap-type: x mandatory;
padding: 1rem 0.5rem 1rem 0.5rem;
gap: 2rem;
height: 100%;
width: 100%;
position: relative;
z-index: 2;
scrollbar-color: var(--primary-color) rgba(20, 20, 30, 0.5);
}
.dashboard-scroller-card {
height: 200px;
width: 116px;
flex-basis: 124px;
flex-shrink: 0;
flex-grow: 0;
scroll-snap-align: start;
transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
position: relative;
&:hover {
transform: translateY(-4px) scale(1.04);
filter: drop-shadow(0 25px 50px rgba(0, 0, 0, 0.4));
&::after {
opacity: 1;
transform: scale(1.2);
}
&::before {
opacity: 0.8;
}
}
&::before {
content: '';
position: absolute;
inset: -2px;
background: linear-gradient(
135deg,
color-mix(in srgb, var(--p-primary-400), transparent 70%),
color-mix(in srgb, var(--p-primary-800), transparent 70%)
);
border-radius: 12px;
z-index: -1;
opacity: 0;
transition: opacity 0.4s ease;
filter: blur(8px);
}
&::after {
content: '';
position: absolute;
bottom: -8px;
left: 10%;
right: 10%;
height: 5px;
background: linear-gradient(
90deg,
transparent,
var(--p-primary-500),
transparent
);
border-radius: 50%;
opacity: 0;
transition: all 0.4s ease;
filter: blur(6px);
}
}
@media (max-width: 767px) {
.dashboard-scroller-card {
height: 184px;
width: 108px;
flex-basis: 108px;
}
.dashboard-scroller-no-books {
padding: 4rem 1rem;
.empty-state-icon {
width: 80px;
height: 80px;
i {
font-size: 2rem;
}
}
p {
font-size: 1.1rem;
}
}
}
@@ -0,0 +1,26 @@
import {Component, ElementRef, Input, OnChanges, OnInit, ViewChild} from '@angular/core';
import {BookCardComponent} from '../../../book/components/book-browser/book-card/book-card.component';
import {InfiniteScrollDirective} from 'ngx-infinite-scroll';
import {ProgressSpinnerModule} from 'primeng/progressspinner';
import {Book} from '../../../book/model/book.model';
@Component({
selector: 'app-dashboard-scroller',
templateUrl: './dashboard-scroller.component.html',
styleUrls: ['./dashboard-scroller.component.scss'],
imports: [
InfiniteScrollDirective,
BookCardComponent,
ProgressSpinnerModule
],
standalone: true
})
export class DashboardScrollerComponent {
@Input() bookListType: 'lastRead' | null = null;
@Input() title: string = 'Last Read Books';
@Input() books!: Book[] | null;
@ViewChild('scrollContainer') scrollContainer!: ElementRef;
}
@@ -0,0 +1,60 @@
<div class="dashboard-container">
@if ((bookState$ | async)?.loaded === false) {
<div class="flex items-center justify-center h-full">
<p-progressSpinner
styleClass="spinner center-spinner"
[style]="{'width': '60px', 'height': '60px'}"
strokeWidth="3"
fill="transparent"
animationDuration="1.5s">
</p-progressSpinner>
</div>
}
@if ((bookState$ | async)?.loaded === true) {
<div class="dashboard">
<div class="w-full">
@if (isLibrariesEmpty$ | async) {
<div class="dashboard-no-library">
@if ((userService.userState$ | async)?.user?.permissions; as permissions) {
<div>
@if (permissions.admin || permissions.canManipulateLibrary) {
<div>
<h1 class="no-library-header">
Welcome to BookLore!<br>
Let's create your first library
</h1>
<p class="text-gray-300 mb-8 mx-auto leading-relaxed">
A library is where all your books live. Start building your digital collection today!
</p>
<p-button
label="Create Your Library"
icon="pi pi-plus"
styleClass="p-button-rounded p-button-outlined"
(click)="createNewLibrary()">
</p-button>
</div>
}
</div>
}
</div>
} @else {
<app-dashboard-scroller
[books]="lastReadBooks$ | async"
[bookListType]="'lastRead'"
[title]="'Continue Reading'">
</app-dashboard-scroller>
<app-dashboard-scroller
[books]="latestAddedBooks$ | async"
[title]="'Recently Added'">
</app-dashboard-scroller>
<app-dashboard-scroller
[books]="randomBooks$ | async"
[title]="'Discover Something New'">
</app-dashboard-scroller>
}
</div>
</div>
}
</div>
@@ -0,0 +1,81 @@
.dashboard-container {
height: calc(100dvh - 6.7rem);
overflow-y: auto;
position: relative;
&::before {
content: '';
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
pointer-events: none;
z-index: 0;
}
&::-webkit-scrollbar {
width: 12px;
}
&::-webkit-scrollbar-track {
background: rgba(20, 20, 30, 0.5);
border-radius: 10px;
}
scrollbar-width: thin;
scrollbar-color: var(--primary-color) rgba(20, 20, 30, 0.5);
}
@media (max-width: 768px) {
.dashboard-container {
height: calc(100dvh - 5rem);
&::-webkit-scrollbar {
width: 8px;
}
}
}
.dashboard {
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
position: relative;
z-index: 1;
}
.dashboard .no-library-header {
font-size: 1.75rem;
font-weight: 700;
margin-bottom: 2rem;
background: linear-gradient(135deg, #ffffff, #e2e8f0, var(--p-primary-500));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
letter-spacing: -0.02em;
}
.dashboard-no-library {
padding: 3rem;
background: var(--p-surface-900);
border-radius: 24px;
border: 1px solid rgba(255, 255, 255, 0.1);
backdrop-filter: blur(20px);
position: relative;
overflow: hidden;
}
.dashboard .p-dialog {
max-width: 90%;
}
::ng-deep .p-dialog-mask {
background-color: rgba(0, 0, 0, 0.5);
}
::ng-deep .p-dialog-mask {
backdrop-filter: blur(3px);
}
@@ -0,0 +1,94 @@
import {Component, inject, OnInit} from '@angular/core';
import {LibraryCreatorComponent} from '../../../library-creator/library-creator.component';
import {DialogService, DynamicDialogRef} from 'primeng/dynamicdialog';
import {LibraryService} from '../../../book/service/library.service';
import {Observable} from 'rxjs';
import {map} from 'rxjs/operators';
import {Button} from 'primeng/button';
import {AsyncPipe} from '@angular/common';
import {DashboardScrollerComponent} from '../dashboard-scroller/dashboard-scroller.component';
import {BookService} from '../../../book/service/book.service';
import {BookState} from '../../../book/model/state/book-state.model';
import {Book, ReadStatus} from '../../../book/model/book.model';
import {UserService} from '../../../settings/user-management/user.service';
import {ProgressSpinner} from 'primeng/progressspinner';
@Component({
selector: 'app-main-dashboard',
templateUrl: './main-dashboard.component.html',
styleUrls: ['./main-dashboard.component.scss'],
imports: [
Button,
DashboardScrollerComponent,
AsyncPipe,
ProgressSpinner
],
providers: [DialogService],
standalone: true
})
export class MainDashboardComponent implements OnInit {
ref: DynamicDialogRef | undefined;
private bookService = inject(BookService);
private dialogService = inject(DialogService);
protected userService = inject(UserService);
bookState$ = this.bookService.bookState$;
lastReadBooks$: Observable<Book[]> | undefined;
latestAddedBooks$: Observable<Book[]> | undefined;
randomBooks$: Observable<Book[]> | undefined;
isLibrariesEmpty$: Observable<boolean> = inject(LibraryService).libraryState$.pipe(
map(state => !state.libraries || state.libraries.length === 0)
);
ngOnInit(): void {
this.lastReadBooks$ = this.bookService.bookState$.pipe(
map((state: BookState) => (
(state.books || []).filter(book => book.lastReadTime && (book.readStatus === ReadStatus.READING || book.readStatus === ReadStatus.RE_READING || book.readStatus === ReadStatus.PAUSED))
.sort((a, b) => {
const aTime = new Date(a.lastReadTime!).getTime();
const bTime = new Date(b.lastReadTime!).getTime();
return bTime - aTime;
})
.slice(0, 25)
))
);
this.latestAddedBooks$ = this.bookService.bookState$.pipe(
map((state: BookState) => (
(state.books || [])
.filter(book => book.addedOn)
.sort((a, b) => {
const aTime = new Date(a.addedOn!).getTime();
const bTime = new Date(b.addedOn!).getTime();
return bTime - aTime;
})
.slice(0, 25)
))
);
this.randomBooks$ = this.bookService.bookState$.pipe(
map((state: BookState) => this.getRandomBooks(state.books || [], 15))
);
}
private getRandomBooks(books: Book[], count: number): Book[] {
const shuffled = books.sort(() => 0.5 - Math.random());
return shuffled.slice(0, count);
}
createNewLibrary() {
this.ref = this.dialogService.open(LibraryCreatorComponent, {
header: 'Create New Library',
modal: true,
closable: true,
style: {
position: 'absolute',
top: '15%',
}
});
}
}