add UserCollection info page
This commit is contained in:
1 parent
bca1b789b3
commit
d4fb225f8e
4 files changed
+146
No files matched your search
Whitespace-only changes.
@@ -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-user-collection-entry-grid [entries]="list.entries" [listId]="getListId()"></app-user-collection-entry-grid>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { ListInfoComponent } from './list-info.component';
|
||||||
|
|
||||||
|
describe('ListInfoComponent', () => {
|
||||||
|
let component: ListInfoComponent;
|
||||||
|
let fixture: ComponentFixture<ListInfoComponent>;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
declarations: [ListInfoComponent]
|
||||||
|
});
|
||||||
|
fixture = TestBed.createComponent(ListInfoComponent);
|
||||||
|
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 { List } from '../../shared/models/list.model';
|
||||||
|
import { Entry } from '../../shared/models/entry.model';
|
||||||
|
import { DatePipe } from '@angular/common';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-list-info',
|
||||||
|
templateUrl: './list-info.component.html',
|
||||||
|
styleUrls: ['./list-info.component.css'],
|
||||||
|
providers: [DatePipe],
|
||||||
|
})
|
||||||
|
export class ListInfoComponent {
|
||||||
|
list: List = {} as List;
|
||||||
|
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 List;
|
||||||
|
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');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user