Renamed many components + started implementing lazy loading

This commit is contained in:
X4Lo committed 2024-04-05 22:12:05 +00:00
1 parent c8578ccf77
commit 60b517500f
80 files changed
+274 -242

No files matched your search

@@ -0,0 +1,176 @@
.movie-card {
cursor: pointer;
display: flex;
flex-direction: column;
}
.movie-card .card-head {
position: relative;
border-radius: 10px;
height: auto;
overflow: hidden;
margin-bottom: 15px;
}
.movie-card .card-img {
width: 100%;
height: auto;
aspect-ratio: 2 / 3;
object-fit: cover;
transition: transform 0.3s ease;
}
.movie-card .card-body {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
background: rgba(0, 0, 0, 0.5);
color: #fff;
padding: 10px;
box-sizing: border-box;
transition: max-height 0.3s ease, padding 0.3s ease;
overflow: hidden;
max-height: 60px;
}
/* * HOVER */
.movie-card:hover .card-img {
transform: scale(1.1);
}
.movie-card .card-overlay {
position: absolute;
inset: 0;
opacity: 0;
backdrop-filter: blur(2px);
}
.movie-card:hover .card-overlay {
opacity: 1;
transition: 0.3s ease;
}
.movie-card:hover .card-body {
max-height: 100px;
padding: 12px;
}
.movie-card:hover .card-title {
white-space: normal;
}
/* ! HOVER END*/
/* * BUTTONS */
.movie-card .bookmark,
.movie-card .info,
.movie-card .rating {
position: absolute;
top: 15px;
padding: 6px;
border-radius: 10px;
color: var(--light-azure);
transform: scale(var(--mv-card-scale));
background: rgba(51, 50, 50, 0.224);
color: var(--white);
}
.movie-card .bookmark {
left: 15px;
}
.movie-card .info {
left: 15px;
top: 60px;
}
.movie-card .bookmark i,
.movie-card .info i {
size: 50px;
font-size: 30px;
}
.movie-card .bookmark:hover,
.movie-card .info:hover {
color: var(--light-azure);
background: rgba(0, 0, 0, 0.5);
transition: color 0.3s ease, background-color 0.3s ease;
}
.movie-card:hover :is(.bookmark, .rating, .info) {
--mv-card-scale: 1;
}
.bookmark,
.info {
display: flex;
justify-content: center;
align-items: center;
}
/* ? rating */
.movie-card .rating {
display: flex;
align-items: center;
right: 15px;
/* color: var(--light-azure); */
color: var(--white);
}
.movie-card .rating span {
/* color: var(--light-azure); */
color: var(--white);
font-size: 15px;
font-weight: var(--fw-5);
margin-left: 5px;
}
.movie-card .rating i {
font-size: 15px;
font-weight: var(--fw-5);
}
/* ! BUTTONS */
.movie-card .card-title {
font-size: 1.05em;
font-weight: var(--fw-5);
margin-bottom: 5px;
width: auto;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.movie-card:hover .card-title,
.movie-card:hover .card-info {
text-overflow: clip;
color: var(--white);
}
.movie-card:hover .card-title {
color: var(--yellow);
}
.movie-card .card-info {
display: flex;
font-family: -apple-system, "Segoe UI", BlinkMacSystemFont, sans-serif;
font-size: 15px;
font-weight: 400;
}
.movie-card .duration {
margin-right: 8px;
}
.card-dot {
width: 3px;
height: 3px;
vertical-align: 2px;
border-radius: 50%;
display: inline-block;
background: #6d7583;
content: "";
margin: 9px 6px;
}
.movie-card .card-title,
.movie-card .card-info {
color: #fff;
}
@@ -0,0 +1,36 @@
<div class="movie-card" @fadeInOut>
<div class="card-head">
<img class="card-img" [src]="getPostPath()" alt="Movie Poster">
<div class="card-overlay" (click)="cardClick()">
<div class="rating">
<i class='bx bx-star'></i>
<span>{{formattedRate}}</span>
</div>
<div class="bookmark" *ngIf="!entry.isInLibrary">
<i class='bx bxs-add-to-queue' (click)="addEntry(entry.entryId.tmdb_id, entry.is_tvseries)"></i>
</div>
<div class="bookmark" *ngIf="entry.isInLibrary">
<i class='bx bxs-trash' (click)="removeEntry(entry.id)" style="color: #d42f50;"></i>
</div>
<!-- <div [ngClass]="{'info': !entry.isInLibrary, 'bookmark': entry.isInLibrary}"> -->
<div class="info" *ngIf="entry.isInLibrary">
<i class='bx bx-list-plus' (click)="showAddToListModal()"></i>
</div>
</div>
<!-- card body moved inside card head -->
<div class="card-body" (click)="cardClick()">
<a [href]="getTmdbLink()" target="_blank" rel="noopener noreferrer">
<h3 class="card-title">{{ entry.title }}</h3>
</a>
<div class="card-info">
<span class="Year">{{releaseYear}}</span>
<i class="card-dot"></i>
<span class="duration">137 min</span>
</div>
</div>
</div>
</div>
@@ -0,0 +1,21 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MainCardComponent } from './main-card.component';
describe('MainCardComponent', () => {
let component: MainCardComponent;
let fixture: ComponentFixture<MainCardComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [MainCardComponent]
});
fixture = TestBed.createComponent(MainCardComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,117 @@
import { Component, Input, OnInit } from '@angular/core';
import { ListSelectionModalComponent } from '../../modals/list-selection-modal/list-selection-modal.component';
import { MatDialog } from '@angular/material/dialog';
import { trigger, transition, style, animate } from '@angular/animations';
import { Entry } from '../../../models/entry.model';
import { LibraryService } from '../../../../core/services/library.service';
@Component({
selector: 'app-main-card',
templateUrl: './main-card.component.html',
styleUrls: ['./main-card.component.css'],
animations: [
trigger('fadeInOut', [
transition(':enter', [
// :enter is alias for 'void => *'
style({ opacity: 0 }),
animate('0.5s ease-out', style({ opacity: 1 })),
]),
transition(':leave', [
// :leave is alias for '* => void'
animate('0.5s ease-in', style({ opacity: 0 })),
]),
]),
],
})
export class MainCardComponent implements OnInit {
@Input() entry!: Entry;
constructor(
private libraryService: LibraryService,
public dialog: MatDialog
) {}
ngOnInit(): void {
this.libraryService.isInLibrary(this.entry.entryId.tmdb_id).subscribe({
next: (e) => {
if (e != null) {
e.isInLibrary = true;
this.entry = e;
}
},
error: (error) => {},
});
}
get releaseYear(): number {
return new Date(this.entry.release_date).getFullYear();
}
get formattedRate(): string {
return this.entry.entryRating.tmdb_rating.toFixed(1);
}
addEntry(tmdb_id: string, is_tvserie: boolean) {
console.log('Adding Entry To Library.');
this.libraryService.addEntry(tmdb_id, is_tvserie).subscribe({
next: (entry) => {
if (entry != null) {
entry.isInLibrary = true;
this.entry = entry;
this.libraryService.getAllEntries(true);
}
},
error: (error) => {
console.error('Error adding entry:', error);
},
});
}
removeEntry(id: number) {
console.log('Deleting Entry From Library.');
this.libraryService.deleteEntry(id).subscribe({
next: (response) => {
// Handle successful deletion
console.log('Entry successfully deleted.', response);
this.entry.id = 0;
this.entry.isInLibrary = false;
},
error: (error) => {
// Handle error scenario
console.error('Error deleting entry:', error);
// Optionally, display an error message to the user using a service or a component
},
});
}
showAddToListModal() {
if (this.entry) {
const dialogRef = this.dialog.open(ListSelectionModalComponent, {
width: '400px',
height: '55%',
data: {
entryId: this.entry.id,
},
});
dialogRef.afterClosed().subscribe((result) => {
console.log('Modal Closed: ', result);
});
}
}
cardClick() {
console.log(this.entry);
}
getTmdbLink() {
let type = this.entry.is_tvseries ? 'tv' : 'movie';
return `https://www.themoviedb.org/${type}/${this.entry.entryId.tmdb_id}`;
}
getPostPath() {
if (this.entry.poster_path == null) return 'assets/images/default/default-poster.png';
return `https://image.tmdb.org/t/p/w500` + this.entry.poster_path;
}
}
@@ -0,0 +1,12 @@
.movies-container {
display: grid;
grid-template-columns: repeat(auto-fill,
minmax(160px, 2fr));
gap: 20px;
}
.pagination-container {
display: flex;
justify-content: center;
align-items: center;
}
@@ -0,0 +1,4 @@
<!-- Entries Container/Grid -->
<div class="movies-container">
<app-main-card *ngFor="let entry of entries" [entry]="entry"></app-main-card>
</div>
@@ -0,0 +1,21 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { DynamicEntryListComponent } from './dynamic-entry-list.component';
describe('DynamicEntryListComponent', () => {
let component: DynamicEntryListComponent;
let fixture: ComponentFixture<DynamicEntryListComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [DynamicEntryListComponent]
});
fixture = TestBed.createComponent(DynamicEntryListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,11 @@
import { Component, Input } from '@angular/core';
import { Entry } from '../../../../shared/models/entry.model';
@Component({
selector: 'app-dynamic-entry-list',
templateUrl: './dynamic-entry-list.component.html',
styleUrls: ['./dynamic-entry-list.component.css'],
})
export class DynamicEntryListComponent {
@Input() entries: Entry[] = [];
}
@@ -0,0 +1,16 @@
.movies-container {
display: grid;
grid-template-columns: repeat(
auto-fill,
minmax(200px, 1fr)
); /* Creates a responsive grid */
gap: 20px; /* Space between items */
/* padding: 20px;Padding around the grid */
}
.pagination-container {
display: flex;
justify-content: center;
align-items: center;
}
@@ -0,0 +1,20 @@
<!-- Entries Container/Grid -->
<div class="movies-container">
<app-main-card *ngFor="let entry of entries" [entry]="entry"></app-main-card>
</div>
<!-- Pagination -->
<div class="pagination-container">
<ul class="pagination pagination-sm">
<li class="page-item" [class.disabled]="currentPage === 1">
<a class="page-link" href="javascript:;" (click)="goToPage(currentPage - 1)">Previous</a>
</li>
<!-- Dynamically generate page numbers -->
<li class="page-item" *ngFor="let page of pageNumbers" [class.active]="currentPage === page">
<a class="page-link" href="javascript:;" (click)="goToPage(page)">{{ page }}</a>
</li>
<li class="page-item">
<a class="page-link" href="javascript:;" (click)="goToPage(currentPage + 1)">Next</a>
</li>
</ul>
</div>
@@ -0,0 +1,21 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { EntryListComponent } from './entry-list.component';
describe('EntryListComponent', () => {
let component: EntryListComponent;
let fixture: ComponentFixture<EntryListComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [EntryListComponent]
});
fixture = TestBed.createComponent(EntryListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,59 @@
import { Component, Input, OnInit } from '@angular/core';
import { TmdbService } from '../../../core/services/tmdb.service';
import { Entry } from '../../../shared/models/entry.model';
@Component({
selector: 'app-entry-list',
templateUrl: './entry-list.component.html',
styleUrls: ['./entry-list.component.css'],
})
export class EntryListComponent implements OnInit {
@Input() isMovies: boolean = true;
@Input() type: string = '';
entries: Entry[] = [];
pages: Record<number, Entry[]> = {};
currentPage: number = 1;
constructor(private tmdbService: TmdbService) {}
ngOnInit() {
this.fetchMovies();
}
fetchMovies() {
if (this.type == 'popular') {
if (this.pages[this.currentPage]) {
console.log('page existe deja');
this.entries = this.pages[this.currentPage];
} else {
console.log("page n'existe pas");
this.tmdbService
.getPopular(this.currentPage, this.isMovies)
.subscribe((myEntries) => {
this.pages[this.currentPage] = myEntries;
this.entries = this.pages[this.currentPage];
});
}
} else if (this.type == 'trending') {
this.tmdbService
.getTrending(this.currentPage, this.isMovies, 'day')
.subscribe((myEntries) => (this.entries = myEntries));
}
}
goToPage(page: number) {
this.currentPage = page;
this.fetchMovies();
}
get pageNumbers(): number[] {
this.currentPage = this.currentPage <= 0 ? 1 : this.currentPage; // page <= 0 fix
let startPage = this.currentPage <= 3 ? 1 : this.currentPage - 2;
let endPage = startPage + 4;
return Array.from(
{ length: endPage - startPage + 1 },
(_, i) => startPage + i
);
}
}
@@ -0,0 +1,36 @@
.modal-content {
padding: 20px 20px 0 20px;
}
.modal-body {
padding-right: 5px;
padding-left: 5px;
margin-bottom: 10px;
}
.modal-footer {
margin-bottom: 15px;
}
.modal-input {
padding-right: 10px !important;
}
.simplebar-content-wrapper {
padding-right: 10px;
}
.simplebar-content-wrapper {
max-height: 300px;
overflow-y: auto;
}
.user-lists {
height: 100%;
background-color: var(--bs-body-bg) !important;
border-right: 1px solid var(--bs-border-color);
}
.user-lists .btn {
color: var(--bs-border-color);
}
@@ -0,0 +1,57 @@
<!-- <h2 mat-dialog-title>Choose a list</h2>
<mat-dialog-content>
<mat-form-field appearance="fill">
<mat-label>List Name</mat-label>
<input [formControl]="searchControl" matInput>
</mat-form-field>
<mat-dialog-actions align="center" *ngIf="doShowAddButton()">
<button mat-button (click)="createList()" *ngIf="doShowAddButton()">Create List</button>
</mat-dialog-actions>
<mat-selection-list #shoes (selectionChange)="onSelectionChange($event)">
<mat-list-option *ngFor="let list of listsToShow" [value]="list.id" checkboxPosition="before">
{{list.name}}
</mat-list-option>
</mat-selection-list>
</mat-dialog-content>
<mat-dialog-actions align="end">
<button mat-button [mat-dialog-close]="true">OK</button>
<button mat-button mat-dialog-close>Cancel</button>
</mat-dialog-actions> -->
<div class="modal-content user-lists">
<div class="modal-header">
<h2 class="modal-title">Choose a list</h2>
<button type="button" class="btn-close" (click)="closeDialog()"></button>
</div>
<!-- Modal Body -->
<div class="modal-body">
<div class="input-group mb-3 ">
<!-- <label for="listNameInput" class="form-label">List Name</label> -->
<input type="text" class="form-control" id="listNameInput" [formControl]="searchControl"
placeholder="List name..." @scaleInOut>
<button class="btn btn-success growing-width-element" type="button" *ngIf="doShowAddButton()" (click)="createList()" @scaleInOut>Create
List</button>
</div>
<div class="d-grid gap-2" *ngIf="doShowAddButton()">
</div>
<div data-simplebar class="simplebar-content-wrapper">
<div class="list-group">
<label *ngFor="let list of listsToShow" class="list-group-item">
<input class="form-check-input me-1" type="checkbox" [value]="list.id"
(change)="onSelectionChange(list, $event)" [checked]="list.isChecked">
{{ list.name }}
</label>
</div>
</div>
</div>
<!-- Modal Footer -->
<div class="modal-footer">
<div class="btn-group">
<!-- <button type="button" class="btn btn-secondary" (click)="closeDialog()">Cancel</button> -->
<button type="button" class="btn btn-primary" (click)="confirmSelection()">OK</button>
</div>
</div>
</div>
@@ -0,0 +1,21 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ListSelectionModalComponent } from './list-selection-modal.component';
describe('ListSelectionModalComponent', () => {
let component: ListSelectionModalComponent;
let fixture: ComponentFixture<ListSelectionModalComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [ListSelectionModalComponent]
});
fixture = TestBed.createComponent(ListSelectionModalComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,171 @@
import { Component, Inject, Input, OnInit, ViewChild } from '@angular/core';
import { FormControl } from '@angular/forms';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { ListService } from '../../../../core/services/list.service';
import { NotificationPopupComponent } from '../../notification-popup/notification-popup.component';
import { NotificationService } from '../../../services/notification.service';
import { UserCollection } from '../../../../shared/models/userCollection.model';
import {
trigger,
state,
style,
transition,
animate,
} from '@angular/animations';
@Component({
selector: 'app-list-selection-modal',
templateUrl: './list-selection-modal.component.html',
styleUrls: ['./list-selection-modal.component.css'],
animations: [
trigger('fadeInOut', [
state('in', style({ opacity: 1 })),
transition(':enter', [style({ opacity: 0 }), animate(600)]),
transition(':leave', [animate(600, style({ opacity: 0 }))]),
]),
trigger('scaleInOut', [
transition(':enter', [
state('in', style({ opacity: 1 })),
style({ transform: 'scale(0)' }),
animate('200ms ease-in-out', style({ transform: 'scale(1)' })),
]),
transition(':leave', [
animate('200ms ease-in-out', style({ transform: 'scale(0)' })),
]),
]),
],
})
export class ListSelectionModalComponent implements OnInit {
@Input() entryId: number = 0;
@ViewChild(NotificationPopupComponent)
notificationComponent!: NotificationPopupComponent;
searchControl = new FormControl('');
showAddButton: boolean = false;
lists: UserCollection[] = [];
listsToShow: UserCollection[] = [];
constructor(
public dialogRef: MatDialogRef<ListSelectionModalComponent>,
@Inject(MAT_DIALOG_DATA) public data: any,
private listService: ListService,
private notificationService: NotificationService
) {}
ngOnInit() {
this.entryId = this.data.entryId;
this.getLists();
this.searchControl.valueChanges.subscribe((value) => {
this.applyFilter(value);
});
}
getLists() {
this.listService.getLists().subscribe({
next: (l) => {
l.forEach((list) => {
if (
list.listEntries.some((entry) => entry.entry_id == this.entryId)
) {
list.isChecked = true;
}
});
this.lists = l;
this.listsToShow = this.lists;
this.applyFilter(this.searchControl.value);
},
error: (error) => {
console.log("Counldn't get lists from backend.");
},
});
}
applyFilter(filterValue: string | null) {
if (filterValue == null) {
this.listsToShow = [...this.lists]; // Show all lists if filter is cleared or null
this.showAddButton = false; // Assuming you want to hide the button when there's no filter
return;
}
const normalizedFilter = filterValue.toLowerCase().trim();
this.listsToShow = this.lists.filter((list) =>
list.name.toLowerCase().trim().includes(normalizedFilter)
);
this.showAddButton = this.listsToShow.length === 0;
}
createList() {
const listName = this.searchControl.value; // string
let myNewList = { name: listName } as UserCollection;
this.listService.createList(myNewList).subscribe(async (list) => {
await this.getLists();
});
}
doShowAddButton(): boolean {
return this.showAddButton;
}
onSelectionChange(list: UserCollection, event: Event): void {
const inputElement = event.target as HTMLInputElement;
const isChecked = inputElement.checked;
if (isChecked || isChecked == null) {
console.log(`Adding Entry ${this.entryId} to list: ${list.name}`);
this.listService
.addEntryToList(list.id, this.entryId, list.listEntries.length + 1)
.subscribe({
next: (response) => {
console.log('Success:', response);
this.getLists();
this.showNotification(
'Entry Added',
'Entry added successfully',
'success'
);
},
error: (error) => {
console.error('Error:', error);
this.showNotification('Error', 'Failed to add entry', 'error');
},
});
} else {
console.log(`Removing Entry ${this.entryId} from list: ${list.name}`);
this.listService
.removeEntryFromList(list.id.toString(), this.entryId)
.subscribe({
next: (_) => {
this.showNotification(
'Entry Removed',
'Entry removed successfully',
'success'
);
},
error: (error) => {
console.error('Error removing entry:', error);
this.showNotification('Error', 'Failed to remove entry', 'error');
},
});
}
}
closeDialog(): void {
this.dialogRef.close();
}
confirmSelection(): void {
this.dialogRef.close(/* Optionally pass back some data */);
}
showNotification(title: string, message: string, type: string): void {
// this.notificationComponent.showNotification(message, type);
this.notificationService.showNotification(title, message, type);
}
}
@@ -1,7 +1,7 @@
import { Entry } from './entry.model';
import { ListEntry } from './listEntry.model';
export interface List {
export interface UserCollection {
id: number;
name: string;
@@ -0,0 +1,8 @@
import { DateFormatPipe } from './date-format.pipe';
describe('DateFormatPipe', () => {
it('create an instance', () => {
const pipe = new DateFormatPipe();
expect(pipe).toBeTruthy();
});
});
@@ -0,0 +1,16 @@
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'dateFormat'
})
export class DateFormatPipe implements PipeTransform {
transform(value: string): string {
if (!value) return '';
const date = new Date(value);
const formatter = new Intl.DateTimeFormat('en-US', { month: 'long', day: '2-digit', year: 'numeric' });
return formatter.format(date);
}
}
@@ -6,7 +6,7 @@ import {
EmbeddedViewRef,
ComponentRef,
} from '@angular/core';
import { NotificationPopupComponent } from '../notification-popup/notification-popup.component';
import { NotificationPopupComponent } from '../components/notification-popup/notification-popup.component';
@Injectable({
providedIn: 'root',
+23 -4
View File
@@ -1,10 +1,29 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { NotificationPopupComponent } from './notification-popup/notification-popup.component';
import { NotificationPopupComponent } from './components/notification-popup/notification-popup.component';
import { DateFormatPipe } from './pipes/date-format/date-format.pipe';
import { MainCardComponent } from './components/cards/main-card/main-card.component';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ListSelectionModalComponent } from './components/modals/list-selection-modal/list-selection-modal.component';
@NgModule({
declarations: [NotificationPopupComponent],
imports: [CommonModule],
exports: [NotificationPopupComponent],
declarations: [
// ? pipes
DateFormatPipe,
// ? components
// NotificationPopupComponent,
// MainCardComponent,
// DynamicEntryListComponent,
// NotificationPopupComponent,
// ListSelectionModalComponent,
// ? modules
],
imports: [CommonModule, FormsModule, ReactiveFormsModule],
exports: [
//NotificationPopupComponent,
DateFormatPipe,
],
})
export class SharedModule {}