[O] Display relative time in rating chart

This commit is contained in:
Azalea
2024-03-03 15:31:59 -05:00
parent 48819c10a9
commit ef5d0a81eb
2 changed files with 20 additions and 12 deletions

View File

@@ -61,6 +61,7 @@ export function renderCal(el: HTMLElement, d: {date: any, value: any}[]) {
}
const now = moment()
export const CHARTJS_OPT: ChartOptions<'line'> = {
responsive: true,
maintainAspectRatio: false,
@@ -85,7 +86,21 @@ export const CHARTJS_OPT: ChartOptions<'line'> = {
},
tooltip: {
mode: 'index',
intersect: false
intersect: false,
callbacks: {
title: (tooltipItems) => {
const date = tooltipItems[0].parsed.x;
const diff = now.diff(date, 'days')
return diff ? `${diff} days ago` : 'Today'
}
}
}
},
}
}
export const pfpNotFound = (e: Event) => {
(e.target as HTMLImageElement).src = "/assets/imgs/no_profile.png"
}
export const coverNotFound = (e: Event) => {
(e.target as HTMLImageElement).src = "/assets/imgs/no_cover.jpg"
}