Introduce reading session tracking with visual insights (#1957)
* Introduce reading session tracking with visual insights (#1957) --------- Co-authored-by: acx10 <acx10@users.noreply.github.com>
This commit is contained in:
+30
@@ -0,0 +1,30 @@
|
||||
<div class="reading-session-heatmap-container">
|
||||
<div class="chart-header">
|
||||
<div class="chart-title">
|
||||
<h3>Reading Session Activity</h3>
|
||||
<p class="chart-description">Daily reading session activity throughout the year</p>
|
||||
</div>
|
||||
<div class="year-selector">
|
||||
<button type="button"
|
||||
class="year-nav-btn"
|
||||
(click)="changeYear(-1)"
|
||||
title="Previous year">
|
||||
<i class="pi pi-chevron-left"></i>
|
||||
</button>
|
||||
<span class="current-year">{{ currentYear }}</span>
|
||||
<button type="button"
|
||||
class="year-nav-btn"
|
||||
(click)="changeYear(1)"
|
||||
title="Next year">
|
||||
<i class="pi pi-chevron-right"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="chart-wrapper">
|
||||
<canvas baseChart
|
||||
[data]="(chartData$ | async) ?? {labels: [], datasets: []}"
|
||||
[options]="chartOptions"
|
||||
[type]="chartType">
|
||||
</canvas>
|
||||
</div>
|
||||
</div>
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
.reading-session-heatmap-container {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.chart-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 0.5rem;
|
||||
gap: 1rem;
|
||||
|
||||
.chart-title {
|
||||
flex: 1;
|
||||
|
||||
h3 {
|
||||
color: var(--text-color, #ffffff);
|
||||
font-size: 1.25rem;
|
||||
font-weight: 500;
|
||||
margin: 0 0 0.5rem 0;
|
||||
}
|
||||
|
||||
.chart-description {
|
||||
color: var(--text-secondary-color);
|
||||
font-size: 0.9rem;
|
||||
margin: 0;
|
||||
line-height: 1.4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.year-selector {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
flex-shrink: 0;
|
||||
|
||||
.year-nav-btn {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||
border-radius: 6px;
|
||||
padding: 0.5rem 0.75rem;
|
||||
color: #ffffff;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
&:hover {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
border-color: rgba(255, 255, 255, 0.3);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
&:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
i {
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
}
|
||||
|
||||
.current-year {
|
||||
font-size: 1.125rem;
|
||||
font-weight: 600;
|
||||
color: #ffffff;
|
||||
min-width: 4.5rem;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
||||
.chart-wrapper {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
min-height: 200px;
|
||||
height: 200px;
|
||||
|
||||
canvas {
|
||||
width: 100% !important;
|
||||
height: auto !important;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.chart-header {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
|
||||
.year-selector {
|
||||
justify-content: center;
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.chart-header {
|
||||
.chart-title {
|
||||
h3 {
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
.chart-description {
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.year-selector {
|
||||
.current-year {
|
||||
font-size: 1rem;
|
||||
min-width: 4rem;
|
||||
}
|
||||
|
||||
.year-nav-btn {
|
||||
padding: 0.4rem 0.6rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
+228
@@ -0,0 +1,228 @@
|
||||
import {Component, inject, Input, OnDestroy, OnInit} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {BaseChartDirective} from 'ng2-charts';
|
||||
import {Chart, ChartConfiguration, ChartData, registerables} from 'chart.js';
|
||||
import {MatrixController, MatrixElement} from 'chartjs-chart-matrix';
|
||||
import {BehaviorSubject, EMPTY, Observable, Subject} from 'rxjs';
|
||||
import {catchError, takeUntil} from 'rxjs/operators';
|
||||
import {ReadingSessionHeatmapResponse, UserStatsService} from '../../../settings/user-management/user-stats.service';
|
||||
|
||||
const DAY_NAMES = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
|
||||
const MONTH_NAMES = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
||||
|
||||
interface MatrixDataPoint {
|
||||
x: number;
|
||||
y: number;
|
||||
v: number;
|
||||
date: string;
|
||||
}
|
||||
|
||||
type SessionHeatmapChartData = ChartData<'matrix', MatrixDataPoint[], string>;
|
||||
|
||||
@Component({
|
||||
selector: 'app-reading-session-heatmap',
|
||||
standalone: true,
|
||||
imports: [CommonModule, BaseChartDirective],
|
||||
templateUrl: './reading-session-heatmap.component.html',
|
||||
styleUrls: ['./reading-session-heatmap.component.scss']
|
||||
})
|
||||
export class ReadingSessionHeatmapComponent implements OnInit, OnDestroy {
|
||||
@Input() initialYear: number = new Date().getFullYear();
|
||||
|
||||
public currentYear: number = new Date().getFullYear();
|
||||
public readonly chartType = 'matrix' as const;
|
||||
public readonly chartData$: Observable<SessionHeatmapChartData>;
|
||||
public readonly chartOptions: ChartConfiguration['options'];
|
||||
|
||||
private readonly userStatsService = inject(UserStatsService);
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
private readonly chartDataSubject: BehaviorSubject<SessionHeatmapChartData>;
|
||||
private maxSessionCount = 1;
|
||||
|
||||
constructor() {
|
||||
this.chartDataSubject = new BehaviorSubject<SessionHeatmapChartData>({
|
||||
labels: [],
|
||||
datasets: [{label: 'Reading Sessions', data: []}]
|
||||
});
|
||||
this.chartData$ = this.chartDataSubject.asObservable();
|
||||
|
||||
this.chartOptions = {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
layout: {
|
||||
padding: {top: 20, bottom: 20, left: 10, right: 10}
|
||||
},
|
||||
plugins: {
|
||||
legend: {display: false},
|
||||
tooltip: {
|
||||
enabled: true,
|
||||
backgroundColor: 'rgba(0, 0, 0, 0.9)',
|
||||
titleColor: '#ffffff',
|
||||
bodyColor: '#ffffff',
|
||||
borderColor: '#ffffff',
|
||||
borderWidth: 1,
|
||||
cornerRadius: 6,
|
||||
displayColors: false,
|
||||
padding: 12,
|
||||
titleFont: {size: 14, weight: 'bold'},
|
||||
bodyFont: {size: 13},
|
||||
callbacks: {
|
||||
title: (context) => {
|
||||
const point = context[0].raw as MatrixDataPoint;
|
||||
const date = new Date(point.date);
|
||||
return date.toLocaleDateString('en-US', {
|
||||
weekday: 'short',
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
day: 'numeric'
|
||||
});
|
||||
},
|
||||
label: (context) => {
|
||||
const point = context.raw as MatrixDataPoint;
|
||||
return `${point.v} reading session${point.v === 1 ? '' : 's'}`;
|
||||
}
|
||||
}
|
||||
},
|
||||
datalabels: {display: false}
|
||||
},
|
||||
scales: {
|
||||
x: {
|
||||
type: 'linear',
|
||||
position: 'top',
|
||||
min: 0,
|
||||
max: 52,
|
||||
ticks: {
|
||||
stepSize: 4,
|
||||
callback: (value) => {
|
||||
const weekNum = value as number;
|
||||
if (weekNum % 4 === 0) {
|
||||
const date = this.getDateFromWeek(this.currentYear, weekNum);
|
||||
return MONTH_NAMES[date.getMonth()];
|
||||
}
|
||||
return '';
|
||||
},
|
||||
color: '#ffffff',
|
||||
font: {family: "'Inter', sans-serif", size: 11}
|
||||
},
|
||||
grid: {display: false},
|
||||
border: {display: false}
|
||||
},
|
||||
y: {
|
||||
type: 'linear',
|
||||
min: 0,
|
||||
max: 6,
|
||||
ticks: {
|
||||
stepSize: 1,
|
||||
callback: (value) => {
|
||||
const dayIndex = value as number;
|
||||
return dayIndex >= 0 && dayIndex <= 6 ? DAY_NAMES[dayIndex] : '';
|
||||
},
|
||||
color: '#ffffff',
|
||||
font: {family: "'Inter', sans-serif", size: 11}
|
||||
},
|
||||
border: {display: false}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
Chart.register(...registerables, MatrixController, MatrixElement);
|
||||
this.currentYear = this.initialYear;
|
||||
this.loadYearData(this.currentYear);
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
public changeYear(delta: number): void {
|
||||
this.currentYear += delta;
|
||||
this.loadYearData(this.currentYear);
|
||||
}
|
||||
|
||||
private loadYearData(year: number): void {
|
||||
this.userStatsService.getHeatmapForYear(year)
|
||||
.pipe(
|
||||
takeUntil(this.destroy$),
|
||||
catchError((error) => {
|
||||
console.error('Error loading reading session heatmap:', error);
|
||||
return EMPTY;
|
||||
})
|
||||
)
|
||||
.subscribe((data) => {
|
||||
this.updateChartData(data);
|
||||
});
|
||||
}
|
||||
|
||||
private updateChartData(sessionData: ReadingSessionHeatmapResponse[]): void {
|
||||
const sessionMap = new Map<string, number>();
|
||||
sessionData.forEach(item => {
|
||||
sessionMap.set(item.date, item.count);
|
||||
});
|
||||
|
||||
this.maxSessionCount = Math.max(1, ...sessionData.map(d => d.count));
|
||||
|
||||
const heatmapData: MatrixDataPoint[] = [];
|
||||
const startDate = new Date(this.currentYear, 0, 1);
|
||||
const endDate = new Date(this.currentYear, 11, 31);
|
||||
|
||||
const firstMonday = new Date(startDate);
|
||||
const dayOfWeek = firstMonday.getDay();
|
||||
const daysToMonday = dayOfWeek === 0 ? 6 : dayOfWeek - 1;
|
||||
firstMonday.setDate(firstMonday.getDate() - daysToMonday);
|
||||
|
||||
let weekIndex = 0;
|
||||
let currentDate = new Date(firstMonday);
|
||||
|
||||
while (currentDate <= endDate || weekIndex === 0) {
|
||||
for (let dayOfWeek = 0; dayOfWeek < 7; dayOfWeek++) {
|
||||
const dateStr = currentDate.toISOString().split('T')[0];
|
||||
|
||||
if (currentDate >= startDate && currentDate <= endDate) {
|
||||
const count = sessionMap.get(dateStr) || 0;
|
||||
|
||||
heatmapData.push({
|
||||
x: weekIndex,
|
||||
y: dayOfWeek,
|
||||
v: count,
|
||||
date: dateStr
|
||||
});
|
||||
}
|
||||
|
||||
currentDate.setDate(currentDate.getDate() + 1);
|
||||
}
|
||||
|
||||
weekIndex++;
|
||||
|
||||
if (currentDate > endDate) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this.chartDataSubject.next({
|
||||
labels: [],
|
||||
datasets: [{
|
||||
label: 'Reading Sessions',
|
||||
data: heatmapData,
|
||||
backgroundColor: (context) => {
|
||||
const point = context.raw as MatrixDataPoint;
|
||||
if (!point?.v) return 'rgba(255, 255, 255, 0.05)';
|
||||
|
||||
const intensity = point.v / this.maxSessionCount;
|
||||
const alpha = Math.max(0.2, Math.min(1.0, intensity * 0.8 + 0.2));
|
||||
return `rgba(106, 176, 76, ${alpha})`;
|
||||
},
|
||||
borderColor: 'rgba(255, 255, 255, 0.1)',
|
||||
borderWidth: 1
|
||||
}]
|
||||
});
|
||||
}
|
||||
|
||||
private getDateFromWeek(year: number, week: number): Date {
|
||||
const date = new Date(year, 0, 1);
|
||||
date.setDate(date.getDate() + (week * 7) - date.getDay());
|
||||
return date;
|
||||
}
|
||||
}
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
<div class="timeline-container">
|
||||
<div class="timeline-header">
|
||||
<div class="header-title">
|
||||
<h3>Reading Session Timeline</h3>
|
||||
<p class="timeline-subtitle">Your reading schedule throughout the week</p>
|
||||
</div>
|
||||
<div class="week-selector">
|
||||
<button type="button"
|
||||
class="week-nav-btn"
|
||||
(click)="changeWeek(-1)"
|
||||
title="Previous week">
|
||||
<i class="pi pi-chevron-left"></i>
|
||||
</button>
|
||||
<div class="week-info">
|
||||
<span class="week-label">Week {{ currentWeek }}</span>
|
||||
<span class="week-dates">{{ getWeekDateRange() }}</span>
|
||||
</div>
|
||||
<button type="button"
|
||||
class="week-nav-btn"
|
||||
(click)="changeWeek(1)"
|
||||
title="Next week">
|
||||
<i class="pi pi-chevron-right"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="timeline-content">
|
||||
<div class="hour-markers">
|
||||
<div class="day-label-spacer"></div>
|
||||
<div class="hour-grid">
|
||||
@for (hour of hourLabels; track $index) {
|
||||
<div class="hour-marker" [class.major]="$index % 3 === 0">
|
||||
<span class="hour-label">{{ hour }}</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="timeline-rows">
|
||||
@for (dayData of timelineData; track dayData.dayOfWeek) {
|
||||
<div class="timeline-row">
|
||||
<div class="day-label">{{ dayData.day }}</div>
|
||||
<div class="timeline-track">
|
||||
<div class="grid-lines">
|
||||
@for (hour of hourLabels; track $index) {
|
||||
<div class="grid-line" [class.major]="$index % 6 === 0"></div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="sessions">
|
||||
@for (session of dayData.sessions; track $index) {
|
||||
<div class="session-block"
|
||||
[ngClass]="'book-type-' + (session.bookType || 'default').toLowerCase()"
|
||||
[style.left.%]="session.left"
|
||||
[style.width.%]="session.width"
|
||||
[style.top]="session.totalLevels > 1 ? 'calc(' + session.level + ' / ' + session.totalLevels + ' * 100% + ' + session.level * 2 + 'px)' : '0'"
|
||||
[style.height]="session.totalLevels > 1 ? 'calc((1 / ' + session.totalLevels + ' * 100%) - ' + (session.totalLevels - 1) * 2 / session.totalLevels + 'px)' : '100%'">
|
||||
<div class="session-content">
|
||||
<span class="session-time">
|
||||
{{ formatTime(session.startHour, session.startMinute) }}
|
||||
</span>
|
||||
<span class="session-duration">
|
||||
{{ formatDuration(session.duration) }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="session-tooltip">
|
||||
<div class="tooltip-content">
|
||||
<div class="tooltip-cover">
|
||||
<img [src]="getCoverUrl(session.bookId)" alt="Book Cover">
|
||||
</div>
|
||||
<div class="tooltip-details">
|
||||
<div class="tooltip-header">
|
||||
<i class="pi pi-book"></i>
|
||||
<span class="tooltip-title">{{ session.bookTitle || 'Reading Session' }}</span>
|
||||
</div>
|
||||
<div class="tooltip-divider"></div>
|
||||
<div class="tooltip-body">
|
||||
<div class="tooltip-row">
|
||||
<i class="pi pi-clock"></i>
|
||||
<span class="tooltip-label">Time:</span>
|
||||
<span class="tooltip-value">
|
||||
{{ formatTime(session.startHour, session.startMinute) }} -
|
||||
{{ formatTime(session.endHour, session.endMinute) }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="tooltip-row">
|
||||
<i class="pi pi-hourglass"></i>
|
||||
<span class="tooltip-label">Duration:</span>
|
||||
<span class="tooltip-value">{{ formatDuration(session.duration) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
+483
@@ -0,0 +1,483 @@
|
||||
.timeline-container {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.timeline-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 0.5rem;
|
||||
gap: 1rem;
|
||||
|
||||
.header-title {
|
||||
flex: 1;
|
||||
|
||||
h3 {
|
||||
color: var(--text-color, #ffffff);
|
||||
font-size: 1.25rem;
|
||||
font-weight: 500;
|
||||
margin: 0 0 0.5rem 0;
|
||||
}
|
||||
|
||||
.timeline-subtitle {
|
||||
color: var(--text-secondary-color);
|
||||
font-size: 0.9rem;
|
||||
margin: 0;
|
||||
line-height: 1.4;
|
||||
}
|
||||
}
|
||||
|
||||
.week-selector {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
flex-shrink: 0;
|
||||
|
||||
.week-nav-btn {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||
border-radius: 6px;
|
||||
padding: 0.5rem 0.75rem;
|
||||
color: #ffffff;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
&:hover {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
border-color: rgba(255, 255, 255, 0.3);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
&:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
i {
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
}
|
||||
|
||||
.week-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
min-width: 100px;
|
||||
|
||||
.week-label {
|
||||
font-size: 1.125rem;
|
||||
font-weight: 600;
|
||||
color: #ffffff;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.week-dates {
|
||||
font-size: 0.8rem;
|
||||
color: var(--text-secondary-color);
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.timeline-content {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.hour-markers {
|
||||
display: flex;
|
||||
margin-bottom: 0.5rem;
|
||||
|
||||
.day-label-spacer {
|
||||
width: 100px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.hour-grid {
|
||||
flex: 1;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(24, 1fr);
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.hour-marker {
|
||||
position: relative;
|
||||
height: 20px;
|
||||
|
||||
&.major {
|
||||
.hour-label {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.hour-label {
|
||||
display: none;
|
||||
font-size: 0.7rem;
|
||||
color: rgba(255, 255, 255, 0.6);
|
||||
position: absolute;
|
||||
left: 0;
|
||||
transform: translateX(-50%);
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
|
||||
.timeline-rows {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.timeline-row {
|
||||
display: flex;
|
||||
align-items: stretch;
|
||||
|
||||
.day-label {
|
||||
width: 50px;
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
color: rgba(255, 255, 255, 0.9);
|
||||
padding-right: 1rem;
|
||||
}
|
||||
|
||||
.timeline-track {
|
||||
flex: 1;
|
||||
position: relative;
|
||||
background: rgba(255, 255, 255, 0.02);
|
||||
border-radius: 4px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
min-height: 40px;
|
||||
}
|
||||
}
|
||||
|
||||
.grid-lines {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(24, 1fr);
|
||||
pointer-events: none;
|
||||
|
||||
.grid-line {
|
||||
border-right: 1px solid rgba(255, 255, 255, 0.05);
|
||||
|
||||
&:last-child {
|
||||
border-right: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.sessions {
|
||||
position: absolute;
|
||||
inset: 4px;
|
||||
pointer-events: none;
|
||||
|
||||
.session-block {
|
||||
position: absolute;
|
||||
border-radius: 4px;
|
||||
pointer-events: auto;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
overflow: visible;
|
||||
box-sizing: border-box;
|
||||
|
||||
&.book-type-epub, &.book-type-default {
|
||||
background: linear-gradient(135deg, #4a90e2 0%, #357abd 100%);
|
||||
box-shadow: 0 2px 8px rgba(74, 144, 226, 0.3);
|
||||
|
||||
&:hover {
|
||||
box-shadow: 0 4px 16px rgba(74, 144, 226, 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
&.book-type-pdf {
|
||||
background: linear-gradient(135deg, #e24a4a 0%, #bd3535 100%);
|
||||
box-shadow: 0 2px 8px rgba(226, 74, 74, 0.3);
|
||||
|
||||
&:hover {
|
||||
box-shadow: 0 4px 16px rgba(226, 74, 74, 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
&.book-type-cbx {
|
||||
background: linear-gradient(135deg, #e2b74a 0%, #bd9635 100%);
|
||||
box-shadow: 0 2px 8px rgba(226, 183, 74, 0.3);
|
||||
|
||||
&:hover {
|
||||
box-shadow: 0 4px 16px rgba(226, 183, 74, 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
&:hover {
|
||||
transform: translateY(-2px);
|
||||
z-index: 10;
|
||||
|
||||
.session-tooltip {
|
||||
opacity: 1;
|
||||
transform: translate(-50%, 0);
|
||||
pointer-events: auto;
|
||||
}
|
||||
}
|
||||
|
||||
.session-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100%;
|
||||
padding: 4px 8px;
|
||||
color: white;
|
||||
font-size: 0.7rem;
|
||||
font-weight: 500;
|
||||
text-align: center;
|
||||
gap: 2px;
|
||||
overflow: hidden;
|
||||
|
||||
.session-time {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
max-width: 100%;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.session-duration {
|
||||
font-size: 0.65rem;
|
||||
opacity: 0.9;
|
||||
white-space: nowrap;
|
||||
line-height: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.session-tooltip {
|
||||
position: absolute;
|
||||
bottom: calc(100% + 15px);
|
||||
left: 50%;
|
||||
transform: translate(-50%, 10px);
|
||||
background: rgba(30, 30, 30, 0.98);
|
||||
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||
border-radius: 8px;
|
||||
padding: 0;
|
||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
|
||||
z-index: 1000;
|
||||
pointer-events: none;
|
||||
min-width: 320px;
|
||||
max-width: 350px;
|
||||
backdrop-filter: blur(10px);
|
||||
opacity: 0;
|
||||
transition: opacity 0.2s ease, transform 0.2s ease;
|
||||
|
||||
.tooltip-content {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.tooltip-cover {
|
||||
flex-shrink: 0;
|
||||
width: 80px;
|
||||
height: 120px;
|
||||
|
||||
img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
border-radius: 4px;
|
||||
background-color: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
}
|
||||
|
||||
.tooltip-details {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.tooltip-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
padding: 0;
|
||||
background: none;
|
||||
|
||||
i {
|
||||
font-size: 1.1rem;
|
||||
color: #4a90e2;
|
||||
}
|
||||
|
||||
.tooltip-title {
|
||||
color: #ffffff;
|
||||
font-weight: 600;
|
||||
font-size: 0.95rem;
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
|
||||
.tooltip-divider {
|
||||
height: 1px;
|
||||
background: linear-gradient(90deg,
|
||||
transparent 0%,
|
||||
rgba(255, 255, 255, 0.1) 50%,
|
||||
transparent 100%);
|
||||
margin: 0.75rem 0;
|
||||
}
|
||||
|
||||
.tooltip-body {
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.625rem;
|
||||
}
|
||||
|
||||
.tooltip-row {
|
||||
display: grid;
|
||||
grid-template-columns: auto auto 1fr;
|
||||
align-items: center;
|
||||
gap: 0.625rem;
|
||||
font-size: 0.875rem;
|
||||
|
||||
i {
|
||||
font-size: 0.875rem;
|
||||
color: rgba(255, 255, 255, 0.6);
|
||||
width: 16px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.tooltip-label {
|
||||
color: rgba(255, 255, 255, 0.7);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.tooltip-value {
|
||||
color: #ffffff;
|
||||
text-align: right;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
|
||||
&::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 100%;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
width: 0;
|
||||
height: 0;
|
||||
border-left: 8px solid transparent;
|
||||
border-right: 8px solid transparent;
|
||||
border-top: 8px solid rgba(30, 30, 30, 0.98);
|
||||
filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.timeline-header {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
|
||||
.week-selector {
|
||||
justify-content: center;
|
||||
margin-top: 0.5rem;
|
||||
|
||||
.week-info {
|
||||
min-width: 120px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.timeline-content {
|
||||
min-height: 300px;
|
||||
padding: 0.75rem;
|
||||
}
|
||||
|
||||
.timeline-row {
|
||||
.day-label {
|
||||
width: 70px;
|
||||
font-size: 0.75rem;
|
||||
padding-right: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
.hour-markers {
|
||||
.day-label-spacer {
|
||||
width: 70px;
|
||||
}
|
||||
}
|
||||
|
||||
.hour-marker {
|
||||
.hour-label {
|
||||
font-size: 0.6rem;
|
||||
}
|
||||
}
|
||||
|
||||
.session-block {
|
||||
.session-content {
|
||||
font-size: 0.65rem;
|
||||
|
||||
.session-duration {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.session-tooltip {
|
||||
min-width: 240px;
|
||||
max-width: 280px;
|
||||
font-size: 0.85rem;
|
||||
|
||||
.tooltip-header {
|
||||
padding: 0.75rem;
|
||||
|
||||
.tooltip-title {
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
}
|
||||
|
||||
.tooltip-body {
|
||||
padding: 0.75rem;
|
||||
}
|
||||
|
||||
.tooltip-row {
|
||||
font-size: 0.8rem;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.timeline-header {
|
||||
.header-title {
|
||||
h3 {
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
.timeline-subtitle {
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.week-selector {
|
||||
.week-info {
|
||||
.week-label {
|
||||
font-size: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.week-nav-btn {
|
||||
padding: 0.4rem 0.6rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
+305
@@ -0,0 +1,305 @@
|
||||
import {Component, inject, Input, OnInit} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {UserStatsService, ReadingSessionTimelineResponse} from '../../../settings/user-management/user-stats.service';
|
||||
import {UrlHelperService} from '../../../../shared/service/url-helper.service';
|
||||
import {BookType} from '../../../book/model/book.model';
|
||||
|
||||
interface ReadingSession {
|
||||
startTime: Date;
|
||||
endTime: Date;
|
||||
duration: number;
|
||||
bookTitle?: string;
|
||||
bookId: number;
|
||||
bookType: BookType;
|
||||
}
|
||||
|
||||
interface TimelineSession {
|
||||
startHour: number;
|
||||
startMinute: number;
|
||||
endHour: number;
|
||||
endMinute: number;
|
||||
duration: number;
|
||||
left: number;
|
||||
width: number;
|
||||
bookTitle?: string;
|
||||
bookId: number;
|
||||
bookType: BookType;
|
||||
level: number;
|
||||
totalLevels: number;
|
||||
}
|
||||
|
||||
interface DayTimeline {
|
||||
day: string;
|
||||
dayOfWeek: number;
|
||||
sessions: TimelineSession[];
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-reading-session-timeline',
|
||||
standalone: true,
|
||||
imports: [CommonModule],
|
||||
templateUrl: './reading-session-timeline.component.html',
|
||||
styleUrls: ['./reading-session-timeline.component.scss']
|
||||
})
|
||||
export class ReadingSessionTimelineComponent implements OnInit {
|
||||
@Input() initialYear: number = new Date().getFullYear();
|
||||
@Input() weekNumber: number = this.getCurrentWeekNumber();
|
||||
|
||||
private userStatsService = inject(UserStatsService);
|
||||
private urlHelperService = inject(UrlHelperService);
|
||||
|
||||
public daysOfWeek = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
||||
public hourLabels: string[] = [];
|
||||
public timelineData: DayTimeline[] = [];
|
||||
public currentYear: number = new Date().getFullYear();
|
||||
public currentWeek: number = this.getCurrentWeekNumber();
|
||||
|
||||
ngOnInit(): void {
|
||||
this.currentYear = this.initialYear;
|
||||
this.currentWeek = this.weekNumber;
|
||||
this.initializeHourLabels();
|
||||
this.loadReadingSessions();
|
||||
}
|
||||
|
||||
private initializeHourLabels(): void {
|
||||
for (let i = 0; i < 24; i++) {
|
||||
const hour = i === 0 ? 12 : i > 12 ? i - 12 : i;
|
||||
const period = i < 12 ? 'AM' : 'PM';
|
||||
this.hourLabels.push(`${hour} ${period}`);
|
||||
}
|
||||
}
|
||||
|
||||
private loadReadingSessions(): void {
|
||||
this.userStatsService.getTimelineForWeek(this.currentYear, this.currentWeek)
|
||||
.subscribe({
|
||||
next: (response) => {
|
||||
const sessions = this.convertResponseToSessions(response);
|
||||
this.processSessionData(sessions);
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Error loading reading sessions:', error);
|
||||
this.processSessionData([]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private convertResponseToSessions(response: ReadingSessionTimelineResponse[]): ReadingSession[] {
|
||||
const sessions: ReadingSession[] = [];
|
||||
|
||||
response.forEach((item) => {
|
||||
const startTime = new Date(item.startDate);
|
||||
const endTime = new Date(item.endDate);
|
||||
const duration = Math.floor((endTime.getTime() - startTime.getTime()) / (1000 * 60));
|
||||
|
||||
sessions.push({
|
||||
startTime,
|
||||
endTime,
|
||||
duration,
|
||||
bookId: item.bookId,
|
||||
bookTitle: item.bookTitle,
|
||||
bookType: item.bookType
|
||||
});
|
||||
});
|
||||
|
||||
return sessions.sort((a, b) => a.startTime.getTime() - b.startTime.getTime());
|
||||
}
|
||||
|
||||
private getCurrentWeekNumber(): number {
|
||||
const now = new Date();
|
||||
const startOfYear = new Date(now.getFullYear(), 0, 1);
|
||||
const days = Math.floor((now.getTime() - startOfYear.getTime()) / (24 * 60 * 60 * 1000));
|
||||
return Math.ceil((days + startOfYear.getDay() + 1) / 7);
|
||||
}
|
||||
|
||||
public changeWeek(delta: number): void {
|
||||
this.currentWeek += delta;
|
||||
|
||||
const weeksInYear = this.getWeeksInYear(this.currentYear);
|
||||
if (this.currentWeek > weeksInYear) {
|
||||
this.currentWeek = 1;
|
||||
this.currentYear++;
|
||||
} else if (this.currentWeek < 1) {
|
||||
this.currentYear--;
|
||||
this.currentWeek = this.getWeeksInYear(this.currentYear);
|
||||
}
|
||||
|
||||
this.loadReadingSessions();
|
||||
}
|
||||
|
||||
private getWeeksInYear(year: number): number {
|
||||
const lastDay = new Date(year, 11, 31);
|
||||
const startOfYear = new Date(year, 0, 1);
|
||||
const days = Math.floor((lastDay.getTime() - startOfYear.getTime()) / (24 * 60 * 60 * 1000));
|
||||
return Math.ceil((days + startOfYear.getDay() + 1) / 7);
|
||||
}
|
||||
|
||||
public getWeekDateRange(): string {
|
||||
const startOfYear = new Date(this.currentYear, 0, 1);
|
||||
const daysToAdd = (this.currentWeek - 1) * 7;
|
||||
const weekStart = new Date(startOfYear.getTime() + daysToAdd * 24 * 60 * 60 * 1000);
|
||||
|
||||
const dayOfWeek = weekStart.getDay();
|
||||
weekStart.setDate(weekStart.getDate() - dayOfWeek);
|
||||
|
||||
const weekEnd = new Date(weekStart);
|
||||
weekEnd.setDate(weekStart.getDate() + 6);
|
||||
|
||||
const formatDate = (date: Date) => {
|
||||
const month = date.toLocaleDateString('en-US', {month: 'short'});
|
||||
const day = date.getDate();
|
||||
return `${month} ${day}`;
|
||||
};
|
||||
|
||||
return `${formatDate(weekStart)} - ${formatDate(weekEnd)}`;
|
||||
}
|
||||
|
||||
private processSessionData(sessions: ReadingSession[]): void {
|
||||
const dayMap = new Map<number, ReadingSession[]>();
|
||||
|
||||
sessions.forEach(session => {
|
||||
const sessionStart = new Date(session.startTime);
|
||||
const sessionEnd = new Date(session.endTime);
|
||||
|
||||
if (sessionStart.getDate() === sessionEnd.getDate()) {
|
||||
const dayOfWeek = sessionStart.getDay();
|
||||
if (!dayMap.has(dayOfWeek)) {
|
||||
dayMap.set(dayOfWeek, []);
|
||||
}
|
||||
dayMap.get(dayOfWeek)!.push(session);
|
||||
} else {
|
||||
let currentStart = new Date(sessionStart);
|
||||
|
||||
while (currentStart < sessionEnd) {
|
||||
const dayOfWeek = currentStart.getDay();
|
||||
const endOfDay = new Date(currentStart);
|
||||
endOfDay.setHours(23, 59, 59, 999);
|
||||
|
||||
const segmentEnd = sessionEnd < endOfDay ? sessionEnd : endOfDay;
|
||||
const segmentDuration = Math.floor((segmentEnd.getTime() - currentStart.getTime()) / (1000 * 60));
|
||||
|
||||
if (!dayMap.has(dayOfWeek)) {
|
||||
dayMap.set(dayOfWeek, []);
|
||||
}
|
||||
|
||||
dayMap.get(dayOfWeek)!.push({
|
||||
startTime: new Date(currentStart),
|
||||
endTime: new Date(segmentEnd),
|
||||
duration: segmentDuration,
|
||||
bookTitle: session.bookTitle,
|
||||
bookId: session.bookId,
|
||||
bookType: session.bookType
|
||||
});
|
||||
|
||||
currentStart = new Date(segmentEnd);
|
||||
currentStart.setDate(currentStart.getDate() + 1);
|
||||
currentStart.setHours(0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.timelineData = [];
|
||||
for (let i = 0; i < 7; i++) {
|
||||
const sessionsForDay = dayMap.get(i) || [];
|
||||
const timelineSessions = this.layoutSessionsForDay(sessionsForDay);
|
||||
|
||||
this.timelineData.push({
|
||||
day: this.daysOfWeek[i],
|
||||
dayOfWeek: i,
|
||||
sessions: timelineSessions
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private layoutSessionsForDay(sessions: ReadingSession[]): TimelineSession[] {
|
||||
if (sessions.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
sessions.sort((a, b) => {
|
||||
if (a.startTime.getTime() !== b.startTime.getTime()) {
|
||||
return a.startTime.getTime() - b.startTime.getTime();
|
||||
}
|
||||
return b.endTime.getTime() - a.endTime.getTime();
|
||||
});
|
||||
|
||||
const tracks: ReadingSession[][] = [];
|
||||
|
||||
sessions.forEach(session => {
|
||||
let placed = false;
|
||||
for (let i = 0; i < tracks.length; i++) {
|
||||
const lastSessionInTrack = tracks[i][tracks[i].length - 1];
|
||||
if (session.startTime >= lastSessionInTrack.endTime) {
|
||||
tracks[i].push(session);
|
||||
placed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!placed) {
|
||||
tracks.push([session]);
|
||||
}
|
||||
});
|
||||
|
||||
const totalLevels = tracks.length;
|
||||
const timelineSessions: TimelineSession[] = [];
|
||||
|
||||
tracks.forEach((track, level) => {
|
||||
track.forEach(session => {
|
||||
timelineSessions.push(this.convertToTimelineSession(session, level, totalLevels));
|
||||
});
|
||||
});
|
||||
|
||||
return timelineSessions;
|
||||
}
|
||||
|
||||
private convertToTimelineSession(session: ReadingSession, level: number, totalLevels: number): TimelineSession {
|
||||
const startHour = session.startTime.getHours();
|
||||
const startMinute = session.startTime.getMinutes();
|
||||
const endHour = session.endTime.getHours();
|
||||
const endMinute = session.endTime.getMinutes();
|
||||
|
||||
const startDecimal = startHour + startMinute / 60;
|
||||
const endDecimal = endHour + endMinute / 60;
|
||||
|
||||
const left = (startDecimal / 24) * 100;
|
||||
let width = ((endDecimal - startDecimal) / 24) * 100;
|
||||
|
||||
if (width < 0.5) {
|
||||
width = 0.5;
|
||||
}
|
||||
|
||||
return {
|
||||
startHour,
|
||||
startMinute,
|
||||
endHour,
|
||||
endMinute,
|
||||
duration: session.duration,
|
||||
left,
|
||||
width,
|
||||
bookTitle: session.bookTitle,
|
||||
bookId: session.bookId,
|
||||
bookType: session.bookType,
|
||||
level,
|
||||
totalLevels
|
||||
};
|
||||
}
|
||||
|
||||
public formatTime(hour: number, minute: number): string {
|
||||
const displayHour = hour === 0 ? 12 : hour > 12 ? hour - 12 : hour;
|
||||
const period = hour < 12 ? 'AM' : 'PM';
|
||||
const displayMinute = minute.toString().padStart(2, '0');
|
||||
return `${displayHour}:${displayMinute} ${period}`;
|
||||
}
|
||||
|
||||
public formatDuration(minutes: number): string {
|
||||
const hours = Math.floor(minutes / 60);
|
||||
const mins = minutes % 60;
|
||||
if (hours > 0) {
|
||||
return mins > 0 ? `${hours}h ${mins}m` : `${hours}h`;
|
||||
}
|
||||
return `${mins}m`;
|
||||
}
|
||||
|
||||
public getCoverUrl(bookId: number): string {
|
||||
return this.urlHelperService.getThumbnailUrl1(bookId);
|
||||
}
|
||||
}
|
||||
@@ -392,16 +392,6 @@
|
||||
}
|
||||
</div>
|
||||
}
|
||||
@case ('readingHeatmap') {
|
||||
<h3>Books Finished per Month</h3>
|
||||
<div class="chart-wrapper reading-heatmap-chart">
|
||||
<canvas baseChart
|
||||
[data]="(readingHeatmapChartService.heatmapChartData$ | async) ?? {labels: [], datasets: []}"
|
||||
[options]="readingHeatmapChartService.heatmapChartOptions"
|
||||
[type]="readingHeatmapChartService.heatmapChartType">
|
||||
</canvas>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
@@ -711,6 +711,40 @@
|
||||
}
|
||||
}
|
||||
|
||||
.year-selector {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 1rem;
|
||||
|
||||
.year-nav-btn {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||
border-radius: 4px;
|
||||
padding: 0.5rem 0.75rem;
|
||||
color: #ffffff;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
|
||||
&:hover {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
border-color: rgba(255, 255, 255, 0.3);
|
||||
}
|
||||
|
||||
i {
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
}
|
||||
|
||||
.current-year {
|
||||
font-size: 1.125rem;
|
||||
font-weight: 600;
|
||||
color: #ffffff;
|
||||
min-width: 4rem;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 1600px) {
|
||||
.charts-grid {
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
|
||||
@@ -31,7 +31,6 @@ import {TopSeriesChartService} from '../service/top-series-chart.service';
|
||||
import {ReadingDNAChartService} from '../service/reading-dna-chart.service';
|
||||
import {ReadingHabitsChartService} from '../service/reading-habits-chart.service';
|
||||
import {ChartConfig, ChartConfigService} from '../service/chart-config.service';
|
||||
import {ReadingHeatmapChartService} from '../service/reading-heatmap-chart.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-stats-component',
|
||||
@@ -71,7 +70,6 @@ export class StatsComponent implements OnInit, OnDestroy {
|
||||
protected readonly readingDNAChartService = inject(ReadingDNAChartService);
|
||||
protected readonly readingHabitsChartService = inject(ReadingHabitsChartService);
|
||||
protected readonly chartConfigService = inject(ChartConfigService);
|
||||
protected readonly readingHeatmapChartService = inject(ReadingHeatmapChartService);
|
||||
private readonly pageTitle = inject(PageTitleService);
|
||||
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
@@ -100,7 +98,6 @@ export class StatsComponent implements OnInit, OnDestroy {
|
||||
|
||||
ngOnInit(): void {
|
||||
Chart.register(...registerables, Tooltip, ChartDataLabels, MatrixController, MatrixElement);
|
||||
// Register matrix chart - it's automatically registered when imported
|
||||
Chart.defaults.plugins.legend.labels.font = {
|
||||
family: "'Inter', sans-serif",
|
||||
size: 11.5,
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<div class="user-stats-container">
|
||||
<div class="header-section">
|
||||
<div class="header-content">
|
||||
<div class="greeting">
|
||||
<i class="pi pi-chart-line"></i>
|
||||
<h2>{{ userName ? userName + "'s Reading Statistics" : "Your Reading Statistics" }}</h2>
|
||||
</div>
|
||||
<p class="subtitle">Track your reading habits and progress</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="charts-container">
|
||||
<div class="chart-card">
|
||||
<app-reading-session-heatmap [initialYear]="currentYear"></app-reading-session-heatmap>
|
||||
</div>
|
||||
|
||||
<div class="chart-card">
|
||||
<app-reading-session-timeline [initialYear]="currentYear"></app-reading-session-timeline>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,147 @@
|
||||
.user-stats-container {
|
||||
max-width: 1800px;
|
||||
margin: 0 auto;
|
||||
padding: 0.5rem;
|
||||
height: calc(100dvh - 6.25rem);
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.header-section {
|
||||
background: var(--card-background);
|
||||
border-radius: 12px;
|
||||
padding: 1.5rem;
|
||||
backdrop-filter: blur(10px);
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
||||
margin-bottom: 2rem;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
transition: all 0.3s ease;
|
||||
width: fit-content;
|
||||
max-width: 100%;
|
||||
|
||||
&:hover {
|
||||
border-color: rgba(255, 255, 255, 0.2);
|
||||
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
.header-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.greeting {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
|
||||
i {
|
||||
font-size: 1.5rem;
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
h2 {
|
||||
color: var(--text-color, #ffffff);
|
||||
font-size: 1.5rem;
|
||||
font-weight: 600;
|
||||
margin: 0;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
color: var(--text-secondary-color);
|
||||
font-size: 0.95rem;
|
||||
margin: 0;
|
||||
padding-left: 0;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
|
||||
.charts-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2rem;
|
||||
}
|
||||
|
||||
.chart-card {
|
||||
background: var(--card-background);
|
||||
border-radius: 12px;
|
||||
padding: 1.5rem;
|
||||
backdrop-filter: blur(10px);
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
||||
transition: all 0.3s ease;
|
||||
|
||||
&:hover {
|
||||
border-color: rgba(255, 255, 255, 0.2);
|
||||
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.user-stats-container {
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.header-section {
|
||||
padding: 1rem;
|
||||
|
||||
.greeting {
|
||||
i {
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 1.25rem;
|
||||
white-space: normal;
|
||||
}
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
font-size: 0.875rem;
|
||||
padding-left: 0;
|
||||
white-space: normal;
|
||||
}
|
||||
}
|
||||
|
||||
.chart-card {
|
||||
padding: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.user-stats-container {
|
||||
padding: 0.75rem;
|
||||
}
|
||||
|
||||
.header-section {
|
||||
padding: 0.75rem;
|
||||
|
||||
.greeting {
|
||||
gap: 0.5rem;
|
||||
|
||||
i {
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 1rem;
|
||||
white-space: normal;
|
||||
}
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
font-size: 0.8rem;
|
||||
padding-left: 0;
|
||||
white-space: normal;
|
||||
}
|
||||
}
|
||||
|
||||
.chart-card {
|
||||
padding: 0.75rem;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {Subject} from 'rxjs';
|
||||
import {ReadingSessionHeatmapComponent} from '../reading-session-heatmap/reading-session-heatmap.component';
|
||||
import {ReadingSessionTimelineComponent} from '../reading-session-timeline/reading-session-timeline.component';
|
||||
import {UserService} from '../../../settings/user-management/user.service';
|
||||
import {takeUntil} from 'rxjs/operators';
|
||||
|
||||
interface UserChartConfig {
|
||||
id: string;
|
||||
component: any;
|
||||
enabled: boolean;
|
||||
order: number;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-user-stats',
|
||||
standalone: true,
|
||||
imports: [CommonModule, ReadingSessionHeatmapComponent, ReadingSessionTimelineComponent],
|
||||
templateUrl: './user-stats.component.html',
|
||||
styleUrls: ['./user-stats.component.scss']
|
||||
})
|
||||
export class UserStatsComponent implements OnInit, OnDestroy {
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
|
||||
private userService = inject(UserService);
|
||||
public currentYear = new Date().getFullYear();
|
||||
public userName: string = '';
|
||||
|
||||
ngOnInit(): void {
|
||||
this.userService.userState$
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe(state => {
|
||||
if (state.user) {
|
||||
this.userName = state.user.name || state.user.username;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user