Support adding private, user-specific notes to books
This commit is contained in:
committed by
Aditya Chandel
parent
b8284b2e1c
commit
800cc4054f
@@ -0,0 +1,206 @@
|
||||
<div class="book-notes-container">
|
||||
<div class="notes-content">
|
||||
@if (loading) {
|
||||
<div class="flex flex-col items-center justify-center p-8 gap-4">
|
||||
<p-progressSpinner/>
|
||||
<span class="text-gray-400">Loading notes...</span>
|
||||
</div>
|
||||
} @else if (notes.length === 0) {
|
||||
<div class="text-center p-8 text-gray-400 empty-state">
|
||||
<div class="empty-state-icon">
|
||||
<p-button
|
||||
outlined
|
||||
rounded
|
||||
icon="pi pi-plus"
|
||||
severity="primary"
|
||||
(click)="openCreateDialog()"
|
||||
pTooltip="Add New Note"
|
||||
tooltipPosition="top"
|
||||
class="action-btn floating-btn">
|
||||
</p-button>
|
||||
</div>
|
||||
<p class="text-gray-200 empty-state-title">No notes yet for this book</p>
|
||||
<p class="text-sm text-gray-400 mt-2 empty-state-subtitle">
|
||||
Click "Add Note" to create your first note and start capturing your thoughts
|
||||
</p>
|
||||
<div class="empty-state-decoration"></div>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="notes-scroll-container">
|
||||
<div class="notes-horizontal-list">
|
||||
@for (note of notes; track note.id + '-' + note.createdAt + '-' + $index) {
|
||||
<div class="note-card border border-zinc-700">
|
||||
<div class="note-header">
|
||||
<div class="flex justify-between items-start p-3">
|
||||
<div class="flex flex-col gap-1">
|
||||
<h4 class="note-title font-medium text-lg text-gray-200 m-0">{{ note.title }}</h4>
|
||||
<div class="note-meta">
|
||||
<i class="pi pi-clock text-xs mr-1"></i>
|
||||
<span class="text-sm text-gray-400">
|
||||
@if (note.createdAt !== note.updatedAt) {
|
||||
Updated {{ formatDate(note.updatedAt) }}
|
||||
} @else {
|
||||
Created {{ formatDate(note.createdAt) }}
|
||||
}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="note-actions">
|
||||
<p-button
|
||||
icon="pi pi-pencil"
|
||||
size="small"
|
||||
severity="secondary"
|
||||
text
|
||||
(onClick)="openEditDialog(note)"
|
||||
pTooltip="Edit note"
|
||||
tooltipPosition="top"
|
||||
class="action-btn-hover">
|
||||
</p-button>
|
||||
<p-button
|
||||
icon="pi pi-trash"
|
||||
size="small"
|
||||
severity="danger"
|
||||
text
|
||||
(onClick)="deleteNote(note)"
|
||||
pTooltip="Delete note"
|
||||
tooltipPosition="top"
|
||||
class="action-btn-hover">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="note-content-area px-3 pb-3">
|
||||
<div class="text-zinc-300 note-body">{{ note.content }}</div>
|
||||
<div class="note-fade-overlay"></div>
|
||||
</div>
|
||||
<div class="note-bottom-glow"></div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (notes.length > 0) {
|
||||
<div class="action-bar">
|
||||
<p-button
|
||||
outlined
|
||||
icon="pi pi-plus"
|
||||
severity="success"
|
||||
(click)="openCreateDialog()"
|
||||
pTooltip="Add New Note"
|
||||
tooltipPosition="left">
|
||||
</p-button>
|
||||
</div>
|
||||
}
|
||||
|
||||
<p-dialog
|
||||
header="Add New Note"
|
||||
[(visible)]="showCreateDialog"
|
||||
[modal]="true"
|
||||
[style]="{width: '500px'}"
|
||||
[closable]="true"
|
||||
[dismissableMask]="true">
|
||||
|
||||
<div class="flex flex-col gap-4">
|
||||
<div class="field">
|
||||
<label for="create-title" class="block text-sm font-medium mb-2">Title</label>
|
||||
<input
|
||||
id="create-title"
|
||||
pInputText
|
||||
[(ngModel)]="newNote.title"
|
||||
placeholder="Enter note title"
|
||||
class="w-full"
|
||||
maxlength="255"/>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="create-content" class="block text-sm font-medium mb-2">Content</label>
|
||||
<textarea
|
||||
id="create-content"
|
||||
pTextarea
|
||||
[(ngModel)]="newNote.content"
|
||||
placeholder="Enter your note content..."
|
||||
[rows]="8"
|
||||
class="w-full"
|
||||
[autoResize]="true">
|
||||
</textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ng-template #footer>
|
||||
<div class="flex gap-2 justify-end">
|
||||
<p-button
|
||||
label="Cancel"
|
||||
severity="secondary"
|
||||
outlined
|
||||
(onClick)="cancelCreate()">
|
||||
</p-button>
|
||||
<p-button
|
||||
outlined
|
||||
severity="success"
|
||||
label="Save Note"
|
||||
icon="pi pi-save"
|
||||
(onClick)="createNote()">
|
||||
</p-button>
|
||||
</div>
|
||||
</ng-template>
|
||||
</p-dialog>
|
||||
|
||||
<p-dialog
|
||||
header="Edit Note"
|
||||
[(visible)]="showEditDialog"
|
||||
[modal]="true"
|
||||
[style]="{width: '500px'}"
|
||||
[closable]="true"
|
||||
[dismissableMask]="true">
|
||||
|
||||
<div class="flex flex-col gap-4">
|
||||
<div class="field">
|
||||
<label for="edit-title" class="block text-sm font-medium mb-2">Title</label>
|
||||
<input
|
||||
id="edit-title"
|
||||
pInputText
|
||||
[(ngModel)]="editNote.title"
|
||||
placeholder="Enter note title"
|
||||
class="w-full"
|
||||
maxlength="255"/>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="edit-content" class="block text-sm font-medium mb-2">Content</label>
|
||||
<textarea
|
||||
id="edit-content"
|
||||
pTextarea
|
||||
[(ngModel)]="editNote.content"
|
||||
placeholder="Enter your note content..."
|
||||
[rows]="8"
|
||||
class="w-full"
|
||||
[autoResize]="true">
|
||||
</textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ng-template #footer>
|
||||
<div class="flex gap-2 justify-end">
|
||||
<p-button
|
||||
label="Cancel"
|
||||
severity="secondary"
|
||||
outlined
|
||||
(onClick)="cancelEdit()">
|
||||
</p-button>
|
||||
<p-button
|
||||
outlined
|
||||
severity="success"
|
||||
label="Update Note"
|
||||
icon="pi pi-save"
|
||||
(onClick)="updateNote()">
|
||||
</p-button>
|
||||
</div>
|
||||
</ng-template>
|
||||
</p-dialog>
|
||||
|
||||
<p-confirmDialog key="deleteNote"></p-confirmDialog>
|
||||
</div>
|
||||
@@ -0,0 +1,254 @@
|
||||
.book-notes-container {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: relative;
|
||||
display: flex;
|
||||
min-height: 250px;
|
||||
|
||||
.notes-content {
|
||||
flex: 1;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.action-bar {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
right: 0;
|
||||
transform: translateY(-50%);
|
||||
z-index: 1000;
|
||||
}
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
position: relative;
|
||||
padding: 3rem !important;
|
||||
|
||||
.empty-state-title {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
margin-top: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.empty-state-subtitle {
|
||||
max-width: 400px;
|
||||
margin: 0 auto;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.empty-state-decoration {
|
||||
position: absolute;
|
||||
top: 20%;
|
||||
right: 15%;
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
border-radius: 50%;
|
||||
filter: blur(40px);
|
||||
animation: float 4s ease-in-out infinite;
|
||||
}
|
||||
}
|
||||
|
||||
.notes-scroll-container {
|
||||
overflow-x: auto;
|
||||
overflow-y: hidden;
|
||||
height: 100%;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
height: 10px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-track {
|
||||
background: rgba(30, 30, 30, 0.5);
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
scrollbar-width: thin;
|
||||
}
|
||||
|
||||
.notes-horizontal-list {
|
||||
display: flex;
|
||||
gap: 1.5rem;
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
.note-card {
|
||||
width: 500px;
|
||||
height: 240px;
|
||||
flex-shrink: 0;
|
||||
padding: 0;
|
||||
border-radius: 16px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
|
||||
|
||||
@media (max-width: 768px) {
|
||||
width: 340px;
|
||||
height: 220px;
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
width: 290px;
|
||||
height: 200px;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
transform: translateY(-2px);
|
||||
border-color: color-mix(in srgb, var(--primary-color), transparent 50%);
|
||||
|
||||
.note-bottom-glow {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.action-btn-hover {
|
||||
opacity: 1;
|
||||
transform: scale(1);
|
||||
}
|
||||
}
|
||||
|
||||
.note-header {
|
||||
flex-shrink: 0;
|
||||
background: linear-gradient(135deg, rgba(40, 40, 40, 0.8), rgba(30, 30, 30, 0.8));
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
||||
position: relative;
|
||||
|
||||
.note-title {
|
||||
max-width: 350px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
background: linear-gradient(135deg, #f8fafc, #e2e8f0);
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
background-clip: text;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
max-width: 200px;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
max-width: 180px;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
}
|
||||
|
||||
.note-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
opacity: 0.8;
|
||||
|
||||
i {
|
||||
color: #3b82f6;
|
||||
}
|
||||
}
|
||||
|
||||
.note-actions {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
flex-shrink: 0;
|
||||
|
||||
.action-btn-hover {
|
||||
opacity: 0.7;
|
||||
transition: all 0.3s ease;
|
||||
transform: scale(0.9);
|
||||
|
||||
::ng-deep .p-button {
|
||||
border-radius: 8px;
|
||||
|
||||
&:hover {
|
||||
transform: scale(1.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.note-content-area {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
position: relative;
|
||||
padding: 1rem !important;
|
||||
|
||||
.note-fade-overlay {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 30px;
|
||||
background: linear-gradient(transparent, rgba(20, 20, 20, 0.9));
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
|
||||
.note-bottom-glow {
|
||||
position: absolute;
|
||||
bottom: -5px;
|
||||
left: 20%;
|
||||
right: 20%;
|
||||
height: 10px;
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
transparent,
|
||||
color-mix(in srgb, var(--primary-color), transparent 60%),
|
||||
transparent
|
||||
);
|
||||
border-radius: 50%;
|
||||
opacity: 0;
|
||||
transition: opacity 0.3s ease;
|
||||
filter: blur(5px);
|
||||
}
|
||||
}
|
||||
|
||||
.note-body {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
max-height: 180px;
|
||||
overflow-y: auto;
|
||||
word-wrap: break-word;
|
||||
white-space: pre-wrap;
|
||||
padding-right: 8px;
|
||||
box-sizing: border-box;
|
||||
line-height: 1.6;
|
||||
color: #e2e8f0;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
max-height: 140px;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
max-height: 120px;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes float {
|
||||
0%, 100% {
|
||||
transform: translateY(0px);
|
||||
}
|
||||
50% {
|
||||
transform: translateY(-10px);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
0%, 100% {
|
||||
transform: scale(1);
|
||||
opacity: 1;
|
||||
}
|
||||
50% {
|
||||
transform: scale(1.05);
|
||||
opacity: 0.8;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
import {Component, DestroyRef, inject, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Dialog} from 'primeng/dialog';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {Textarea} from 'primeng/textarea';
|
||||
import {ConfirmDialog} from 'primeng/confirmdialog';
|
||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {ConfirmationService, MessageService} from 'primeng/api';
|
||||
import {BookNote, BookNoteService, CreateBookNoteRequest} from '../../../core/service/book-note.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-notes-component',
|
||||
standalone: true,
|
||||
imports: [
|
||||
CommonModule,
|
||||
FormsModule,
|
||||
Button,
|
||||
Dialog,
|
||||
InputText,
|
||||
Textarea,
|
||||
ConfirmDialog,
|
||||
ProgressSpinner,
|
||||
Tooltip
|
||||
],
|
||||
templateUrl: './book-notes-component.html',
|
||||
styleUrl: './book-notes-component.scss'
|
||||
})
|
||||
export class BookNotesComponent implements OnInit, OnChanges {
|
||||
@Input() bookId!: number;
|
||||
|
||||
private bookNoteService = inject(BookNoteService);
|
||||
private confirmationService = inject(ConfirmationService);
|
||||
private messageService = inject(MessageService);
|
||||
private destroyRef = inject(DestroyRef);
|
||||
|
||||
notes: BookNote[] = [];
|
||||
loading = false;
|
||||
showCreateDialog = false;
|
||||
showEditDialog = false;
|
||||
selectedNote: BookNote | null = null;
|
||||
|
||||
newNote: CreateBookNoteRequest = {
|
||||
bookId: 0,
|
||||
title: '',
|
||||
content: ''
|
||||
};
|
||||
|
||||
editNote: CreateBookNoteRequest = {
|
||||
bookId: 0,
|
||||
title: '',
|
||||
content: ''
|
||||
};
|
||||
|
||||
ngOnInit(): void {
|
||||
if (this.bookId) {
|
||||
this.loadNotes();
|
||||
}
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges): void {
|
||||
if (changes['bookId'] && changes['bookId'].currentValue) {
|
||||
this.loadNotes();
|
||||
}
|
||||
}
|
||||
|
||||
loadNotes(): void {
|
||||
if (!this.bookId) return;
|
||||
|
||||
this.loading = true;
|
||||
this.bookNoteService.getNotesForBook(this.bookId)
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe({
|
||||
next: (notes) => {
|
||||
this.notes = notes.sort((a, b) =>
|
||||
new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime()
|
||||
);
|
||||
this.loading = false;
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Failed to load notes:', error);
|
||||
this.loading = false;
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: 'Failed to load notes for this book.'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
openCreateDialog(): void {
|
||||
this.newNote = {
|
||||
bookId: this.bookId,
|
||||
title: '',
|
||||
content: ''
|
||||
};
|
||||
this.showCreateDialog = true;
|
||||
}
|
||||
|
||||
openEditDialog(note: BookNote): void {
|
||||
this.selectedNote = note;
|
||||
this.editNote = {
|
||||
id: note.id,
|
||||
bookId: note.bookId,
|
||||
title: note.title,
|
||||
content: note.content
|
||||
};
|
||||
this.showEditDialog = true;
|
||||
}
|
||||
|
||||
createNote(): void {
|
||||
if (!this.newNote.title.trim() || !this.newNote.content.trim()) {
|
||||
this.messageService.add({
|
||||
severity: 'warn',
|
||||
summary: 'Validation Error',
|
||||
detail: 'Both title and content are required.'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.bookNoteService.createOrUpdateNote(this.newNote)
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe({
|
||||
next: (note) => {
|
||||
this.notes.unshift(note);
|
||||
this.showCreateDialog = false;
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Success',
|
||||
detail: 'Note created successfully.'
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Failed to create note:', error);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: 'Failed to create note.'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
updateNote(): void {
|
||||
if (!this.editNote.title?.trim() || !this.editNote.content?.trim()) {
|
||||
this.messageService.add({
|
||||
severity: 'warn',
|
||||
summary: 'Validation Error',
|
||||
detail: 'Both title and content are required.'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.bookNoteService.createOrUpdateNote(this.editNote)
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe({
|
||||
next: (updatedNote) => {
|
||||
const index = this.notes.findIndex(n => n.id === this.selectedNote?.id);
|
||||
if (index !== -1) {
|
||||
this.notes[index] = updatedNote;
|
||||
this.notes.sort((a, b) =>
|
||||
new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime()
|
||||
);
|
||||
}
|
||||
this.showEditDialog = false;
|
||||
this.selectedNote = null;
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Success',
|
||||
detail: 'Note updated successfully.'
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Failed to update note:', error);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: 'Failed to update note.'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
deleteNote(note: BookNote): void {
|
||||
this.confirmationService.confirm({
|
||||
key: 'deleteNote',
|
||||
message: `Are you sure you want to delete the note "${note.title}"?`,
|
||||
header: 'Confirm Deletion',
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptIcon: 'pi pi-trash',
|
||||
rejectIcon: 'pi pi-times',
|
||||
acceptButtonStyleClass: 'p-button-danger, p-button-outlined p-button-danger',
|
||||
rejectButtonStyleClass: 'p-button-danger, p-button-outlined p-button-info',
|
||||
accept: () => {
|
||||
this.performDelete(note.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private performDelete(noteId: number): void {
|
||||
this.bookNoteService.deleteNote(noteId).subscribe({
|
||||
next: () => {
|
||||
this.notes = this.notes.filter(n => n.id !== noteId);
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Success',
|
||||
detail: 'Note deleted successfully.'
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Failed to delete note:', error);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: 'Failed to delete note.'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
cancelCreate(): void {
|
||||
this.showCreateDialog = false;
|
||||
this.newNote = {
|
||||
bookId: this.bookId,
|
||||
title: '',
|
||||
content: ''
|
||||
};
|
||||
}
|
||||
|
||||
cancelEdit(): void {
|
||||
this.showEditDialog = false;
|
||||
this.selectedNote = null;
|
||||
this.editNote = {
|
||||
bookId: this.bookId,
|
||||
title: '',
|
||||
content: ''
|
||||
};
|
||||
}
|
||||
|
||||
formatDate(dateString: string): string {
|
||||
return new Date(dateString).toLocaleDateString('en-US', {
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
<div class="book-reviews-container">
|
||||
<div class="reviews-content">
|
||||
@if (loading) {
|
||||
<div class="flex flex-col items-center justify-center p-8 gap-4">
|
||||
<p-progressSpinner/>
|
||||
<span class="text-gray-400">Getting latest reviews...</span>
|
||||
</div>
|
||||
} @else if (reviews?.length === 0) {
|
||||
<div class="text-center p-8 text-gray-400">
|
||||
<i class="pi pi-comments text-4xl mb-4 block"></i>
|
||||
<p class="text-gray-200">No reviews available for this book</p>
|
||||
@if (!reviewDownloadEnabled) {
|
||||
<p class="text-sm text-amber-400 mt-2">
|
||||
Book review downloads are currently disabled. Enable this in Metadata Settings to fetch reviews.
|
||||
</p>
|
||||
}
|
||||
</div>
|
||||
} @else {
|
||||
<div class="reviews-scroll-container">
|
||||
<div class="reviews-horizontal-list">
|
||||
@for (review of reviews; track review.id || $index) {
|
||||
<div [class]="'review-card border border-zinc-700' + (!review.title ? ' no-title' : '') + (review.spoiler && !isSpoilerRevealed(review.id!) ? ' has-spoiler' : '')">
|
||||
@if (review.spoiler && !isSpoilerRevealed(review.id!)) {
|
||||
<p-button
|
||||
label="Show Spoiler"
|
||||
icon="pi pi-eye"
|
||||
severity="warn"
|
||||
size="small"
|
||||
class="spoiler-overlay-button"
|
||||
(onClick)="revealSpoiler(review.id!)"/>
|
||||
}
|
||||
|
||||
<div class="review-header">
|
||||
<div class="flex justify-between items-start p-3">
|
||||
<div class="flex flex-col gap-1">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="font-medium text-sm reviewer-name">{{ review.reviewerName || 'Anonymous' }}</span>
|
||||
@if (review.metadataProvider) {
|
||||
<p-tag
|
||||
[rounded]="true"
|
||||
[value]="review.metadataProvider"
|
||||
[severity]="getProviderSeverity(review.metadataProvider)"/>
|
||||
}
|
||||
@if (review.country) {
|
||||
<p-tag [rounded]="true" [value]="review.country" severity="info"/>
|
||||
}
|
||||
@if (review.spoiler) {
|
||||
<p-tag [rounded]="true" value="Spoiler" severity="warn" icon="pi pi-exclamation-triangle"/>
|
||||
}
|
||||
</div>
|
||||
<div class="review-meta">
|
||||
<i class="pi pi-clock text-xs mr-1"></i>
|
||||
@if (review.date) {
|
||||
<span class="text-sm text-gray-400">{{ formatDate(review.date) }}</span>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-2">
|
||||
@if (review.rating) {
|
||||
<div class="flex items-center gap-1">
|
||||
<p-rating
|
||||
[ngModel]="review.rating"
|
||||
[readonly]="true"
|
||||
[stars]="5"/>
|
||||
<span class="text-sm font-medium">{{ review.rating }}/5</span>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (hasPermission) {
|
||||
@if (reviewsLocked) {
|
||||
<div class="flex items-center justify-center w-8 h-8">
|
||||
<i class="pi pi-lock text-amber-500 text-sm"
|
||||
pTooltip="Reviews are locked"
|
||||
tooltipPosition="top"></i>
|
||||
</div>
|
||||
} @else {
|
||||
<p-button
|
||||
icon="pi pi-trash"
|
||||
size="small"
|
||||
severity="danger"
|
||||
text
|
||||
(onClick)="deleteReview(review)"
|
||||
pTooltip="Delete Review"
|
||||
tooltipPosition="top"
|
||||
class="action-btn-hover"/>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (review.title && (!review.spoiler || isSpoilerRevealed(review.id!))) {
|
||||
<div class="review-title-section">
|
||||
<h4 class="font-medium text-xl text-gray-200 leading-tight m-0 review-title"
|
||||
[pTooltip]="review.title"
|
||||
tooltipPosition="top">{{ review.title }}
|
||||
</h4>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="review-content-area">
|
||||
@if (review.spoiler && !isSpoilerRevealed(review.id!)) {
|
||||
<div class="spoiler-blur-content">
|
||||
@if (review.title) {
|
||||
<h4 class="font-medium text-gray-200 leading-tight m-0 review-title blur-sm mb-2">{{ review.title }}</h4>
|
||||
}
|
||||
@if (review.body) {
|
||||
<div class="text-zinc-300 review-body blur-sm">{{ review.body }}</div>
|
||||
} @else {
|
||||
<div class="text-zinc-400 italic text-sm blur-sm">No review content available</div>
|
||||
}
|
||||
</div>
|
||||
} @else {
|
||||
@if (review.body) {
|
||||
<div class="text-zinc-300 review-body">{{ review.body }}</div>
|
||||
} @else {
|
||||
<div class="text-zinc-400 italic text-sm">No review content available</div>
|
||||
}
|
||||
}
|
||||
<div class="review-fade-overlay"></div>
|
||||
</div>
|
||||
<div class="review-bottom-glow"></div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="action-bar">
|
||||
<div class="action-buttons">
|
||||
|
||||
@if (hasPermission) {
|
||||
<p-button
|
||||
outlined
|
||||
[icon]="reviewsLocked ? 'pi pi-lock' : 'pi pi-lock-open'"
|
||||
size="small"
|
||||
[severity]="reviewsLocked ? 'danger' : 'success'"
|
||||
[disabled]="!reviewDownloadEnabled || loading"
|
||||
(click)="toggleReviewsLock()"
|
||||
[pTooltip]="loading ? 'Please wait while reviews are being fetched' : (!reviewDownloadEnabled ? 'Enable review downloads in settings to use this feature' : (reviewsLocked ? 'Unlock Reviews' : 'Lock Reviews'))"
|
||||
tooltipPosition="left"
|
||||
class="action-btn"/>
|
||||
|
||||
<p-button
|
||||
outlined
|
||||
icon="pi pi-refresh"
|
||||
size="small"
|
||||
severity="primary"
|
||||
[loading]="loading"
|
||||
[disabled]="reviewsLocked || !reviewDownloadEnabled || loading"
|
||||
(click)="fetchNewReviews()"
|
||||
[pTooltip]="loading ? 'Please wait while reviews are being fetched' : (!reviewDownloadEnabled ? 'Enable review downloads in settings to use this feature' : (reviewsLocked ? 'Reviews are locked' : 'Fetch New Reviews'))"
|
||||
tooltipPosition="left"
|
||||
class="action-btn"/>
|
||||
}
|
||||
|
||||
@if (hasPermission && reviews && reviews.length > 0) {
|
||||
<p-button
|
||||
outlined
|
||||
icon="pi pi-trash"
|
||||
size="small"
|
||||
severity="danger"
|
||||
[disabled]="reviewsLocked || loading"
|
||||
(click)="deleteAllReviews()"
|
||||
[pTooltip]="loading ? 'Please wait while reviews are being fetched' : (reviewsLocked ? 'Reviews are locked' : 'Delete All Reviews')"
|
||||
tooltipPosition="left"
|
||||
class="action-btn"/>
|
||||
}
|
||||
|
||||
@if (reviews && reviews.length > 0) {
|
||||
<p-button
|
||||
outlined
|
||||
[icon]="allSpoilersRevealed ? 'pi pi-eye-slash' : 'pi pi-eye'"
|
||||
size="small"
|
||||
[severity]="allSpoilersRevealed ? 'warn' : 'info'"
|
||||
[disabled]="loading"
|
||||
(click)="toggleSpoilerVisibility()"
|
||||
[pTooltip]="loading ? 'Please wait while reviews are being fetched' : (allSpoilersRevealed ? 'Hide All Spoilers' : 'Reveal All Spoilers')"
|
||||
tooltipPosition="left"
|
||||
class="action-btn"/>
|
||||
|
||||
<p-button
|
||||
outlined
|
||||
icon="pi pi-sort-amount-down"
|
||||
size="small"
|
||||
severity="contrast"
|
||||
[disabled]="loading"
|
||||
(click)="toggleSortOrder()"
|
||||
[pTooltip]="loading ? 'Please wait while reviews are being fetched' : (sortAscending ? 'Sort by Newest First' : 'Sort by Oldest First')"
|
||||
tooltipPosition="left"
|
||||
class="action-btn"/>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,247 @@
|
||||
.book-reviews-container {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: relative;
|
||||
display: flex;
|
||||
min-height: 250px;
|
||||
|
||||
.reviews-content {
|
||||
flex: 1;
|
||||
padding-right: 60px;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.action-bar {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
right: 0;
|
||||
transform: translateY(-50%);
|
||||
width: 50px;
|
||||
z-index: 1000;
|
||||
pointer-events: none;
|
||||
|
||||
.action-buttons {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
padding: 16px 8px;
|
||||
background: rgba(0, 0, 0, 0.1);
|
||||
border-radius: 8px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||
backdrop-filter: blur(8px);
|
||||
pointer-events: auto;
|
||||
position: relative;
|
||||
top: -50%;
|
||||
|
||||
.action-btn {
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
|
||||
::ng-deep {
|
||||
.p-button {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
padding: 0;
|
||||
|
||||
.p-button-icon {
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.reviews-scroll-container {
|
||||
overflow-x: auto;
|
||||
overflow-y: hidden;
|
||||
padding-bottom: 8px;
|
||||
height: 100%;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
height: 8px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-track {
|
||||
background: var(--surface-ground);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background: var(--surface-border);
|
||||
border-radius: 4px;
|
||||
|
||||
&:hover {
|
||||
background: var(--primary-color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.reviews-horizontal-list {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
.review-card {
|
||||
width: 500px;
|
||||
height: 250px;
|
||||
flex-shrink: 0;
|
||||
padding: 0;
|
||||
border-radius: 16px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
|
||||
@media (max-width: 768px) {
|
||||
width: 340px;
|
||||
height: 220px;
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
width: 290px;
|
||||
height: 200px;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
transform: translateY(-2px);
|
||||
border-color: color-mix(in srgb, var(--primary-color), transparent 50%);
|
||||
|
||||
.action-btn-hover {
|
||||
opacity: 1;
|
||||
transform: scale(1);
|
||||
}
|
||||
}
|
||||
|
||||
&.no-title {
|
||||
.review-content-area {
|
||||
height: calc(100% - 80px);
|
||||
}
|
||||
}
|
||||
|
||||
&.has-spoiler {
|
||||
.review-content-area {
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
&::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.3);
|
||||
z-index: 50;
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
|
||||
.review-header {
|
||||
flex-shrink: 0;
|
||||
background: linear-gradient(135deg, rgba(40, 40, 40, 0.8), rgba(30, 30, 30, 0.8));
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
||||
position: relative;
|
||||
|
||||
.reviewer-name {
|
||||
max-width: 120px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
background: linear-gradient(135deg, #f8fafc, #e2e8f0);
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
background-clip: text;
|
||||
}
|
||||
|
||||
.review-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
opacity: 0.8;
|
||||
|
||||
i {
|
||||
color: #3b82f6;
|
||||
}
|
||||
}
|
||||
|
||||
.action-btn-hover {
|
||||
opacity: 0.7;
|
||||
transition: all 0.3s ease;
|
||||
transform: scale(0.9);
|
||||
|
||||
::ng-deep .p-button {
|
||||
border-radius: 8px;
|
||||
|
||||
&:hover {
|
||||
transform: scale(1.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.review-title-section {
|
||||
flex-shrink: 0;
|
||||
border-bottom: 1px solid var(--surface-border);
|
||||
padding: 8px 16px 4px 16px;
|
||||
}
|
||||
|
||||
.review-content-area {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
position: relative;
|
||||
padding: 8px 16px 16px 16px;
|
||||
|
||||
.review-fade-overlay {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 30px;
|
||||
background: linear-gradient(transparent, rgba(20, 20, 20, 0.9));
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.review-body {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
max-height: 210px;
|
||||
overflow-y: auto;
|
||||
word-wrap: break-word;
|
||||
white-space: pre-wrap;
|
||||
box-sizing: border-box;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 4px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-track {
|
||||
background: var(--surface-ground);
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background: var(--surface-border);
|
||||
border-radius: 2px;
|
||||
|
||||
&:hover {
|
||||
background: var(--primary-color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.review-title {
|
||||
max-width: 450px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
cursor: help;
|
||||
}
|
||||
@@ -0,0 +1,332 @@
|
||||
import {Component, DestroyRef, inject, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {BookReview, BookReviewService} from '../../../book-review-service';
|
||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
import {Rating} from 'primeng/rating';
|
||||
import {Tag} from 'primeng/tag';
|
||||
import {Button} from 'primeng/button';
|
||||
import {ConfirmationService, MessageService} from 'primeng/api';
|
||||
import {UserService} from '../../../settings/user-management/user.service';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {BookService} from '../../service/book.service';
|
||||
import {AppSettingsService} from '../../../core/service/app-settings.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-reviews',
|
||||
standalone: true,
|
||||
imports: [CommonModule, ProgressSpinner, Rating, Tag, Button, FormsModule, Tooltip],
|
||||
templateUrl: './book-reviews.component.html',
|
||||
styleUrl: './book-reviews.component.scss'
|
||||
})
|
||||
export class BookReviewsComponent implements OnInit, OnChanges {
|
||||
@Input() bookId!: number;
|
||||
@Input() reviews: BookReview[] | undefined = [];
|
||||
@Input() active: boolean = false;
|
||||
|
||||
private reviewService = inject(BookReviewService);
|
||||
private bookService = inject(BookService);
|
||||
private confirmationService = inject(ConfirmationService);
|
||||
private messageService = inject(MessageService);
|
||||
private userService = inject(UserService);
|
||||
private appSettingsService = inject(AppSettingsService);
|
||||
private destroyRef = inject(DestroyRef);
|
||||
|
||||
loading = false;
|
||||
hasPermission = false;
|
||||
revealedSpoilers = new Set<number>();
|
||||
sortAscending = false;
|
||||
reviewsLocked = false;
|
||||
allSpoilersRevealed = false;
|
||||
reviewDownloadEnabled = true;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.checkUserPermissions();
|
||||
this.subscribeToBookState();
|
||||
this.subscribeToAppSettings();
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges): void {
|
||||
if (changes['bookId'] && changes['bookId'].currentValue) {
|
||||
this.loadReviews();
|
||||
}
|
||||
}
|
||||
|
||||
private subscribeToBookState(): void {
|
||||
this.bookService.bookState$
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe(state => {
|
||||
if (state.books && this.bookId) {
|
||||
const book = state.books.find(b => b.id === this.bookId);
|
||||
this.reviewsLocked = book?.metadata?.reviewsLocked ?? false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private loadReviews(): void {
|
||||
if (this.loading || !this.bookId) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.loading = true;
|
||||
this.reviewService.getByBookId(this.bookId)
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe({
|
||||
next: (reviews) => {
|
||||
this.reviews = this.sortReviewsByDate(reviews || []);
|
||||
this.loading = false;
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Failed to load reviews for bookId', this.bookId, ':', error);
|
||||
this.reviews = [];
|
||||
this.loading = false;
|
||||
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Failed to Load Reviews',
|
||||
detail: 'Could not load reviews for this book.',
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fetchNewReviews(): void {
|
||||
if (!this.bookId || this.loading || this.reviewsLocked) return;
|
||||
|
||||
this.loading = true;
|
||||
this.revealedSpoilers.clear();
|
||||
|
||||
this.reviewService.refreshReviews(this.bookId)
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe({
|
||||
next: (reviews) => {
|
||||
this.reviews = this.sortReviewsByDate(reviews || []);
|
||||
this.loading = false;
|
||||
this.updateSpoilerState();
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Reviews Updated',
|
||||
detail: 'Latest reviews have been fetched successfully.',
|
||||
life: 3000
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Failed to fetch new reviews:', error);
|
||||
this.loading = false;
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Fetch Failed',
|
||||
detail: 'Could not fetch new reviews for this book.',
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
deleteAllReviews(): void {
|
||||
if (!this.reviews || this.reviews.length === 0 || this.reviewsLocked) return;
|
||||
|
||||
this.confirmationService.confirm({
|
||||
message: `Are you sure you want to delete all ${this.reviews.length} reviews for this book? This action cannot be undone.`,
|
||||
header: 'Confirm Delete All',
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptIcon: 'pi pi-trash',
|
||||
rejectIcon: 'pi pi-times',
|
||||
acceptButtonStyleClass: 'p-button-danger',
|
||||
accept: () => {
|
||||
if (!this.bookId) return;
|
||||
|
||||
this.reviewService.deleteAllByBookId(this.bookId).subscribe({
|
||||
next: () => {
|
||||
this.reviews = [];
|
||||
this.revealedSpoilers.clear();
|
||||
this.allSpoilersRevealed = false;
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'All Reviews Deleted',
|
||||
detail: 'All reviews have been successfully deleted.',
|
||||
life: 3000
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Failed to delete all reviews:', error);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Delete Failed',
|
||||
detail: 'Could not delete all reviews.',
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
toggleSpoilerVisibility(): void {
|
||||
if (this.allSpoilersRevealed) {
|
||||
this.hideAllSpoilers();
|
||||
} else {
|
||||
this.revealAllSpoilers();
|
||||
}
|
||||
}
|
||||
|
||||
hideAllSpoilers(): void {
|
||||
this.revealedSpoilers.clear();
|
||||
this.allSpoilersRevealed = false;
|
||||
}
|
||||
|
||||
revealAllSpoilers(): void {
|
||||
if (this.reviews) {
|
||||
this.reviews.forEach(review => {
|
||||
if (review.spoiler && review.id) {
|
||||
this.revealedSpoilers.add(review.id);
|
||||
}
|
||||
});
|
||||
this.allSpoilersRevealed = true;
|
||||
}
|
||||
}
|
||||
|
||||
toggleReviewsLock(): void {
|
||||
if (!this.bookId) return;
|
||||
|
||||
const newLockState = !this.reviewsLocked;
|
||||
const fieldActions: Record<string, 'LOCK' | 'UNLOCK'> = {
|
||||
'reviewsLocked': newLockState ? 'LOCK' : 'UNLOCK'
|
||||
};
|
||||
|
||||
this.bookService.toggleFieldLocks([this.bookId], fieldActions)
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe({
|
||||
next: () => {
|
||||
const action = newLockState ? 'locked' : 'unlocked';
|
||||
this.messageService.add({
|
||||
severity: 'info',
|
||||
summary: `Reviews ${action.charAt(0).toUpperCase() + action.slice(1)}`,
|
||||
detail: newLockState
|
||||
? 'Reviews are now protected from modifications and refreshes.'
|
||||
: 'Reviews can now be modified and refreshed.',
|
||||
life: 3000
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Failed to toggle lock status:', error);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Lock Toggle Failed',
|
||||
detail: 'Could not change the lock status for reviews.',
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
toggleSortOrder(): void {
|
||||
this.sortAscending = !this.sortAscending;
|
||||
if (this.reviews) {
|
||||
this.reviews = this.sortReviewsByDate([...this.reviews]);
|
||||
}
|
||||
}
|
||||
|
||||
private sortReviewsByDate(reviews: BookReview[]): BookReview[] {
|
||||
return reviews.sort((a, b) => {
|
||||
if (!a.date && !b.date) return 0;
|
||||
if (!a.date) return this.sortAscending ? -1 : 1;
|
||||
if (!b.date) return this.sortAscending ? 1 : -1;
|
||||
|
||||
const dateA = new Date(a.date).getTime();
|
||||
const dateB = new Date(b.date).getTime();
|
||||
|
||||
return this.sortAscending ? dateA - dateB : dateB - dateA;
|
||||
});
|
||||
}
|
||||
|
||||
private checkUserPermissions(): void {
|
||||
this.userService.userState$
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe(userState => {
|
||||
this.hasPermission = userState?.user?.permissions?.admin ||
|
||||
userState?.user?.permissions?.canEditMetadata || false;
|
||||
});
|
||||
}
|
||||
|
||||
deleteReview(review: BookReview): void {
|
||||
if (!review.id || this.reviewsLocked) return;
|
||||
|
||||
this.confirmationService.confirm({
|
||||
message: `Are you sure you want to delete this review by ${review.reviewerName || 'Anonymous'}?`,
|
||||
header: 'Confirm Deletion',
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptIcon: 'pi pi-trash',
|
||||
rejectIcon: 'pi pi-times',
|
||||
acceptButtonStyleClass: 'p-button-danger',
|
||||
accept: () => {
|
||||
this.reviewService.delete(review.id!).subscribe({
|
||||
next: () => {
|
||||
this.reviews = this.reviews?.filter(r => r.id !== review.id);
|
||||
this.updateSpoilerState();
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Review Deleted',
|
||||
detail: 'The review has been successfully deleted.',
|
||||
life: 2000
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Failed to delete review:', error);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Delete Failed',
|
||||
detail: 'Could not delete the review.',
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
revealSpoiler(reviewId: number): void {
|
||||
if (reviewId) {
|
||||
this.revealedSpoilers.add(reviewId);
|
||||
this.updateSpoilerState();
|
||||
}
|
||||
}
|
||||
|
||||
private updateSpoilerState(): void {
|
||||
const spoilerReviews = this.reviews?.filter(r => r.spoiler) || [];
|
||||
const revealedSpoilerReviews = spoilerReviews.filter(r => r.id && this.revealedSpoilers.has(r.id));
|
||||
this.allSpoilersRevealed = spoilerReviews.length > 0 && spoilerReviews.length === revealedSpoilerReviews.length;
|
||||
}
|
||||
|
||||
formatDate(dateString: string): string {
|
||||
const date = new Date(dateString);
|
||||
return date.toLocaleDateString('en-US', {
|
||||
year: 'numeric',
|
||||
month: 'long',
|
||||
day: 'numeric'
|
||||
});
|
||||
}
|
||||
|
||||
isSpoilerRevealed(reviewId: number): boolean {
|
||||
return this.revealedSpoilers.has(reviewId);
|
||||
}
|
||||
|
||||
private subscribeToAppSettings(): void {
|
||||
this.appSettingsService.appSettings$
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe(settings => {
|
||||
this.reviewDownloadEnabled = settings?.metadataPublicReviewsSettings?.downloadEnabled ?? true;
|
||||
});
|
||||
}
|
||||
|
||||
getProviderSeverity(provider: string): 'success' | 'warn' {
|
||||
switch (provider?.toLowerCase()) {
|
||||
case 'amazon':
|
||||
return 'warn';
|
||||
default:
|
||||
return 'success';
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user