generated from nhcarrigan/template
feat: add suggestion feature
This commit is contained in:
@@ -0,0 +1,377 @@
|
||||
/**
|
||||
* @copyright 2026 NHCarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
|
||||
import { Component, OnInit, inject, signal } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { SuggestionService } from '../../services/suggestion.service';
|
||||
import { AuthService } from '../../services/auth.service';
|
||||
import { Suggestion, SuggestionStatus, SuggestionEntity } from '@library/shared-types';
|
||||
|
||||
@Component({
|
||||
selector: 'app-my-suggestions',
|
||||
standalone: true,
|
||||
imports: [CommonModule],
|
||||
template: `
|
||||
<div class="container">
|
||||
<div class="header-section">
|
||||
<h2>My Suggestions</h2>
|
||||
<p class="subtitle">Track the status of items you've suggested to Naomi</p>
|
||||
</div>
|
||||
|
||||
@if (!authService.isAuthenticated()) {
|
||||
<div class="not-authenticated">
|
||||
<p>Please log in to view your suggestions.</p>
|
||||
</div>
|
||||
} @else if (loading()) {
|
||||
<div class="loading">Loading your suggestions...</div>
|
||||
} @else if (suggestions().length === 0) {
|
||||
<div class="empty-state">
|
||||
<p>You haven't made any suggestions yet!</p>
|
||||
<p class="hint">Visit any collection page and click "Suggest a..." to recommend something to Naomi.</p>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="filters">
|
||||
<button
|
||||
(click)="setFilter('all')"
|
||||
[class.active]="statusFilter() === 'all'"
|
||||
class="filter-btn"
|
||||
>
|
||||
All ({{ suggestions().length }})
|
||||
</button>
|
||||
<button
|
||||
(click)="setFilter(SuggestionStatus.UNREVIEWED)"
|
||||
[class.active]="statusFilter() === SuggestionStatus.UNREVIEWED"
|
||||
class="filter-btn pending"
|
||||
>
|
||||
Pending ({{ unreviewedCount() }})
|
||||
</button>
|
||||
<button
|
||||
(click)="setFilter(SuggestionStatus.ACCEPTED)"
|
||||
[class.active]="statusFilter() === SuggestionStatus.ACCEPTED"
|
||||
class="filter-btn accepted"
|
||||
>
|
||||
Accepted ({{ acceptedCount() }})
|
||||
</button>
|
||||
<button
|
||||
(click)="setFilter(SuggestionStatus.DECLINED)"
|
||||
[class.active]="statusFilter() === SuggestionStatus.DECLINED"
|
||||
class="filter-btn declined"
|
||||
>
|
||||
Declined ({{ declinedCount() }})
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="suggestions-list">
|
||||
@for (suggestion of filteredSuggestions(); track suggestion.id) {
|
||||
<div class="suggestion-card" [class]="'status-' + suggestion.status.toLowerCase()">
|
||||
<div class="suggestion-header">
|
||||
<span class="entity-badge" [class]="'entity-' + suggestion.entityType.toLowerCase()">
|
||||
{{ getEntityIcon(suggestion.entityType) }} {{ suggestion.entityType }}
|
||||
</span>
|
||||
<span class="status-badge" [class]="'status-' + suggestion.status.toLowerCase()">
|
||||
{{ getStatusLabel(suggestion.status) }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<h3 class="suggestion-title">{{ suggestion.title }}</h3>
|
||||
|
||||
<div class="suggestion-details">
|
||||
@if (suggestion.gameData) {
|
||||
@if (suggestion.gameData.platform) {
|
||||
<p><strong>Platform:</strong> {{ suggestion.gameData.platform }}</p>
|
||||
}
|
||||
}
|
||||
@if (suggestion.bookData) {
|
||||
@if (suggestion.bookData.author) {
|
||||
<p><strong>Author:</strong> {{ suggestion.bookData.author }}</p>
|
||||
}
|
||||
}
|
||||
@if (suggestion.musicData) {
|
||||
@if (suggestion.musicData.artist) {
|
||||
<p><strong>Artist:</strong> {{ suggestion.musicData.artist }}</p>
|
||||
}
|
||||
}
|
||||
@if (suggestion.artData) {
|
||||
@if (suggestion.artData.artist) {
|
||||
<p><strong>Artist:</strong> {{ suggestion.artData.artist }}</p>
|
||||
}
|
||||
}
|
||||
@if (suggestion.showData) {
|
||||
@if (suggestion.showData.type) {
|
||||
<p><strong>Type:</strong> {{ suggestion.showData.type }}</p>
|
||||
}
|
||||
}
|
||||
@if (suggestion.mangaData) {
|
||||
@if (suggestion.mangaData.author) {
|
||||
<p><strong>Author:</strong> {{ suggestion.mangaData.author }}</p>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (suggestion.status === SuggestionStatus.DECLINED && suggestion.declineReason) {
|
||||
<div class="decline-reason">
|
||||
<strong>Reason:</strong> {{ suggestion.declineReason }}
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="suggestion-footer">
|
||||
<span class="date">Suggested on {{ formatDate(suggestion.createdAt) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
`,
|
||||
styles: [`
|
||||
.container {
|
||||
max-width: 900px;
|
||||
margin: 0 auto;
|
||||
padding: 2rem 1rem;
|
||||
}
|
||||
|
||||
.header-section {
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.header-section h2 {
|
||||
margin: 0 0 0.5rem 0;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
color: #666;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.not-authenticated,
|
||||
.loading,
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 3rem;
|
||||
color: #666;
|
||||
background: #f8f9fa;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.hint {
|
||||
font-size: 0.9rem;
|
||||
color: #888;
|
||||
}
|
||||
|
||||
.filters {
|
||||
display: flex;
|
||||
gap: 0.75rem;
|
||||
margin-bottom: 2rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.filter-btn {
|
||||
padding: 0.5rem 1rem;
|
||||
background: #e5e7eb;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.filter-btn:hover {
|
||||
background: #d1d5db;
|
||||
}
|
||||
|
||||
.filter-btn.active {
|
||||
color: white;
|
||||
}
|
||||
|
||||
.filter-btn.active,
|
||||
.filter-btn.active.pending {
|
||||
background: #f59e0b;
|
||||
}
|
||||
|
||||
.filter-btn.active.accepted {
|
||||
background: #10b981;
|
||||
}
|
||||
|
||||
.filter-btn.active.declined {
|
||||
background: #ef4444;
|
||||
}
|
||||
|
||||
.suggestions-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.suggestion-card {
|
||||
background: white;
|
||||
border: 1px solid #e5e7eb;
|
||||
border-radius: 8px;
|
||||
padding: 1.25rem;
|
||||
transition: box-shadow 0.3s;
|
||||
}
|
||||
|
||||
.suggestion-card:hover {
|
||||
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
|
||||
}
|
||||
|
||||
.suggestion-card.status-accepted {
|
||||
border-left: 4px solid #10b981;
|
||||
}
|
||||
|
||||
.suggestion-card.status-declined {
|
||||
border-left: 4px solid #ef4444;
|
||||
}
|
||||
|
||||
.suggestion-card.status-unreviewed {
|
||||
border-left: 4px solid #f59e0b;
|
||||
}
|
||||
|
||||
.suggestion-header {
|
||||
display: flex;
|
||||
gap: 0.75rem;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.entity-badge,
|
||||
.status-badge {
|
||||
padding: 0.25rem 0.5rem;
|
||||
border-radius: 4px;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.entity-badge {
|
||||
background: #e5e7eb;
|
||||
color: #374151;
|
||||
}
|
||||
|
||||
.entity-badge.entity-game { background: #fff1f1; color: #dc2626; }
|
||||
.entity-badge.entity-book { background: #fdf4ed; color: #8b6f47; }
|
||||
.entity-badge.entity-music { background: #eff6ff; color: #2563eb; }
|
||||
.entity-badge.entity-manga { background: #ecfdf5; color: #059669; }
|
||||
.entity-badge.entity-show { background: #fdf2f8; color: #db2777; }
|
||||
.entity-badge.entity-art { background: #fefce8; color: #ca8a04; }
|
||||
|
||||
.status-badge.status-unreviewed {
|
||||
background: #fef3c7;
|
||||
color: #92400e;
|
||||
}
|
||||
|
||||
.status-badge.status-accepted {
|
||||
background: #d1fae5;
|
||||
color: #065f46;
|
||||
}
|
||||
|
||||
.status-badge.status-declined {
|
||||
background: #fee2e2;
|
||||
color: #991b1b;
|
||||
}
|
||||
|
||||
.suggestion-title {
|
||||
margin: 0 0 0.75rem 0;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
.suggestion-details {
|
||||
font-size: 0.9rem;
|
||||
color: #4b5563;
|
||||
}
|
||||
|
||||
.suggestion-details p {
|
||||
margin: 0.25rem 0;
|
||||
}
|
||||
|
||||
.decline-reason {
|
||||
background: #fee2e2;
|
||||
border: 1px solid #fecaca;
|
||||
border-radius: 4px;
|
||||
padding: 0.75rem;
|
||||
margin-top: 0.75rem;
|
||||
font-size: 0.9rem;
|
||||
color: #991b1b;
|
||||
}
|
||||
|
||||
.suggestion-footer {
|
||||
margin-top: 0.75rem;
|
||||
padding-top: 0.75rem;
|
||||
border-top: 1px solid #e5e7eb;
|
||||
}
|
||||
|
||||
.date {
|
||||
font-size: 0.8rem;
|
||||
color: #9ca3af;
|
||||
}
|
||||
`]
|
||||
})
|
||||
export class MySuggestionsComponent implements OnInit {
|
||||
suggestionService = inject(SuggestionService);
|
||||
authService = inject(AuthService);
|
||||
|
||||
suggestions = signal<Suggestion[]>([]);
|
||||
loading = signal(true);
|
||||
statusFilter = signal<'all' | SuggestionStatus>('all');
|
||||
|
||||
SuggestionStatus = SuggestionStatus;
|
||||
|
||||
unreviewedCount = () => this.suggestions().filter(s => s.status === SuggestionStatus.UNREVIEWED).length;
|
||||
acceptedCount = () => this.suggestions().filter(s => s.status === SuggestionStatus.ACCEPTED).length;
|
||||
declinedCount = () => this.suggestions().filter(s => s.status === SuggestionStatus.DECLINED).length;
|
||||
|
||||
filteredSuggestions = () => {
|
||||
const filter = this.statusFilter();
|
||||
if (filter === 'all') {
|
||||
return this.suggestions();
|
||||
}
|
||||
return this.suggestions().filter(s => s.status === filter);
|
||||
};
|
||||
|
||||
ngOnInit() {
|
||||
if (this.authService.isAuthenticated()) {
|
||||
this.loadSuggestions();
|
||||
} else {
|
||||
this.loading.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
async loadSuggestions() {
|
||||
this.loading.set(true);
|
||||
try {
|
||||
const suggestions = await this.suggestionService.getMySuggestions();
|
||||
this.suggestions.set(suggestions);
|
||||
} catch {
|
||||
// Handle error silently
|
||||
} finally {
|
||||
this.loading.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
setFilter(filter: 'all' | SuggestionStatus) {
|
||||
this.statusFilter.set(filter);
|
||||
}
|
||||
|
||||
getStatusLabel(status: SuggestionStatus): string {
|
||||
switch (status) {
|
||||
case SuggestionStatus.UNREVIEWED: return 'Pending Review';
|
||||
case SuggestionStatus.ACCEPTED: return 'Accepted';
|
||||
case SuggestionStatus.DECLINED: return 'Declined';
|
||||
}
|
||||
}
|
||||
|
||||
getEntityIcon(entityType: SuggestionEntity): string {
|
||||
switch (entityType) {
|
||||
case SuggestionEntity.GAME: return '🎮';
|
||||
case SuggestionEntity.BOOK: return '📚';
|
||||
case SuggestionEntity.MUSIC: return '🎵';
|
||||
case SuggestionEntity.MANGA: return '📖';
|
||||
case SuggestionEntity.SHOW: return '📺';
|
||||
case SuggestionEntity.ART: return '🎨';
|
||||
}
|
||||
}
|
||||
|
||||
formatDate(date: Date | string): string {
|
||||
return new Date(date).toLocaleDateString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user