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,34 @@
<!--breadcrumb-->
<div class="page-breadcrumb d-none d-sm-flex align-items-center mb-3">
<div class="breadcrumb-title pe-3">Library</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">List: {{list.name}}</li>
</ol>
</nav>
</div>
</div>
<!--end breadcrumb-->
<div class="card">
<div class="card-body">
<div class="d-flex justify-content-between align-items-center mb-2">
<h5 class="mb-0">{{list.name}}</h5>
<button type="button" class="btn btn-primary btn-sm">
<span class="material-symbols-outlined">
edit
</span>
</button>
</div>
<div>Created - {{createdAt}} | Updated - {{updatedAt}}</div>
<div *ngIf="list.description != ''">{{list.description}}</div>
<hr>
<div>
<app-userCollection-entry-grid [entries]="list.entries" [listId]="getListId()"></app-userCollection-entry-grid>
</div>
</div>
</div>
@@ -0,0 +1,21 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { UserCollectionInfoPageComponent } from './userCollection-info-page.component';
describe('UserCollectionInfoPageComponent', () => {
let component: UserCollectionInfoPageComponent;
let fixture: ComponentFixture<UserCollectionInfoPageComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [UserCollectionInfoPageComponent],
});
fixture = TestBed.createComponent(UserCollectionInfoPageComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,91 @@
import { Component } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ListService } from '../../../../core/services/list.service';
import { UserCollection } from '../../../../shared/models/userCollection.model';
import { Entry } from '../../../../shared/models/entry.model';
import { DatePipe } from '@angular/common';
@Component({
selector: 'app-userCollection-info-page',
templateUrl: './userCollection-info-page.component.html',
styleUrls: ['./userCollection-info-page.component.css'],
providers: [DatePipe],
})
export class UserCollectionInfoPageComponent {
list: UserCollection = {} as UserCollection;
createdAt: string = '';
updatedAt: string = '';
constructor(
private route: ActivatedRoute,
private listService: ListService,
private datePipe: DatePipe
) {}
ngOnInit(): void {
const id = this.route.snapshot.paramMap.get('id');
if (id == null) return;
this.listService.getList(id.toString()).subscribe(
(data) => {
// Handle the successful reception of data.
this.list = data as unknown as UserCollection;
this.list.entries = this.list.entries as Entry[];
this.createdAt = this.getCreatedDate()?.toString() || '';
this.updatedAt = this.getUpdatedAt()?.toString() || '';
console.log('Data received:', this.list);
},
(error) => {
// Handle any error that occurs during the subscription
console.error('Error occurred:', error);
},
() => {
// Handle completion of the Observable
}
);
}
getListId() {
return this.list.id + '';
}
getCreatedDate() {
return this.datePipe.transform(this.list.createdAt, 'dd MMMM, yyyy');
}
getUpdatedAt() {
console.log(1);
const updatedAt = this.list.updatedAt;
// First, check if updatedAt is a valid date string or timestamp
const modifiedDate = new Date(updatedAt);
// Check if the date is invalid
if (isNaN(modifiedDate.getTime())) {
console.error('Invalid date:', updatedAt);
// Handle invalid date, perhaps return a fallback message or undefined
return 'Date not available';
}
const now = new Date();
const diffInMs = now.getTime() - modifiedDate.getTime();
const diffInDays = diffInMs / (1000 * 60 * 60 * 24);
if (diffInDays < 7) {
// Less than a week, show relative time
if (diffInDays < 1) {
const diffInHours = diffInMs / (1000 * 60 * 60);
if (diffInHours < 1) {
const diffInMinutes = diffInMs / (1000 * 60);
return `${Math.floor(diffInMinutes)} minutes ago`;
}
return `${Math.floor(diffInHours)} hours ago`;
}
return `${Math.floor(diffInDays)} days ago`;
} else {
// More than a week, show formatted date
// Ensure datePipe is properly injected and available in the component
return this.datePipe.transform(modifiedDate, 'dd MMMM, yyyy');
}
}
}