minor style/functions renaming changes

This commit is contained in:
X4Lo committed 2024-04-16 19:13:56 +01:00
1 parent 3374aa9944
commit 8b4c0792c0
13 files changed
+95 -50

No files matched your search

@@ -1,4 +1,4 @@
import { Component } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { UserCollectionService } from '../../../../core/services/userCollection.service';
import { UserCollection } from '../../../../shared/models/userCollection.model';
@@ -11,7 +11,7 @@ import { DatePipe } from '@angular/common';
styleUrls: ['./userCollection-info-page.component.css'],
providers: [DatePipe],
})
export class UserCollectionInfoPageComponent {
export class UserCollectionInfoPageComponent implements OnInit{
list: UserCollection = {} as UserCollection;
createdAt: string = '';
updatedAt: string = '';
@@ -26,7 +26,7 @@ export class UserCollectionInfoPageComponent {
const id = this.route.snapshot.paramMap.get('id');
if (id == null) return;
this.listService.getList(id.toString()).subscribe(
this.listService.getCollection(id.toString()).subscribe(
(data) => {
// Handle the successful reception of data.
this.list = data as unknown as UserCollection;
@@ -55,7 +55,6 @@ export class UserCollectionInfoPageComponent {
}
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);
@@ -71,20 +70,24 @@ export class UserCollectionInfoPageComponent {
const diffInMs = now.getTime() - modifiedDate.getTime();
const diffInDays = diffInMs / (1000 * 60 * 60 * 24);
let isPlural = '';
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`;
if(diffInMinutes >= 2) isPlural = 's'
return `${Math.floor(diffInMinutes)} minute${isPlural} ago`;
}
return `${Math.floor(diffInHours)} hours ago`;
if(diffInHours >= 2) isPlural = 's'
return `${Math.floor(diffInHours)} hour${isPlural} ago`;
}
return `${Math.floor(diffInDays)} days ago`;
if(diffInDays >= 2) isPlural = 's'
return `${Math.floor(diffInDays)} day${isPlural} 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');
}
}