add library page component
This commit is contained in:
1 parent
f0970a07e8
commit
6c8a60656d
4 files changed
+143
No files matched your search
Whitespace-only changes.
@@ -0,0 +1,29 @@
|
|||||||
|
<!--breadcrumb-->
|
||||||
|
<div class="page-breadcrumb d-none d-sm-flex align-items-center mb-3">
|
||||||
|
<div class="breadcrumb-title pe-3">Discover</div>
|
||||||
|
<div class="ps-3">
|
||||||
|
<nav aria-label="breadcrumb">
|
||||||
|
<ol class="breadcrumb mb-0 p-0">
|
||||||
|
<li class="breadcrumb-item">
|
||||||
|
<a href="javascript:;">
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li class="breadcrumb-item active" aria-current="page">Trending</li>
|
||||||
|
</ol>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
<div class="ms-auto">
|
||||||
|
<div class="btn-group">
|
||||||
|
<button type="button" class="btn btn-outline-dark" [class.active]="entryType === 0"
|
||||||
|
(click)="setEntryType(0)">All</button>
|
||||||
|
<button type="button" class="btn btn-outline-dark" [class.active]="entryType === 1"
|
||||||
|
(click)="setEntryType(1)">Movies</button>
|
||||||
|
|
||||||
|
<button type="button" class="btn btn-outline-dark" [class.active]="entryType === 2"
|
||||||
|
(click)="setEntryType(2)">TV-Series</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!--end breadcrumb-->
|
||||||
|
|
||||||
|
<app-dynamic-entry-list [entries]="entries"></app-dynamic-entry-list>
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { LibraryComponent } from './library.component';
|
||||||
|
|
||||||
|
describe('LibraryComponent', () => {
|
||||||
|
let component: LibraryComponent;
|
||||||
|
let fixture: ComponentFixture<LibraryComponent>;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
declarations: [LibraryComponent]
|
||||||
|
});
|
||||||
|
fixture = TestBed.createComponent(LibraryComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
import { Component } from '@angular/core';
|
||||||
|
import { Entry } from '../../../shared/models/entry.model';
|
||||||
|
import { LibraryService } from '../../../core/services/library.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-library',
|
||||||
|
templateUrl: './library.component.html',
|
||||||
|
styleUrls: ['./library.component.css'],
|
||||||
|
})
|
||||||
|
export class LibraryComponent {
|
||||||
|
entryType: number = 0;
|
||||||
|
|
||||||
|
allEntries: Entry[] = [];
|
||||||
|
|
||||||
|
entries: Entry[] = [];
|
||||||
|
|
||||||
|
currentPage: number = 1;
|
||||||
|
pageSize: number = 20;
|
||||||
|
|
||||||
|
constructor(private libraryService: LibraryService) {}
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
console.log('initing');
|
||||||
|
this.fetchEntries();
|
||||||
|
}
|
||||||
|
|
||||||
|
// uses libraryService to get library all content
|
||||||
|
fetchEntries() {
|
||||||
|
this.libraryService.getAllEntries().subscribe({
|
||||||
|
next: (entries) => {
|
||||||
|
this.allEntries = entries;
|
||||||
|
this.filterEntries();
|
||||||
|
},
|
||||||
|
error: (error) => {
|
||||||
|
// Handle any errors, possibly informing the user.
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
filterEntries() {
|
||||||
|
var temp = [] as Entry[];
|
||||||
|
|
||||||
|
// ? type filter
|
||||||
|
if (this.entryType != 0) {
|
||||||
|
this.allEntries.forEach((entry) => {
|
||||||
|
if (Boolean(this.entryType - 1) == entry.is_tvseries) temp.push(entry);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
temp = this.allEntries;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ? title search
|
||||||
|
// let len = temp.length;
|
||||||
|
// for (let i = 0; i < len; i++) {
|
||||||
|
// if (!temp[i].title.toLocaleLowerCase().includes('od')) {
|
||||||
|
// temp.splice(i);
|
||||||
|
// len--;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
const startIndex = (this.currentPage - 1) * this.pageSize;
|
||||||
|
const endIndex = startIndex + this.pageSize;
|
||||||
|
|
||||||
|
this.entries = temp.slice(startIndex, endIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ? pagination
|
||||||
|
goToPage(page: number) {
|
||||||
|
this.currentPage = page;
|
||||||
|
this.fetchEntries();
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ? setter
|
||||||
|
setEntryType(entryType: number) {
|
||||||
|
this.entryType = entryType;
|
||||||
|
this.filterEntries();
|
||||||
|
}
|
||||||
|
|
||||||
|
setPageSize(pageSize: number) {
|
||||||
|
this.pageSize = pageSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user