feat: add suggestion feature

This commit is contained in:
2026-02-04 19:09:28 -08:00
parent 912a8887a5
commit 9902c5ad45
22 changed files with 2666 additions and 49 deletions
+37
View File
@@ -160,6 +160,7 @@ model User {
createdAt DateTime @default(now()) createdAt DateTime @default(now())
updatedAt DateTime @updatedAt updatedAt DateTime @updatedAt
comments Comment[] comments Comment[]
suggestions Suggestion[]
} }
model Comment { model Comment {
@@ -221,3 +222,39 @@ enum AuditCategory {
ADMIN ADMIN
SECURITY SECURITY
} }
model Suggestion {
id String @id @default(auto()) @map("_id") @db.ObjectId
userId String @db.ObjectId
user User @relation(fields: [userId], references: [id])
entityType SuggestionEntity
status SuggestionStatus @default(UNREVIEWED)
declineReason String?
// Data for the suggested item (stored as JSON)
title String
gameData Json?
bookData Json?
musicData Json?
artData Json?
showData Json?
mangaData Json?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
enum SuggestionEntity {
GAME
BOOK
MUSIC
ART
SHOW
MANGA
}
enum SuggestionStatus {
UNREVIEWED
ACCEPTED
DECLINED
}
+1 -1
View File
@@ -25,6 +25,6 @@ export async function bannedGuard(
const isBanned = await userService.isUserBanned(user.id); const isBanned = await userService.isUserBanned(user.id);
if (isBanned) { if (isBanned) {
return reply.code(403).send({ error: "You have been banned from commenting" }); return reply.code(403).send({ error: "You have been banned" });
} }
} }
+173
View File
@@ -0,0 +1,173 @@
import type { FastifyInstance } from "fastify";
import { SuggestionService } from "../../services/suggestion.service";
import { AuditService } from "../../services/audit.service";
import { AuditAction, AuditCategory } from "@library/shared-types";
import type {
SuggestionStatus,
SuggestionEntity,
CreateSuggestionDto,
DeclineSuggestionDto,
} from "@library/shared-types";
import { adminGuard } from "../../middleware/admin-guard";
import { bannedGuard } from "../../middleware/banned-guard";
export default async function (app: FastifyInstance): Promise<void> {
// Get all suggestions (admin only)
app.get<{
Querystring: { status?: SuggestionStatus; entityType?: SuggestionEntity };
}>(
"/",
{
preHandler: [app.authenticate, adminGuard],
},
async (request, reply) => {
const { status, entityType } = request.query;
const suggestions = await SuggestionService.getAllSuggestions({
status,
entityType,
});
reply.send(suggestions);
}
);
// Get current user's suggestions
app.get(
"/my",
{
preHandler: [app.authenticate],
},
async (request, reply) => {
const userId = request.user.id;
const suggestions = await SuggestionService.getUserSuggestions(userId);
reply.send(suggestions);
}
);
// Get a single suggestion by ID
app.get<{ Params: { id: string } }>(
"/:id",
{
preHandler: [app.authenticate],
},
async (request, reply) => {
const { id } = request.params;
const suggestion = await SuggestionService.getSuggestionById(id);
if (!suggestion) {
return reply.notFound("Suggestion not found");
}
// Non-admins can only view their own suggestions
if (!request.user.isAdmin && suggestion.userId !== request.user.id) {
return reply.forbidden("You can only view your own suggestions");
}
reply.send(suggestion);
}
);
// Create a new suggestion (any authenticated non-banned user)
app.post<{ Body: CreateSuggestionDto }>(
"/",
{
preHandler: [app.authenticate, bannedGuard, app.csrfProtection],
},
async (request, reply) => {
const userId = request.user.id;
try {
const suggestion = await SuggestionService.createSuggestion(
userId,
request.body
);
await AuditService.log(
{
action: AuditAction.ENTRY_CREATE,
category: AuditCategory.CONTENT,
resourceType: "Suggestion",
resourceId: suggestion.id,
details: `Created ${suggestion.entityType} suggestion: ${suggestion.title}`,
success: true,
},
request
);
reply.send(suggestion);
} catch (error) {
return reply.badRequest(
error instanceof Error ? error.message : "Failed to create suggestion"
);
}
}
);
// Accept a suggestion (admin only)
app.put<{ Params: { id: string } }>(
"/:id/accept",
{
preHandler: [app.authenticate, adminGuard, app.csrfProtection],
},
async (request, reply) => {
const { id } = request.params;
try {
const suggestion = await SuggestionService.acceptSuggestion(id);
await AuditService.log(
{
action: AuditAction.ENTRY_UPDATE,
category: AuditCategory.ADMIN,
resourceType: "Suggestion",
resourceId: suggestion.id,
details: `Accepted ${suggestion.entityType} suggestion: ${suggestion.title}`,
success: true,
},
request
);
reply.send(suggestion);
} catch (error) {
return reply.badRequest(
error instanceof Error ? error.message : "Failed to accept suggestion"
);
}
}
);
// Decline a suggestion (admin only)
app.put<{ Params: { id: string }; Body: DeclineSuggestionDto }>(
"/:id/decline",
{
preHandler: [app.authenticate, adminGuard, app.csrfProtection],
},
async (request, reply) => {
const { id } = request.params;
const { reason } = request.body;
try {
const suggestion = await SuggestionService.declineSuggestion(id, reason);
await AuditService.log(
{
action: AuditAction.ENTRY_UPDATE,
category: AuditCategory.ADMIN,
resourceType: "Suggestion",
resourceId: suggestion.id,
details: `Declined ${suggestion.entityType} suggestion: ${suggestion.title}${reason ? ` (Reason: ${reason})` : ""}`,
success: true,
},
request
);
reply.send(suggestion);
} catch (error) {
return reply.badRequest(
error instanceof Error ? error.message : "Failed to decline suggestion"
);
}
}
);
}
+2 -2
View File
@@ -47,7 +47,7 @@ export class AuthService {
discordId: dbUser.discordId, discordId: dbUser.discordId,
username: dbUser.username, username: dbUser.username,
email: dbUser.email, email: dbUser.email,
avatarUrl: dbUser.avatar || undefined, avatar: dbUser.avatar || undefined,
isAdmin: dbUser.isAdmin, isAdmin: dbUser.isAdmin,
isBanned: dbUser.isBanned, isBanned: dbUser.isBanned,
inDiscord: dbUser.inDiscord, inDiscord: dbUser.inDiscord,
@@ -97,7 +97,7 @@ export class AuthService {
discordId: dbUser.discordId, discordId: dbUser.discordId,
username: dbUser.username, username: dbUser.username,
email: dbUser.email, email: dbUser.email,
avatarUrl: dbUser.avatar || undefined, avatar: dbUser.avatar || undefined,
isAdmin: dbUser.isAdmin, isAdmin: dbUser.isAdmin,
isBanned: dbUser.isBanned, isBanned: dbUser.isBanned,
inDiscord: dbUser.inDiscord, inDiscord: dbUser.inDiscord,
+1
View File
@@ -11,3 +11,4 @@ export { MusicService } from "./music.service";
export { ShowService } from "./show.service"; export { ShowService } from "./show.service";
export { MangaService } from "./manga.service"; export { MangaService } from "./manga.service";
export { AuditService } from "./audit.service"; export { AuditService } from "./audit.service";
export { SuggestionService } from "./suggestion.service";
+367
View File
@@ -0,0 +1,367 @@
import { prisma } from "../lib/prisma";
import type {
Suggestion,
SuggestionStatus,
SuggestionEntity,
CreateSuggestionDto,
} from "@library/shared-types";
import {
GameStatus,
BookStatus,
MusicType,
MusicStatus,
ShowType,
ShowStatus,
MangaStatus,
} from "@library/shared-types";
import { GameService } from "./game.service";
import { BookService } from "./book.service";
import { MusicService } from "./music.service";
import { ArtService } from "./art.service";
import { ShowService } from "./show.service";
import { MangaService } from "./manga.service";
const gameService = new GameService();
const bookService = new BookService();
const musicService = new MusicService();
const artService = new ArtService();
const showService = new ShowService();
const mangaService = new MangaService();
interface SuggestionUser {
id: string;
username: string;
avatar: string | null;
inDiscord: boolean;
isVip: boolean;
isMod: boolean;
isStaff: boolean;
}
function mapUser(user: {
id: string;
username: string;
avatar: string | null;
inDiscord: boolean;
isVip: boolean;
isMod: boolean;
isStaff: boolean;
}): SuggestionUser {
return {
id: user.id,
username: user.username,
avatar: user.avatar,
inDiscord: user.inDiscord,
isVip: user.isVip,
isMod: user.isMod,
isStaff: user.isStaff,
};
}
function mapSuggestion(suggestion: {
id: string;
userId: string;
user: {
id: string;
username: string;
avatar: string | null;
inDiscord: boolean;
isVip: boolean;
isMod: boolean;
isStaff: boolean;
};
entityType: string;
status: string;
declineReason: string | null;
title: string;
gameData: unknown;
bookData: unknown;
musicData: unknown;
artData: unknown;
showData: unknown;
mangaData: unknown;
createdAt: Date;
updatedAt: Date;
}): Suggestion {
return {
id: suggestion.id,
userId: suggestion.userId,
user: mapUser(suggestion.user) as Suggestion["user"],
entityType: suggestion.entityType as SuggestionEntity,
status: suggestion.status as SuggestionStatus,
declineReason: suggestion.declineReason ?? undefined,
title: suggestion.title,
gameData: suggestion.gameData as Suggestion["gameData"],
bookData: suggestion.bookData as Suggestion["bookData"],
musicData: suggestion.musicData as Suggestion["musicData"],
artData: suggestion.artData as Suggestion["artData"],
showData: suggestion.showData as Suggestion["showData"],
mangaData: suggestion.mangaData as Suggestion["mangaData"],
createdAt: suggestion.createdAt,
updatedAt: suggestion.updatedAt,
};
}
function getMusicType(type?: string): MusicType {
switch (type) {
case "ALBUM":
return MusicType.album;
case "SINGLE":
return MusicType.single;
case "EP":
return MusicType.ep;
default:
return MusicType.album;
}
}
function getShowType(type?: string): ShowType {
switch (type) {
case "TV_SERIES":
return ShowType.tvSeries;
case "ANIME":
return ShowType.anime;
case "FILM":
return ShowType.film;
case "DOCUMENTARY":
return ShowType.documentary;
default:
return ShowType.tvSeries;
}
}
export const SuggestionService = {
async getAllSuggestions(filters?: {
status?: SuggestionStatus;
entityType?: SuggestionEntity;
}): Promise<Suggestion[]> {
const suggestions = await prisma.suggestion.findMany({
where: {
...(filters?.status && { status: filters.status }),
...(filters?.entityType && { entityType: filters.entityType }),
},
include: {
user: true,
},
orderBy: {
createdAt: "desc",
},
});
return suggestions.map(mapSuggestion);
},
async getUserSuggestions(userId: string): Promise<Suggestion[]> {
const suggestions = await prisma.suggestion.findMany({
where: {
userId,
},
include: {
user: true,
},
orderBy: {
createdAt: "desc",
},
});
return suggestions.map(mapSuggestion);
},
async getSuggestionById(id: string): Promise<Suggestion | null> {
const suggestion = await prisma.suggestion.findUnique({
where: { id },
include: {
user: true,
},
});
if (!suggestion) {
return null;
}
return mapSuggestion(suggestion);
},
async createSuggestion(
userId: string,
data: CreateSuggestionDto
): Promise<Suggestion> {
const pendingCount = await prisma.suggestion.count({
where: {
userId,
status: "UNREVIEWED",
},
});
if (pendingCount >= 5) {
throw new Error("You can only have 5 pending suggestions at a time");
}
const entityDataField = `${data.entityType.toLowerCase()}Data`;
const suggestionData: Record<string, unknown> = {
userId,
entityType: data.entityType,
title: data.title,
};
// Extract the data without entityType and title
const { entityType: _et, title: _t, ...entityData } = data;
suggestionData[entityDataField] = entityData;
const suggestion = await prisma.suggestion.create({
data: suggestionData as Parameters<typeof prisma.suggestion.create>[0]["data"],
include: {
user: true,
},
});
return mapSuggestion(suggestion);
},
async acceptSuggestion(id: string): Promise<Suggestion> {
const suggestion = await prisma.suggestion.findUnique({
where: { id },
include: { user: true },
});
if (!suggestion) {
throw new Error("Suggestion not found");
}
if (suggestion.status !== "UNREVIEWED") {
throw new Error("Suggestion has already been reviewed");
}
// Create the entity based on type with "Want to X" status
switch (suggestion.entityType) {
case "GAME": {
const gameData = suggestion.gameData as {
platform?: string;
notes?: string;
coverImage?: string;
} | null;
await gameService.createGame({
title: suggestion.title,
platform: gameData?.platform,
status: GameStatus.backlog,
notes: gameData?.notes,
coverImage: gameData?.coverImage,
});
break;
}
case "BOOK": {
const bookData = suggestion.bookData as {
author: string;
isbn?: string;
notes?: string;
coverImage?: string;
} | null;
await bookService.createBook({
title: suggestion.title,
author: bookData?.author ?? "Unknown",
isbn: bookData?.isbn,
status: BookStatus.toRead,
notes: bookData?.notes,
coverImage: bookData?.coverImage,
});
break;
}
case "MUSIC": {
const musicData = suggestion.musicData as {
artist: string;
type: string;
notes?: string;
coverArt?: string;
} | null;
await musicService.createMusic({
title: suggestion.title,
artist: musicData?.artist ?? "Unknown",
type: getMusicType(musicData?.type),
status: MusicStatus.wantToListen,
notes: musicData?.notes,
coverArt: musicData?.coverArt,
});
break;
}
case "ART": {
const artData = suggestion.artData as {
artist: string;
description?: string;
imageUrl: string;
} | null;
await artService.createArt({
title: suggestion.title,
artist: artData?.artist ?? "Unknown",
description: artData?.description,
imageUrl: artData?.imageUrl ?? "",
});
break;
}
case "SHOW": {
const showData = suggestion.showData as {
type: string;
notes?: string;
coverImage?: string;
} | null;
await showService.createShow({
title: suggestion.title,
type: getShowType(showData?.type),
status: ShowStatus.wantToWatch,
notes: showData?.notes,
coverImage: showData?.coverImage,
});
break;
}
case "MANGA": {
const mangaData = suggestion.mangaData as {
author: string;
notes?: string;
coverImage?: string;
} | null;
await mangaService.createManga({
title: suggestion.title,
author: mangaData?.author ?? "Unknown",
status: MangaStatus.wantToRead,
notes: mangaData?.notes,
coverImage: mangaData?.coverImage,
});
break;
}
}
// Update suggestion status
const updatedSuggestion = await prisma.suggestion.update({
where: { id },
data: { status: "ACCEPTED" },
include: { user: true },
});
return mapSuggestion(updatedSuggestion);
},
async declineSuggestion(id: string, reason?: string): Promise<Suggestion> {
const suggestion = await prisma.suggestion.findUnique({
where: { id },
});
if (!suggestion) {
throw new Error("Suggestion not found");
}
if (suggestion.status !== "UNREVIEWED") {
throw new Error("Suggestion has already been reviewed");
}
const updatedSuggestion = await prisma.suggestion.update({
where: { id },
data: {
status: "DECLINED",
declineReason: reason,
},
include: { user: true },
});
return mapSuggestion(updatedSuggestion);
},
};
+4 -4
View File
@@ -20,7 +20,7 @@ export class UserService {
discordId: user.discordId, discordId: user.discordId,
username: user.username, username: user.username,
email: user.email, email: user.email,
avatarUrl: user.avatar || undefined, avatar: user.avatar || undefined,
isAdmin: user.isAdmin, isAdmin: user.isAdmin,
isBanned: user.isBanned, isBanned: user.isBanned,
inDiscord: user.inDiscord, inDiscord: user.inDiscord,
@@ -44,7 +44,7 @@ export class UserService {
discordId: user.discordId, discordId: user.discordId,
username: user.username, username: user.username,
email: user.email, email: user.email,
avatarUrl: user.avatar || undefined, avatar: user.avatar || undefined,
isAdmin: user.isAdmin, isAdmin: user.isAdmin,
isBanned: user.isBanned, isBanned: user.isBanned,
inDiscord: user.inDiscord, inDiscord: user.inDiscord,
@@ -65,7 +65,7 @@ export class UserService {
discordId: user.discordId, discordId: user.discordId,
username: user.username, username: user.username,
email: user.email, email: user.email,
avatarUrl: user.avatar || undefined, avatar: user.avatar || undefined,
isAdmin: user.isAdmin, isAdmin: user.isAdmin,
isBanned: user.isBanned, isBanned: user.isBanned,
inDiscord: user.inDiscord, inDiscord: user.inDiscord,
@@ -86,7 +86,7 @@ export class UserService {
discordId: user.discordId, discordId: user.discordId,
username: user.username, username: user.username,
email: user.email, email: user.email,
avatarUrl: user.avatar || undefined, avatar: user.avatar || undefined,
isAdmin: user.isAdmin, isAdmin: user.isAdmin,
isBanned: user.isBanned, isBanned: user.isBanned,
inDiscord: user.inDiscord, inDiscord: user.inDiscord,
+8
View File
@@ -37,6 +37,14 @@ export const appRoutes: Route[] = [
path: 'admin/audit', path: 'admin/audit',
loadComponent: () => import('./components/admin/admin-audit.component').then(m => m.AdminAuditComponent) loadComponent: () => import('./components/admin/admin-audit.component').then(m => m.AdminAuditComponent)
}, },
{
path: 'admin/suggestions',
loadComponent: () => import('./components/admin/admin-suggestions.component').then(m => m.AdminSuggestionsComponent)
},
{
path: 'my-suggestions',
loadComponent: () => import('./components/my-suggestions/my-suggestions.component').then(m => m.MySuggestionsComponent)
},
{ {
path: '**', path: '**',
redirectTo: '' redirectTo: ''
@@ -0,0 +1,634 @@
/**
* @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 { FormsModule } from '@angular/forms';
import { SuggestionService } from '../../services/suggestion.service';
import { AuthService } from '../../services/auth.service';
import { Suggestion, SuggestionStatus, SuggestionEntity } from '@library/shared-types';
@Component({
selector: 'app-admin-suggestions',
standalone: true,
imports: [CommonModule, FormsModule],
template: `
<div class="container">
<div class="header-section">
<h2>Manage Suggestions</h2>
<p class="subtitle">Review and respond to community suggestions</p>
</div>
@if (!authService.isAdmin()) {
<div class="not-authorized">
<p>You don't have permission to view this page.</p>
</div>
} @else if (loading()) {
<div class="loading">Loading suggestions...</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>
@if (filteredSuggestions().length === 0) {
<div class="empty-state">
<p>No suggestions found.</p>
</div>
} @else {
<div class="suggestions-list">
@for (suggestion of filteredSuggestions(); track suggestion.id) {
<div class="suggestion-card" [class]="'status-' + suggestion.status.toLowerCase()">
<div class="suggestion-header">
<div class="badges">
<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>
<span class="user-info">
@if (suggestion.user.avatar) {
<img [src]="suggestion.user.avatar" [alt]="suggestion.user.username" class="user-avatar">
}
{{ suggestion.user.username }}
</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.gameData.notes) {
<p><strong>Notes:</strong> {{ suggestion.gameData.notes }}</p>
}
@if (suggestion.gameData.coverImage) {
<img [src]="suggestion.gameData.coverImage" alt="Cover" class="suggestion-image">
}
}
@if (suggestion.bookData) {
@if (suggestion.bookData.author) {
<p><strong>Author:</strong> {{ suggestion.bookData.author }}</p>
}
@if (suggestion.bookData.isbn) {
<p><strong>ISBN:</strong> {{ suggestion.bookData.isbn }}</p>
}
@if (suggestion.bookData.notes) {
<p><strong>Notes:</strong> {{ suggestion.bookData.notes }}</p>
}
@if (suggestion.bookData.coverImage) {
<img [src]="suggestion.bookData.coverImage" alt="Cover" class="suggestion-image">
}
}
@if (suggestion.musicData) {
@if (suggestion.musicData.artist) {
<p><strong>Artist:</strong> {{ suggestion.musicData.artist }}</p>
}
@if (suggestion.musicData.type) {
<p><strong>Type:</strong> {{ suggestion.musicData.type }}</p>
}
@if (suggestion.musicData.notes) {
<p><strong>Notes:</strong> {{ suggestion.musicData.notes }}</p>
}
@if (suggestion.musicData.coverArt) {
<img [src]="suggestion.musicData.coverArt" alt="Cover" class="suggestion-image">
}
}
@if (suggestion.artData) {
@if (suggestion.artData.artist) {
<p><strong>Artist:</strong> {{ suggestion.artData.artist }}</p>
}
@if (suggestion.artData.description) {
<p><strong>Description:</strong> {{ suggestion.artData.description }}</p>
}
@if (suggestion.artData.imageUrl) {
<img [src]="suggestion.artData.imageUrl" alt="Artwork" class="suggestion-image">
}
}
@if (suggestion.showData) {
@if (suggestion.showData.type) {
<p><strong>Type:</strong> {{ suggestion.showData.type }}</p>
}
@if (suggestion.showData.notes) {
<p><strong>Notes:</strong> {{ suggestion.showData.notes }}</p>
}
@if (suggestion.showData.coverImage) {
<img [src]="suggestion.showData.coverImage" alt="Cover" class="suggestion-image">
}
}
@if (suggestion.mangaData) {
@if (suggestion.mangaData.author) {
<p><strong>Author:</strong> {{ suggestion.mangaData.author }}</p>
}
@if (suggestion.mangaData.notes) {
<p><strong>Notes:</strong> {{ suggestion.mangaData.notes }}</p>
}
@if (suggestion.mangaData.coverImage) {
<img [src]="suggestion.mangaData.coverImage" alt="Cover" class="suggestion-image">
}
}
</div>
@if (suggestion.status === SuggestionStatus.DECLINED && suggestion.declineReason) {
<div class="decline-reason">
<strong>Decline reason:</strong> {{ suggestion.declineReason }}
</div>
}
<div class="suggestion-footer">
<span class="date">Suggested on {{ formatDate(suggestion.createdAt) }}</span>
@if (suggestion.status === SuggestionStatus.UNREVIEWED) {
<div class="actions">
<button (click)="acceptSuggestion(suggestion)" class="btn btn-accept">
Accept
</button>
<button (click)="openDeclineModal(suggestion)" class="btn btn-decline">
Decline
</button>
</div>
}
</div>
</div>
}
</div>
}
}
@if (showDeclineModal()) {
<div class="modal-overlay" (click)="closeDeclineModal()">
<div class="modal" (click)="$event.stopPropagation()">
<h3>Decline Suggestion</h3>
<p>Are you sure you want to decline "{{ decliningsuggestion()?.title }}"?</p>
<div class="form-group">
<label for="decline-reason">Reason (optional):</label>
<textarea
id="decline-reason"
[(ngModel)]="declineReason"
name="declineReason"
rows="3"
placeholder="Let the user know why you're declining this suggestion..."
></textarea>
</div>
<div class="modal-actions">
<button (click)="confirmDecline()" class="btn btn-decline">Decline</button>
<button (click)="closeDeclineModal()" class="btn btn-secondary">Cancel</button>
</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-authorized,
.loading,
.empty-state {
text-align: center;
padding: 3rem;
color: #666;
background: #f8f9fa;
border-radius: 8px;
}
.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;
justify-content: space-between;
align-items: center;
margin-bottom: 0.75rem;
flex-wrap: wrap;
gap: 0.5rem;
}
.badges {
display: flex;
gap: 0.5rem;
}
.user-info {
display: flex;
align-items: center;
gap: 0.5rem;
font-size: 0.875rem;
color: #666;
}
.user-avatar {
width: 24px;
height: 24px;
border-radius: 50%;
}
.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;
}
.suggestion-image {
max-width: 150px;
max-height: 200px;
border-radius: 4px;
margin-top: 0.5rem;
border: 2px solid #e5e7eb;
}
.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;
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
gap: 0.5rem;
}
.date {
font-size: 0.8rem;
color: #9ca3af;
}
.actions {
display: flex;
gap: 0.5rem;
}
.btn {
padding: 0.5rem 1rem;
border: none;
border-radius: 4px;
cursor: pointer;
font-weight: 500;
transition: all 0.3s;
}
.btn-accept {
background: #10b981;
color: white;
}
.btn-accept:hover {
background: #059669;
}
.btn-decline {
background: #ef4444;
color: white;
}
.btn-decline:hover {
background: #dc2626;
}
.btn-secondary {
background: #e5e7eb;
color: #374151;
}
.btn-secondary:hover {
background: #d1d5db;
}
/* Modal styles */
.modal-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
display: flex;
align-items: center;
justify-content: center;
z-index: 1000;
}
.modal {
background: white;
border-radius: 8px;
padding: 1.5rem;
max-width: 500px;
width: 90%;
max-height: 90vh;
overflow-y: auto;
}
.modal h3 {
margin: 0 0 1rem 0;
}
.modal p {
margin: 0 0 1rem 0;
color: #666;
}
.form-group {
margin-bottom: 1rem;
}
.form-group label {
display: block;
margin-bottom: 0.5rem;
font-weight: 500;
}
.form-group textarea {
width: 100%;
padding: 0.5rem;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 1rem;
resize: vertical;
}
.modal-actions {
display: flex;
gap: 0.5rem;
justify-content: flex-end;
}
`]
})
export class AdminSuggestionsComponent implements OnInit {
suggestionService = inject(SuggestionService);
authService = inject(AuthService);
suggestions = signal<Suggestion[]>([]);
loading = signal(true);
statusFilter = signal<'all' | SuggestionStatus>('all');
showDeclineModal = signal(false);
decliningsuggestion = signal<Suggestion | null>(null);
declineReason = '';
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.isAdmin()) {
this.loadSuggestions();
} else {
this.loading.set(false);
}
}
async loadSuggestions() {
this.loading.set(true);
try {
const suggestions = await this.suggestionService.getAllSuggestions();
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';
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();
}
async acceptSuggestion(suggestion: Suggestion) {
if (!confirm(`Accept "${suggestion.title}"? This will add it to your collection.`)) return;
try {
await this.suggestionService.acceptSuggestion(suggestion.id);
alert(`"${suggestion.title}" has been added to your collection!`);
this.loadSuggestions();
} catch {
alert('Failed to accept suggestion. Please try again.');
}
}
openDeclineModal(suggestion: Suggestion) {
this.decliningsuggestion.set(suggestion);
this.declineReason = '';
this.showDeclineModal.set(true);
}
closeDeclineModal() {
this.showDeclineModal.set(false);
this.decliningsuggestion.set(null);
this.declineReason = '';
}
async confirmDecline() {
const suggestion = this.decliningsuggestion();
if (!suggestion) return;
try {
await this.suggestionService.declineSuggestion(suggestion.id, {
reason: this.declineReason || undefined
});
this.closeDeclineModal();
this.loadSuggestions();
} catch {
alert('Failed to decline suggestion. Please try again.');
}
}
}
@@ -28,8 +28,8 @@ import { User } from '@library/shared-types';
@for (user of users(); track user.id) { @for (user of users(); track user.id) {
<div class="user-card" [class.banned]="user.isBanned"> <div class="user-card" [class.banned]="user.isBanned">
<div class="user-info"> <div class="user-info">
@if (user.avatarUrl) { @if (user.avatar) {
<img [src]="user.avatarUrl" [alt]="user.username" class="avatar" /> <img [src]="user.avatar" [alt]="user.username" class="avatar" />
} @else { } @else {
<div class="avatar-placeholder">{{ user.username.charAt(0).toUpperCase() }}</div> <div class="avatar-placeholder">{{ user.username.charAt(0).toUpperCase() }}</div>
} }
@@ -11,7 +11,8 @@ import { ArtService } from '../../services/art.service';
import { AuthService } from '../../services/auth.service'; import { AuthService } from '../../services/auth.service';
import { CommentsService } from '../../services/comments.service'; import { CommentsService } from '../../services/comments.service';
import { SanitizeService } from '../../services/sanitize.service'; import { SanitizeService } from '../../services/sanitize.service';
import { Art, CreateArtDto, UpdateArtDto, Comment } from '@library/shared-types'; import { SuggestionService } from '../../services/suggestion.service';
import { Art, CreateArtDto, UpdateArtDto, Comment, SuggestionEntity } from '@library/shared-types';
@Component({ @Component({
selector: 'app-art-gallery', selector: 'app-art-gallery',
@@ -26,6 +27,10 @@ import { Art, CreateArtDto, UpdateArtDto, Comment } from '@library/shared-types'
<button (click)="toggleAddForm()" class="btn btn-primary"> <button (click)="toggleAddForm()" class="btn btn-primary">
{{ showAddForm() ? 'Cancel' : 'Add Art' }} {{ showAddForm() ? 'Cancel' : 'Add Art' }}
</button> </button>
} @else if (authService.isAuthenticated() && !authService.user()?.isBanned) {
<button (click)="toggleSuggestForm()" class="btn btn-primary">
{{ showSuggestForm() ? 'Cancel' : 'Suggest Art' }}
</button>
} }
</div> </div>
@@ -104,6 +109,71 @@ import { Art, CreateArtDto, UpdateArtDto, Comment } from '@library/shared-types'
</form> </form>
} }
@if (showSuggestForm() && !authService.isAdmin() && authService.isAuthenticated()) {
<form (ngSubmit)="submitSuggestion()" class="add-form suggest-form">
<h3>Suggest Art</h3>
<p class="suggest-note">Your suggestion will be reviewed by Naomi. If accepted, it will be added to the gallery!</p>
<div class="form-group">
<label for="suggest-title">Title</label>
<input
type="text"
id="suggest-title"
[(ngModel)]="suggestedArt.title"
name="title"
required
placeholder="Artwork title"
>
</div>
<div class="form-group">
<label for="suggest-artist">Artist</label>
<input
type="text"
id="suggest-artist"
[(ngModel)]="suggestedArt.artist"
name="artist"
required
placeholder="Who created this artwork"
>
</div>
<div class="form-group">
<label for="suggest-imageUrl">Image URL</label>
<input
type="url"
id="suggest-imageUrl"
[(ngModel)]="suggestedArt.imageUrl"
name="imageUrl"
required
placeholder="https://example.com/image.png"
>
</div>
<div class="form-group">
<label for="suggest-description">Description (optional, used as alt text)</label>
<textarea
id="suggest-description"
[(ngModel)]="suggestedArt.description"
name="description"
rows="2"
placeholder="Describe the artwork for accessibility..."
></textarea>
</div>
@if (suggestedArt.imageUrl) {
<div class="image-preview">
<p>Preview:</p>
<img [src]="suggestedArt.imageUrl" [alt]="suggestedArt.description || 'Preview'" (error)="onImageError($event)">
</div>
}
<div class="form-actions">
<button type="submit" class="btn btn-primary">Submit Suggestion</button>
<button type="button" (click)="toggleSuggestForm()" class="btn btn-secondary">Cancel</button>
</div>
</form>
}
@if (editingArt() && authService.isAdmin()) { @if (editingArt() && authService.isAdmin()) {
<form (ngSubmit)="saveEdit()" class="add-form"> <form (ngSubmit)="saveEdit()" class="add-form">
<h3>Edit Artwork</h3> <h3>Edit Artwork</h3>
@@ -367,6 +437,18 @@ import { Art, CreateArtDto, UpdateArtDto, Comment } from '@library/shared-types'
margin-right: auto; margin-right: auto;
} }
.suggest-form {
border: 2px solid #fdcb6e;
background: #fffdf5;
}
.suggest-note {
color: #666;
font-size: 0.9rem;
margin-bottom: 1rem;
font-style: italic;
}
.form-group { .form-group {
margin-bottom: 1rem; margin-bottom: 1rem;
} }
@@ -737,6 +819,7 @@ export class ArtGalleryComponent implements OnInit {
authService = inject(AuthService); authService = inject(AuthService);
commentsService = inject(CommentsService); commentsService = inject(CommentsService);
sanitizeService = inject(SanitizeService); sanitizeService = inject(SanitizeService);
suggestionService = inject(SuggestionService);
artPieces = signal<Art[]>([]); artPieces = signal<Art[]>([]);
loading = signal(true); loading = signal(true);
@@ -752,6 +835,15 @@ export class ArtGalleryComponent implements OnInit {
editingCommentId = signal<string | null>(null); editingCommentId = signal<string | null>(null);
editCommentContent = ''; editCommentContent = '';
// Suggestion state
showSuggestForm = signal(false);
suggestedArt: { title: string; artist: string; imageUrl: string; description?: string } = {
title: '',
artist: '',
imageUrl: '',
description: ''
};
newArt: Partial<CreateArtDto> = { newArt: Partial<CreateArtDto> = {
title: '', title: '',
artist: '', artist: '',
@@ -971,4 +1063,39 @@ export class ArtGalleryComponent implements OnInit {
} }
}); });
} }
// Suggestion methods
toggleSuggestForm() {
this.showSuggestForm.update(v => !v);
if (!this.showSuggestForm()) {
this.resetSuggestForm();
}
}
resetSuggestForm() {
this.suggestedArt = {
title: '',
artist: '',
imageUrl: '',
description: ''
};
}
async submitSuggestion() {
if (!this.suggestedArt.title || !this.suggestedArt.artist || !this.suggestedArt.imageUrl) return;
try {
await this.suggestionService.createSuggestion({
entityType: SuggestionEntity.ART,
title: this.suggestedArt.title,
artist: this.suggestedArt.artist,
imageUrl: this.suggestedArt.imageUrl,
description: this.suggestedArt.description
});
alert('Thank you for your suggestion! It will be reviewed soon.');
this.toggleSuggestForm();
} catch {
alert('Failed to submit suggestion. Please try again.');
}
}
} }
@@ -11,7 +11,8 @@ import { BooksService } from '../../services/books.service';
import { AuthService } from '../../services/auth.service'; import { AuthService } from '../../services/auth.service';
import { CommentsService } from '../../services/comments.service'; import { CommentsService } from '../../services/comments.service';
import { SanitizeService } from '../../services/sanitize.service'; import { SanitizeService } from '../../services/sanitize.service';
import { Book, BookStatus, CreateBookDto, UpdateBookDto, Comment } from '@library/shared-types'; import { SuggestionService } from '../../services/suggestion.service';
import { Book, BookStatus, CreateBookDto, UpdateBookDto, Comment, SuggestionEntity } from '@library/shared-types';
@Component({ @Component({
selector: 'app-books-list', selector: 'app-books-list',
@@ -25,6 +26,10 @@ import { Book, BookStatus, CreateBookDto, UpdateBookDto, Comment } from '@librar
<button (click)="toggleAddForm()" class="btn btn-primary"> <button (click)="toggleAddForm()" class="btn btn-primary">
{{ showAddForm() ? 'Cancel' : 'Add Book' }} {{ showAddForm() ? 'Cancel' : 'Add Book' }}
</button> </button>
} @else if (authService.isAuthenticated() && !authService.user()?.isBanned) {
<button (click)="toggleSuggestForm()" class="btn btn-primary">
{{ showSuggestForm() ? 'Cancel' : 'Suggest a Book' }}
</button>
} }
</div> </div>
@@ -222,6 +227,83 @@ import { Book, BookStatus, CreateBookDto, UpdateBookDto, Comment } from '@librar
</form> </form>
} }
@if (showSuggestForm() && !authService.isAdmin() && authService.isAuthenticated()) {
<form (ngSubmit)="submitSuggestion()" class="add-form suggest-form">
<h3>Suggest a Book</h3>
<p class="suggest-note">Your suggestion will be reviewed by Naomi. If accepted, it will be added to the reading list!</p>
<div class="form-group">
<label for="suggest-title">Title</label>
<input
type="text"
id="suggest-title"
[(ngModel)]="suggestedBook.title"
name="title"
required
placeholder="Enter book title"
>
</div>
<div class="form-group">
<label for="suggest-author">Author</label>
<input
type="text"
id="suggest-author"
[(ngModel)]="suggestedBook.author"
name="author"
required
placeholder="Enter author name"
>
</div>
<div class="form-group">
<label for="suggest-isbn">ISBN (optional)</label>
<input
type="text"
id="suggest-isbn"
[(ngModel)]="suggestedBook.isbn"
name="isbn"
placeholder="ISBN (optional)"
>
</div>
<div class="form-group">
<label for="suggest-notes">Notes (why should Naomi read this?)</label>
<textarea
id="suggest-notes"
[(ngModel)]="suggestedBook.notes"
name="notes"
rows="3"
placeholder="Tell Naomi why this book is worth reading..."
></textarea>
</div>
<div class="form-group">
<label for="suggest-coverImage">Cover Image (max 500KB)</label>
<input
type="file"
id="suggest-coverImage"
name="coverImage"
accept="image/*"
(change)="onImageSelected($event, 'suggest')"
>
@if (suggestBookImagePreview()) {
<div class="image-preview">
<img [src]="suggestBookImagePreview()" alt="Cover preview">
<button type="button" (click)="clearImage('suggest')" class="btn btn-danger btn-sm">Remove</button>
</div>
}
@if (imageError()) {
<span class="error-text">{{ imageError() }}</span>
}
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">Submit Suggestion</button>
<button type="button" (click)="toggleSuggestForm()" class="btn btn-secondary">Cancel</button>
</div>
</form>
}
<div class="filters"> <div class="filters">
<button <button
(click)="setFilter('all')" (click)="setFilter('all')"
@@ -422,6 +504,18 @@ import { Book, BookStatus, CreateBookDto, UpdateBookDto, Comment } from '@librar
backdrop-filter: blur(10px); backdrop-filter: blur(10px);
} }
.suggest-form {
border: 2px solid #8b6f47;
background: #faf8f5;
}
.suggest-note {
color: #666;
font-size: 0.9rem;
margin-bottom: 1rem;
font-style: italic;
}
.form-group { .form-group {
margin-bottom: 1rem; margin-bottom: 1rem;
} }
@@ -851,6 +945,7 @@ export class BooksListComponent implements OnInit {
authService = inject(AuthService); authService = inject(AuthService);
commentsService = inject(CommentsService); commentsService = inject(CommentsService);
sanitizeService = inject(SanitizeService); sanitizeService = inject(SanitizeService);
suggestionService = inject(SuggestionService);
books = signal<Book[]>([]); books = signal<Book[]>([]);
loading = signal(true); loading = signal(true);
@@ -869,9 +964,20 @@ export class BooksListComponent implements OnInit {
// Image upload state // Image upload state
newBookImagePreview = signal<string | null>(null); newBookImagePreview = signal<string | null>(null);
editBookImagePreview = signal<string | null>(null); editBookImagePreview = signal<string | null>(null);
suggestBookImagePreview = signal<string | null>(null);
imageError = signal<string | null>(null); imageError = signal<string | null>(null);
private readonly MAX_IMAGE_SIZE = 500 * 1024; // 500KB private readonly MAX_IMAGE_SIZE = 500 * 1024; // 500KB
// Suggestion state
showSuggestForm = signal(false);
suggestedBook: { title: string; author: string; isbn?: string; notes?: string; coverImage?: string } = {
title: '',
author: '',
isbn: '',
notes: '',
coverImage: undefined
};
// Expose BookStatus enum to template // Expose BookStatus enum to template
BookStatus = BookStatus; BookStatus = BookStatus;
@@ -1014,7 +1120,7 @@ export class BooksListComponent implements OnInit {
} }
// Image handling methods // Image handling methods
onImageSelected(event: Event, target: 'new' | 'edit') { onImageSelected(event: Event, target: 'new' | 'edit' | 'suggest') {
const input = event.target as HTMLInputElement; const input = event.target as HTMLInputElement;
const file = input.files?.[0]; const file = input.files?.[0];
@@ -1040,21 +1146,27 @@ export class BooksListComponent implements OnInit {
if (target === 'new') { if (target === 'new') {
this.newBookImagePreview.set(base64); this.newBookImagePreview.set(base64);
this.newBook.coverImage = base64; this.newBook.coverImage = base64;
} else { } else if (target === 'edit') {
this.editBookImagePreview.set(base64); this.editBookImagePreview.set(base64);
this.editBook.coverImage = base64; this.editBook.coverImage = base64;
} else {
this.suggestBookImagePreview.set(base64);
this.suggestedBook.coverImage = base64;
} }
}; };
reader.readAsDataURL(file); reader.readAsDataURL(file);
} }
clearImage(target: 'new' | 'edit') { clearImage(target: 'new' | 'edit' | 'suggest') {
if (target === 'new') { if (target === 'new') {
this.newBookImagePreview.set(null); this.newBookImagePreview.set(null);
this.newBook.coverImage = undefined; this.newBook.coverImage = undefined;
} else { } else if (target === 'edit') {
this.editBookImagePreview.set(null); this.editBookImagePreview.set(null);
this.editBook.coverImage = undefined; this.editBook.coverImage = undefined;
} else {
this.suggestBookImagePreview.set(null);
this.suggestedBook.coverImage = undefined;
} }
this.imageError.set(null); this.imageError.set(null);
} }
@@ -1169,4 +1281,43 @@ export class BooksListComponent implements OnInit {
} }
}); });
} }
// Suggestion methods
toggleSuggestForm() {
this.showSuggestForm.update(v => !v);
if (!this.showSuggestForm()) {
this.resetSuggestForm();
}
}
resetSuggestForm() {
this.suggestedBook = {
title: '',
author: '',
isbn: '',
notes: '',
coverImage: undefined
};
this.suggestBookImagePreview.set(null);
this.imageError.set(null);
}
async submitSuggestion() {
if (!this.suggestedBook.title || !this.suggestedBook.author) return;
try {
await this.suggestionService.createSuggestion({
entityType: SuggestionEntity.BOOK,
title: this.suggestedBook.title,
author: this.suggestedBook.author,
isbn: this.suggestedBook.isbn,
notes: this.suggestedBook.notes,
coverImage: this.suggestedBook.coverImage
});
alert('Thank you for your suggestion! It will be reviewed soon.');
this.toggleSuggestForm();
} catch {
alert('Failed to submit suggestion. Please try again.');
}
}
} }
@@ -11,7 +11,8 @@ import { GamesService } from '../../services/games.service';
import { AuthService } from '../../services/auth.service'; import { AuthService } from '../../services/auth.service';
import { CommentsService } from '../../services/comments.service'; import { CommentsService } from '../../services/comments.service';
import { SanitizeService } from '../../services/sanitize.service'; import { SanitizeService } from '../../services/sanitize.service';
import { Game, GameStatus, CreateGameDto, UpdateGameDto, Comment } from '@library/shared-types'; import { SuggestionService } from '../../services/suggestion.service';
import { Game, GameStatus, CreateGameDto, UpdateGameDto, Comment, SuggestionEntity } from '@library/shared-types';
@Component({ @Component({
selector: 'app-games-list', selector: 'app-games-list',
@@ -25,6 +26,10 @@ import { Game, GameStatus, CreateGameDto, UpdateGameDto, Comment } from '@librar
<button (click)="toggleAddForm()" class="btn btn-primary"> <button (click)="toggleAddForm()" class="btn btn-primary">
{{ showAddForm() ? 'Cancel' : 'Add Game' }} {{ showAddForm() ? 'Cancel' : 'Add Game' }}
</button> </button>
} @else if (authService.isAuthenticated() && !authService.user()?.isBanned) {
<button (click)="toggleSuggestForm()" class="btn btn-primary">
{{ showSuggestForm() ? 'Cancel' : 'Suggest a Game' }}
</button>
} }
</div> </div>
@@ -198,6 +203,71 @@ import { Game, GameStatus, CreateGameDto, UpdateGameDto, Comment } from '@librar
</form> </form>
} }
@if (showSuggestForm() && !authService.isAdmin() && authService.isAuthenticated()) {
<form (ngSubmit)="submitSuggestion()" class="add-form suggest-form">
<h3>Suggest a Game</h3>
<p class="suggest-note">Your suggestion will be reviewed by Naomi. If accepted, it will be added to the backlog!</p>
<div class="form-group">
<label for="suggest-title">Title</label>
<input
type="text"
id="suggest-title"
[(ngModel)]="suggestedGame.title"
name="title"
required
placeholder="Enter game title"
>
</div>
<div class="form-group">
<label for="suggest-platform">Platform</label>
<input
type="text"
id="suggest-platform"
[(ngModel)]="suggestedGame.platform"
name="platform"
placeholder="PC, PS5, Xbox, Switch, etc."
>
</div>
<div class="form-group">
<label for="suggest-notes">Notes (why should Naomi play this?)</label>
<textarea
id="suggest-notes"
[(ngModel)]="suggestedGame.notes"
name="notes"
rows="3"
placeholder="Tell Naomi why this game is worth playing..."
></textarea>
</div>
<div class="form-group">
<label for="suggest-coverImage">Box Art (max 500KB)</label>
<input
type="file"
id="suggest-coverImage"
name="coverImage"
accept="image/*"
(change)="onImageSelected($event, 'suggest')"
>
@if (suggestGameImagePreview()) {
<div class="image-preview">
<img [src]="suggestGameImagePreview()" alt="Box art preview">
<button type="button" (click)="clearImage('suggest')" class="btn btn-danger btn-sm">Remove</button>
</div>
}
@if (imageError()) {
<span class="error-text">{{ imageError() }}</span>
}
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">Submit Suggestion</button>
<button type="button" (click)="toggleSuggestForm()" class="btn btn-secondary">Cancel</button>
</div>
</form>
}
<div class="filters"> <div class="filters">
<button <button
(click)="setFilter('all')" (click)="setFilter('all')"
@@ -385,6 +455,18 @@ import { Game, GameStatus, CreateGameDto, UpdateGameDto, Comment } from '@librar
margin-bottom: 2rem; margin-bottom: 2rem;
} }
.suggest-form {
border: 2px solid #ff6b6b;
background: #fff9f9;
}
.suggest-note {
color: #666;
font-size: 0.9rem;
margin-bottom: 1rem;
font-style: italic;
}
.form-group { .form-group {
margin-bottom: 1rem; margin-bottom: 1rem;
} }
@@ -723,6 +805,7 @@ export class GamesListComponent implements OnInit {
authService = inject(AuthService); authService = inject(AuthService);
commentsService = inject(CommentsService); commentsService = inject(CommentsService);
sanitizeService = inject(SanitizeService); sanitizeService = inject(SanitizeService);
suggestionService = inject(SuggestionService);
games = signal<Game[]>([]); games = signal<Game[]>([]);
loading = signal(true); loading = signal(true);
@@ -741,9 +824,19 @@ export class GamesListComponent implements OnInit {
// Image upload state // Image upload state
newGameImagePreview = signal<string | null>(null); newGameImagePreview = signal<string | null>(null);
editGameImagePreview = signal<string | null>(null); editGameImagePreview = signal<string | null>(null);
suggestGameImagePreview = signal<string | null>(null);
imageError = signal<string | null>(null); imageError = signal<string | null>(null);
private readonly MAX_IMAGE_SIZE = 500 * 1024; // 500KB private readonly MAX_IMAGE_SIZE = 500 * 1024; // 500KB
// Suggestion state
showSuggestForm = signal(false);
suggestedGame: { title: string; platform?: string; notes?: string; coverImage?: string } = {
title: '',
platform: '',
notes: '',
coverImage: undefined
};
// Expose GameStatus enum to template // Expose GameStatus enum to template
GameStatus = GameStatus; GameStatus = GameStatus;
@@ -878,7 +971,7 @@ export class GamesListComponent implements OnInit {
} }
// Image handling methods // Image handling methods
onImageSelected(event: Event, target: 'new' | 'edit') { onImageSelected(event: Event, target: 'new' | 'edit' | 'suggest') {
const input = event.target as HTMLInputElement; const input = event.target as HTMLInputElement;
const file = input.files?.[0]; const file = input.files?.[0];
@@ -904,21 +997,27 @@ export class GamesListComponent implements OnInit {
if (target === 'new') { if (target === 'new') {
this.newGameImagePreview.set(base64); this.newGameImagePreview.set(base64);
this.newGame.coverImage = base64; this.newGame.coverImage = base64;
} else { } else if (target === 'edit') {
this.editGameImagePreview.set(base64); this.editGameImagePreview.set(base64);
this.editGame.coverImage = base64; this.editGame.coverImage = base64;
} else {
this.suggestGameImagePreview.set(base64);
this.suggestedGame.coverImage = base64;
} }
}; };
reader.readAsDataURL(file); reader.readAsDataURL(file);
} }
clearImage(target: 'new' | 'edit') { clearImage(target: 'new' | 'edit' | 'suggest') {
if (target === 'new') { if (target === 'new') {
this.newGameImagePreview.set(null); this.newGameImagePreview.set(null);
this.newGame.coverImage = undefined; this.newGame.coverImage = undefined;
} else { } else if (target === 'edit') {
this.editGameImagePreview.set(null); this.editGameImagePreview.set(null);
this.editGame.coverImage = undefined; this.editGame.coverImage = undefined;
} else {
this.suggestGameImagePreview.set(null);
this.suggestedGame.coverImage = undefined;
} }
this.imageError.set(null); this.imageError.set(null);
} }
@@ -1037,4 +1136,41 @@ export class GamesListComponent implements OnInit {
} }
}); });
} }
// Suggestion methods
toggleSuggestForm() {
this.showSuggestForm.update(v => !v);
if (!this.showSuggestForm()) {
this.resetSuggestForm();
}
}
resetSuggestForm() {
this.suggestedGame = {
title: '',
platform: '',
notes: '',
coverImage: undefined
};
this.suggestGameImagePreview.set(null);
this.imageError.set(null);
}
async submitSuggestion() {
if (!this.suggestedGame.title) return;
try {
await this.suggestionService.createSuggestion({
entityType: SuggestionEntity.GAME,
title: this.suggestedGame.title,
platform: this.suggestedGame.platform,
notes: this.suggestedGame.notes,
coverImage: this.suggestedGame.coverImage
});
alert('Thank you for your suggestion! It will be reviewed soon.');
this.toggleSuggestForm();
} catch {
alert('Failed to submit suggestion. Please try again.');
}
}
} }
@@ -32,9 +32,13 @@ import { AuthService } from '../../services/auth.service';
<div class="auth-section"> <div class="auth-section">
@if (authService.user(); as user) { @if (authService.user(); as user) {
<span class="welcome">Welcome, {{ user.username }}!</span> <span class="welcome">Welcome, {{ user.username }}!</span>
@if (!user.isAdmin) {
<a routerLink="/my-suggestions" class="user-link">My Suggestions</a>
}
@if (user.isAdmin) { @if (user.isAdmin) {
<a routerLink="/admin/users" class="admin-badge">Users</a> <a routerLink="/admin/users" class="admin-badge">Users</a>
<a routerLink="/admin/audit" class="admin-badge">Audit</a> <a routerLink="/admin/audit" class="admin-badge">Audit</a>
<a routerLink="/admin/suggestions" class="admin-badge">Suggestions</a>
} }
<button (click)="logout()" class="btn btn-secondary">Logout</button> <button (click)="logout()" class="btn btn-secondary">Logout</button>
} @else { } @else {
@@ -122,6 +126,20 @@ import { AuthService } from '../../services/auth.service';
transform: translateY(-2px); transform: translateY(-2px);
} }
.user-link {
color: var(--witch-lavender);
text-decoration: none;
font-size: 0.9rem;
padding: 0.25rem 0.5rem;
border-radius: 4px;
transition: all 0.3s;
}
.user-link:hover {
background-color: var(--witch-plum);
color: var(--witch-moon);
}
.btn { .btn {
padding: 0.5rem 1rem; padding: 0.5rem 1rem;
border: none; border: none;
@@ -11,7 +11,8 @@ import { MangaService } from '../../services/manga.service';
import { AuthService } from '../../services/auth.service'; import { AuthService } from '../../services/auth.service';
import { CommentsService } from '../../services/comments.service'; import { CommentsService } from '../../services/comments.service';
import { SanitizeService } from '../../services/sanitize.service'; import { SanitizeService } from '../../services/sanitize.service';
import { Manga, MangaStatus, CreateMangaDto, UpdateMangaDto, Comment } from '@library/shared-types'; import { SuggestionService } from '../../services/suggestion.service';
import { Manga, MangaStatus, CreateMangaDto, UpdateMangaDto, Comment, SuggestionEntity } from '@library/shared-types';
@Component({ @Component({
selector: 'app-manga-list', selector: 'app-manga-list',
@@ -25,6 +26,10 @@ import { Manga, MangaStatus, CreateMangaDto, UpdateMangaDto, Comment } from '@li
<button (click)="toggleAddForm()" class="btn btn-primary"> <button (click)="toggleAddForm()" class="btn btn-primary">
{{ showAddForm() ? 'Cancel' : 'Add Manga' }} {{ showAddForm() ? 'Cancel' : 'Add Manga' }}
</button> </button>
} @else if (authService.isAuthenticated() && !authService.user()?.isBanned) {
<button (click)="toggleSuggestForm()" class="btn btn-primary">
{{ showSuggestForm() ? 'Cancel' : 'Suggest a Manga' }}
</button>
} }
</div> </div>
@@ -200,6 +205,72 @@ import { Manga, MangaStatus, CreateMangaDto, UpdateMangaDto, Comment } from '@li
</form> </form>
} }
@if (showSuggestForm() && !authService.isAdmin() && authService.isAuthenticated()) {
<form (ngSubmit)="submitSuggestion()" class="add-form suggest-form">
<h3>Suggest a Manga</h3>
<p class="suggest-note">Your suggestion will be reviewed by Naomi. If accepted, it will be added to the reading list!</p>
<div class="form-group">
<label for="suggest-title">Title</label>
<input
type="text"
id="suggest-title"
[(ngModel)]="suggestedManga.title"
name="title"
required
placeholder="Enter manga title"
>
</div>
<div class="form-group">
<label for="suggest-author">Author/Artist</label>
<input
type="text"
id="suggest-author"
[(ngModel)]="suggestedManga.author"
name="author"
required
placeholder="Enter author or artist name"
>
</div>
<div class="form-group">
<label for="suggest-notes">Notes (why should Naomi read this?)</label>
<textarea
id="suggest-notes"
[(ngModel)]="suggestedManga.notes"
name="notes"
rows="3"
placeholder="Tell Naomi why this manga is worth reading..."
></textarea>
</div>
<div class="form-group">
<label for="suggest-coverImage">Cover Art (max 500KB)</label>
<input
type="file"
id="suggest-coverImage"
name="coverImage"
accept="image/*"
(change)="onImageSelected($event, 'suggest')"
>
@if (suggestMangaImagePreview()) {
<div class="image-preview">
<img [src]="suggestMangaImagePreview()" alt="Cover preview">
<button type="button" (click)="clearImage('suggest')" class="btn btn-danger btn-sm">Remove</button>
</div>
}
@if (imageError()) {
<span class="error-text">{{ imageError() }}</span>
}
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">Submit Suggestion</button>
<button type="button" (click)="toggleSuggestForm()" class="btn btn-secondary">Cancel</button>
</div>
</form>
}
<div class="filters"> <div class="filters">
<button <button
(click)="setFilter('all')" (click)="setFilter('all')"
@@ -385,6 +456,18 @@ import { Manga, MangaStatus, CreateMangaDto, UpdateMangaDto, Comment } from '@li
margin-bottom: 2rem; margin-bottom: 2rem;
} }
.suggest-form {
border: 2px solid #00b894;
background: #f5fffc;
}
.suggest-note {
color: #666;
font-size: 0.9rem;
margin-bottom: 1rem;
font-style: italic;
}
.form-group { .form-group {
margin-bottom: 1rem; margin-bottom: 1rem;
} }
@@ -725,6 +808,7 @@ export class MangaListComponent implements OnInit {
authService = inject(AuthService); authService = inject(AuthService);
commentsService = inject(CommentsService); commentsService = inject(CommentsService);
sanitizeService = inject(SanitizeService); sanitizeService = inject(SanitizeService);
suggestionService = inject(SuggestionService);
mangaList = signal<Manga[]>([]); mangaList = signal<Manga[]>([]);
loading = signal(true); loading = signal(true);
@@ -741,9 +825,19 @@ export class MangaListComponent implements OnInit {
newMangaImagePreview = signal<string | null>(null); newMangaImagePreview = signal<string | null>(null);
editMangaImagePreview = signal<string | null>(null); editMangaImagePreview = signal<string | null>(null);
suggestMangaImagePreview = signal<string | null>(null);
imageError = signal<string | null>(null); imageError = signal<string | null>(null);
private readonly MAX_IMAGE_SIZE = 500 * 1024; private readonly MAX_IMAGE_SIZE = 500 * 1024;
// Suggestion state
showSuggestForm = signal(false);
suggestedManga: { title: string; author: string; notes?: string; coverImage?: string } = {
title: '',
author: '',
notes: '',
coverImage: undefined
};
MangaStatus = MangaStatus; MangaStatus = MangaStatus;
readingCount = computed(() => this.mangaList().filter(m => m.status === MangaStatus.reading).length); readingCount = computed(() => this.mangaList().filter(m => m.status === MangaStatus.reading).length);
@@ -875,7 +969,7 @@ export class MangaListComponent implements OnInit {
}); });
} }
onImageSelected(event: Event, target: 'new' | 'edit') { onImageSelected(event: Event, target: 'new' | 'edit' | 'suggest') {
const input = event.target as HTMLInputElement; const input = event.target as HTMLInputElement;
const file = input.files?.[0]; const file = input.files?.[0];
@@ -901,21 +995,27 @@ export class MangaListComponent implements OnInit {
if (target === 'new') { if (target === 'new') {
this.newMangaImagePreview.set(base64); this.newMangaImagePreview.set(base64);
this.newManga.coverImage = base64; this.newManga.coverImage = base64;
} else { } else if (target === 'edit') {
this.editMangaImagePreview.set(base64); this.editMangaImagePreview.set(base64);
this.editManga.coverImage = base64; this.editManga.coverImage = base64;
} else {
this.suggestMangaImagePreview.set(base64);
this.suggestedManga.coverImage = base64;
} }
}; };
reader.readAsDataURL(file); reader.readAsDataURL(file);
} }
clearImage(target: 'new' | 'edit') { clearImage(target: 'new' | 'edit' | 'suggest') {
if (target === 'new') { if (target === 'new') {
this.newMangaImagePreview.set(null); this.newMangaImagePreview.set(null);
this.newManga.coverImage = undefined; this.newManga.coverImage = undefined;
} else { } else if (target === 'edit') {
this.editMangaImagePreview.set(null); this.editMangaImagePreview.set(null);
this.editManga.coverImage = undefined; this.editManga.coverImage = undefined;
} else {
this.suggestMangaImagePreview.set(null);
this.suggestedManga.coverImage = undefined;
} }
this.imageError.set(null); this.imageError.set(null);
} }
@@ -1033,4 +1133,41 @@ export class MangaListComponent implements OnInit {
} }
}); });
} }
// Suggestion methods
toggleSuggestForm() {
this.showSuggestForm.update(v => !v);
if (!this.showSuggestForm()) {
this.resetSuggestForm();
}
}
resetSuggestForm() {
this.suggestedManga = {
title: '',
author: '',
notes: '',
coverImage: undefined
};
this.suggestMangaImagePreview.set(null);
this.imageError.set(null);
}
async submitSuggestion() {
if (!this.suggestedManga.title || !this.suggestedManga.author) return;
try {
await this.suggestionService.createSuggestion({
entityType: SuggestionEntity.MANGA,
title: this.suggestedManga.title,
author: this.suggestedManga.author,
notes: this.suggestedManga.notes,
coverImage: this.suggestedManga.coverImage
});
alert('Thank you for your suggestion! It will be reviewed soon.');
this.toggleSuggestForm();
} catch {
alert('Failed to submit suggestion. Please try again.');
}
}
} }
@@ -11,7 +11,8 @@ import { MusicService } from '../../services/music.service';
import { AuthService } from '../../services/auth.service'; import { AuthService } from '../../services/auth.service';
import { CommentsService } from '../../services/comments.service'; import { CommentsService } from '../../services/comments.service';
import { SanitizeService } from '../../services/sanitize.service'; import { SanitizeService } from '../../services/sanitize.service';
import { Music, MusicStatus, MusicType, CreateMusicDto, UpdateMusicDto, Comment } from '@library/shared-types'; import { SuggestionService } from '../../services/suggestion.service';
import { Music, MusicStatus, MusicType, CreateMusicDto, UpdateMusicDto, Comment, SuggestionEntity } from '@library/shared-types';
@Component({ @Component({
selector: 'app-music-list', selector: 'app-music-list',
@@ -25,6 +26,10 @@ import { Music, MusicStatus, MusicType, CreateMusicDto, UpdateMusicDto, Comment
<button (click)="toggleAddForm()" class="btn btn-primary"> <button (click)="toggleAddForm()" class="btn btn-primary">
{{ showAddForm() ? 'Cancel' : 'Add Music' }} {{ showAddForm() ? 'Cancel' : 'Add Music' }}
</button> </button>
} @else if (authService.isAuthenticated() && !authService.user()?.isBanned) {
<button (click)="toggleSuggestForm()" class="btn btn-primary">
{{ showSuggestForm() ? 'Cancel' : 'Suggest Music' }}
</button>
} }
</div> </div>
@@ -218,6 +223,81 @@ import { Music, MusicStatus, MusicType, CreateMusicDto, UpdateMusicDto, Comment
</form> </form>
} }
@if (showSuggestForm() && !authService.isAdmin() && authService.isAuthenticated()) {
<form (ngSubmit)="submitSuggestion()" class="add-form suggest-form">
<h3>Suggest Music</h3>
<p class="suggest-note">Your suggestion will be reviewed by Naomi. If accepted, it will be added to the listening list!</p>
<div class="form-group">
<label for="suggest-title">Title</label>
<input
type="text"
id="suggest-title"
[(ngModel)]="suggestedMusic.title"
name="title"
required
placeholder="Album/Single/EP title"
>
</div>
<div class="form-group">
<label for="suggest-artist">Artist</label>
<input
type="text"
id="suggest-artist"
[(ngModel)]="suggestedMusic.artist"
name="artist"
required
placeholder="Artist name"
>
</div>
<div class="form-group">
<label for="suggest-type">Type</label>
<select id="suggest-type" [(ngModel)]="suggestedMusic.type" name="type" required>
<option [value]="MusicType.album">Album</option>
<option [value]="MusicType.single">Single</option>
<option [value]="MusicType.ep">EP</option>
</select>
</div>
<div class="form-group">
<label for="suggest-notes">Notes (why should Naomi listen to this?)</label>
<textarea
id="suggest-notes"
[(ngModel)]="suggestedMusic.notes"
name="notes"
rows="3"
placeholder="Tell Naomi why this music is worth listening to..."
></textarea>
</div>
<div class="form-group">
<label for="suggest-coverArt">Album Art (max 500KB)</label>
<input
type="file"
id="suggest-coverArt"
name="coverArt"
accept="image/*"
(change)="onImageSelected($event, 'suggest')"
>
@if (suggestMusicImagePreview()) {
<div class="image-preview">
<img [src]="suggestMusicImagePreview()" alt="Album art preview">
<button type="button" (click)="clearImage('suggest')" class="btn btn-danger btn-sm">Remove</button>
</div>
}
@if (imageError()) {
<span class="error-text">{{ imageError() }}</span>
}
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">Submit Suggestion</button>
<button type="button" (click)="toggleSuggestForm()" class="btn btn-secondary">Cancel</button>
</div>
</form>
}
<div class="filters"> <div class="filters">
<div class="filter-group"> <div class="filter-group">
<strong>Type:</strong> <strong>Type:</strong>
@@ -460,6 +540,18 @@ import { Music, MusicStatus, MusicType, CreateMusicDto, UpdateMusicDto, Comment
backdrop-filter: blur(10px); backdrop-filter: blur(10px);
} }
.suggest-form {
border: 2px solid #74b9ff;
background: #f5faff;
}
.suggest-note {
color: #666;
font-size: 0.9rem;
margin-bottom: 1rem;
font-style: italic;
}
.form-group { .form-group {
margin-bottom: 1rem; margin-bottom: 1rem;
} }
@@ -923,6 +1015,7 @@ export class MusicListComponent implements OnInit {
authService = inject(AuthService); authService = inject(AuthService);
commentsService = inject(CommentsService); commentsService = inject(CommentsService);
sanitizeService = inject(SanitizeService); sanitizeService = inject(SanitizeService);
suggestionService = inject(SuggestionService);
music = signal<Music[]>([]); music = signal<Music[]>([]);
loading = signal(true); loading = signal(true);
@@ -942,9 +1035,20 @@ export class MusicListComponent implements OnInit {
// Image upload state // Image upload state
newMusicImagePreview = signal<string | null>(null); newMusicImagePreview = signal<string | null>(null);
editMusicImagePreview = signal<string | null>(null); editMusicImagePreview = signal<string | null>(null);
suggestMusicImagePreview = signal<string | null>(null);
imageError = signal<string | null>(null); imageError = signal<string | null>(null);
private readonly MAX_IMAGE_SIZE = 500 * 1024; // 500KB private readonly MAX_IMAGE_SIZE = 500 * 1024; // 500KB
// Suggestion state
showSuggestForm = signal(false);
suggestedMusic: { title: string; artist: string; type: MusicType; notes?: string; coverArt?: string } = {
title: '',
artist: '',
type: MusicType.album,
notes: '',
coverArt: undefined
};
// Expose enums to template // Expose enums to template
MusicType = MusicType; MusicType = MusicType;
MusicStatus = MusicStatus; MusicStatus = MusicStatus;
@@ -1113,7 +1217,7 @@ export class MusicListComponent implements OnInit {
} }
// Image handling methods // Image handling methods
onImageSelected(event: Event, target: 'new' | 'edit') { onImageSelected(event: Event, target: 'new' | 'edit' | 'suggest') {
const input = event.target as HTMLInputElement; const input = event.target as HTMLInputElement;
const file = input.files?.[0]; const file = input.files?.[0];
@@ -1139,21 +1243,27 @@ export class MusicListComponent implements OnInit {
if (target === 'new') { if (target === 'new') {
this.newMusicImagePreview.set(base64); this.newMusicImagePreview.set(base64);
this.newMusic.coverArt = base64; this.newMusic.coverArt = base64;
} else { } else if (target === 'edit') {
this.editMusicImagePreview.set(base64); this.editMusicImagePreview.set(base64);
this.editMusicData.coverArt = base64; this.editMusicData.coverArt = base64;
} else {
this.suggestMusicImagePreview.set(base64);
this.suggestedMusic.coverArt = base64;
} }
}; };
reader.readAsDataURL(file); reader.readAsDataURL(file);
} }
clearImage(target: 'new' | 'edit') { clearImage(target: 'new' | 'edit' | 'suggest') {
if (target === 'new') { if (target === 'new') {
this.newMusicImagePreview.set(null); this.newMusicImagePreview.set(null);
this.newMusic.coverArt = undefined; this.newMusic.coverArt = undefined;
} else { } else if (target === 'edit') {
this.editMusicImagePreview.set(null); this.editMusicImagePreview.set(null);
this.editMusicData.coverArt = undefined; this.editMusicData.coverArt = undefined;
} else {
this.suggestMusicImagePreview.set(null);
this.suggestedMusic.coverArt = undefined;
} }
this.imageError.set(null); this.imageError.set(null);
} }
@@ -1268,4 +1378,43 @@ export class MusicListComponent implements OnInit {
} }
}); });
} }
// Suggestion methods
toggleSuggestForm() {
this.showSuggestForm.update(v => !v);
if (!this.showSuggestForm()) {
this.resetSuggestForm();
}
}
resetSuggestForm() {
this.suggestedMusic = {
title: '',
artist: '',
type: MusicType.album,
notes: '',
coverArt: undefined
};
this.suggestMusicImagePreview.set(null);
this.imageError.set(null);
}
async submitSuggestion() {
if (!this.suggestedMusic.title || !this.suggestedMusic.artist) return;
try {
await this.suggestionService.createSuggestion({
entityType: SuggestionEntity.MUSIC,
title: this.suggestedMusic.title,
artist: this.suggestedMusic.artist,
type: this.suggestedMusic.type,
notes: this.suggestedMusic.notes,
coverArt: this.suggestedMusic.coverArt
});
alert('Thank you for your suggestion! It will be reviewed soon.');
this.toggleSuggestForm();
} catch {
alert('Failed to submit suggestion. Please try again.');
}
}
} }
@@ -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();
}
}
@@ -11,7 +11,8 @@ import { ShowsService } from '../../services/shows.service';
import { AuthService } from '../../services/auth.service'; import { AuthService } from '../../services/auth.service';
import { CommentsService } from '../../services/comments.service'; import { CommentsService } from '../../services/comments.service';
import { SanitizeService } from '../../services/sanitize.service'; import { SanitizeService } from '../../services/sanitize.service';
import { Show, ShowStatus, ShowType, CreateShowDto, UpdateShowDto, Comment } from '@library/shared-types'; import { SuggestionService } from '../../services/suggestion.service';
import { Show, ShowStatus, ShowType, CreateShowDto, UpdateShowDto, Comment, SuggestionEntity } from '@library/shared-types';
@Component({ @Component({
selector: 'app-shows-list', selector: 'app-shows-list',
@@ -25,6 +26,10 @@ import { Show, ShowStatus, ShowType, CreateShowDto, UpdateShowDto, Comment } fro
<button (click)="toggleAddForm()" class="btn btn-primary"> <button (click)="toggleAddForm()" class="btn btn-primary">
{{ showAddForm() ? 'Cancel' : 'Add Show' }} {{ showAddForm() ? 'Cancel' : 'Add Show' }}
</button> </button>
} @else if (authService.isAuthenticated() && !authService.user()?.isBanned) {
<button (click)="toggleSuggestForm()" class="btn btn-primary">
{{ showSuggestForm() ? 'Cancel' : 'Suggest a Show' }}
</button>
} }
</div> </div>
@@ -196,6 +201,70 @@ import { Show, ShowStatus, ShowType, CreateShowDto, UpdateShowDto, Comment } fro
</form> </form>
} }
@if (showSuggestForm() && !authService.isAdmin() && authService.isAuthenticated()) {
<form (ngSubmit)="submitSuggestion()" class="add-form suggest-form">
<h3>Suggest a Show</h3>
<p class="suggest-note">Your suggestion will be reviewed by Naomi. If accepted, it will be added to the watch list!</p>
<div class="form-group">
<label for="suggest-title">Title</label>
<input
type="text"
id="suggest-title"
[(ngModel)]="suggestedShow.title"
name="title"
required
placeholder="Enter show title"
>
</div>
<div class="form-group">
<label for="suggest-type">Type</label>
<select id="suggest-type" [(ngModel)]="suggestedShow.type" name="type" required>
<option [value]="ShowType.tvSeries">TV Series</option>
<option [value]="ShowType.anime">Anime</option>
<option [value]="ShowType.film">Film</option>
<option [value]="ShowType.documentary">Documentary</option>
</select>
</div>
<div class="form-group">
<label for="suggest-notes">Notes (why should Naomi watch this?)</label>
<textarea
id="suggest-notes"
[(ngModel)]="suggestedShow.notes"
name="notes"
rows="3"
placeholder="Tell Naomi why this show is worth watching..."
></textarea>
</div>
<div class="form-group">
<label for="suggest-coverImage">Poster/Cover Art (max 500KB)</label>
<input
type="file"
id="suggest-coverImage"
name="coverImage"
accept="image/*"
(change)="onImageSelected($event, 'suggest')"
>
@if (suggestShowImagePreview()) {
<div class="image-preview">
<img [src]="suggestShowImagePreview()" alt="Cover preview">
<button type="button" (click)="clearImage('suggest')" class="btn btn-danger btn-sm">Remove</button>
</div>
}
@if (imageError()) {
<span class="error-text">{{ imageError() }}</span>
}
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">Submit Suggestion</button>
<button type="button" (click)="toggleSuggestForm()" class="btn btn-secondary">Cancel</button>
</div>
</form>
}
<div class="filters"> <div class="filters">
<button <button
(click)="setFilter('all')" (click)="setFilter('all')"
@@ -381,6 +450,18 @@ import { Show, ShowStatus, ShowType, CreateShowDto, UpdateShowDto, Comment } fro
margin-bottom: 2rem; margin-bottom: 2rem;
} }
.suggest-form {
border: 2px solid #e84393;
background: #fff5f9;
}
.suggest-note {
color: #666;
font-size: 0.9rem;
margin-bottom: 1rem;
font-style: italic;
}
.form-group { .form-group {
margin-bottom: 1rem; margin-bottom: 1rem;
} }
@@ -720,6 +801,7 @@ export class ShowsListComponent implements OnInit {
authService = inject(AuthService); authService = inject(AuthService);
commentsService = inject(CommentsService); commentsService = inject(CommentsService);
sanitizeService = inject(SanitizeService); sanitizeService = inject(SanitizeService);
suggestionService = inject(SuggestionService);
shows = signal<Show[]>([]); shows = signal<Show[]>([]);
loading = signal(true); loading = signal(true);
@@ -736,9 +818,19 @@ export class ShowsListComponent implements OnInit {
newShowImagePreview = signal<string | null>(null); newShowImagePreview = signal<string | null>(null);
editShowImagePreview = signal<string | null>(null); editShowImagePreview = signal<string | null>(null);
suggestShowImagePreview = signal<string | null>(null);
imageError = signal<string | null>(null); imageError = signal<string | null>(null);
private readonly MAX_IMAGE_SIZE = 500 * 1024; private readonly MAX_IMAGE_SIZE = 500 * 1024;
// Suggestion state
showSuggestForm = signal(false);
suggestedShow: { title: string; type: ShowType; notes?: string; coverImage?: string } = {
title: '',
type: ShowType.tvSeries,
notes: '',
coverImage: undefined
};
ShowStatus = ShowStatus; ShowStatus = ShowStatus;
ShowType = ShowType; ShowType = ShowType;
@@ -880,7 +972,7 @@ export class ShowsListComponent implements OnInit {
}); });
} }
onImageSelected(event: Event, target: 'new' | 'edit') { onImageSelected(event: Event, target: 'new' | 'edit' | 'suggest') {
const input = event.target as HTMLInputElement; const input = event.target as HTMLInputElement;
const file = input.files?.[0]; const file = input.files?.[0];
@@ -906,21 +998,27 @@ export class ShowsListComponent implements OnInit {
if (target === 'new') { if (target === 'new') {
this.newShowImagePreview.set(base64); this.newShowImagePreview.set(base64);
this.newShow.coverImage = base64; this.newShow.coverImage = base64;
} else { } else if (target === 'edit') {
this.editShowImagePreview.set(base64); this.editShowImagePreview.set(base64);
this.editShow.coverImage = base64; this.editShow.coverImage = base64;
} else {
this.suggestShowImagePreview.set(base64);
this.suggestedShow.coverImage = base64;
} }
}; };
reader.readAsDataURL(file); reader.readAsDataURL(file);
} }
clearImage(target: 'new' | 'edit') { clearImage(target: 'new' | 'edit' | 'suggest') {
if (target === 'new') { if (target === 'new') {
this.newShowImagePreview.set(null); this.newShowImagePreview.set(null);
this.newShow.coverImage = undefined; this.newShow.coverImage = undefined;
} else { } else if (target === 'edit') {
this.editShowImagePreview.set(null); this.editShowImagePreview.set(null);
this.editShow.coverImage = undefined; this.editShow.coverImage = undefined;
} else {
this.suggestShowImagePreview.set(null);
this.suggestedShow.coverImage = undefined;
} }
this.imageError.set(null); this.imageError.set(null);
} }
@@ -1038,4 +1136,41 @@ export class ShowsListComponent implements OnInit {
} }
}); });
} }
// Suggestion methods
toggleSuggestForm() {
this.showSuggestForm.update(v => !v);
if (!this.showSuggestForm()) {
this.resetSuggestForm();
}
}
resetSuggestForm() {
this.suggestedShow = {
title: '',
type: ShowType.tvSeries,
notes: '',
coverImage: undefined
};
this.suggestShowImagePreview.set(null);
this.imageError.set(null);
}
async submitSuggestion() {
if (!this.suggestedShow.title) return;
try {
await this.suggestionService.createSuggestion({
entityType: SuggestionEntity.SHOW,
title: this.suggestedShow.title,
type: this.suggestedShow.type,
notes: this.suggestedShow.notes,
coverImage: this.suggestedShow.coverImage
});
alert('Thank you for your suggestion! It will be reviewed soon.');
this.toggleSuggestForm();
} catch {
alert('Failed to submit suggestion. Please try again.');
}
}
} }
@@ -0,0 +1,55 @@
import { Injectable, inject } from "@angular/core";
import { firstValueFrom } from "rxjs";
import type {
Suggestion,
SuggestionStatus,
SuggestionEntity,
CreateSuggestionDto,
DeclineSuggestionDto,
} from "@library/shared-types";
import { ApiService } from "./api.service";
@Injectable({
providedIn: "root",
})
export class SuggestionService {
private api = inject(ApiService);
async getAllSuggestions(filters?: {
status?: SuggestionStatus;
entityType?: SuggestionEntity;
}): Promise<Suggestion[]> {
const params = new URLSearchParams();
if (filters?.status) {
params.set("status", filters.status);
}
if (filters?.entityType) {
params.set("entityType", filters.entityType);
}
const queryString = params.toString();
const url = queryString ? `/suggestions?${queryString}` : "/suggestions";
return firstValueFrom(this.api.get<Suggestion[]>(url));
}
async getMySuggestions(): Promise<Suggestion[]> {
return firstValueFrom(this.api.get<Suggestion[]>("/suggestions/my"));
}
async getSuggestionById(id: string): Promise<Suggestion> {
return firstValueFrom(this.api.get<Suggestion>(`/suggestions/${id}`));
}
async createSuggestion(data: CreateSuggestionDto): Promise<Suggestion> {
return firstValueFrom(this.api.post<Suggestion>("/suggestions", data));
}
async acceptSuggestion(id: string): Promise<Suggestion> {
return firstValueFrom(this.api.put<Suggestion>(`/suggestions/${id}/accept`, {}));
}
async declineSuggestion(id: string, data: DeclineSuggestionDto): Promise<Suggestion> {
return firstValueFrom(this.api.put<Suggestion>(`/suggestions/${id}/decline`, data));
}
}
+1
View File
@@ -12,3 +12,4 @@ export * from "./lib/manga.types";
export type * from "./lib/auth.types"; export type * from "./lib/auth.types";
export * from "./lib/comment.types"; export * from "./lib/comment.types";
export * from "./lib/audit.types"; export * from "./lib/audit.types";
export * from "./lib/suggestion.types";
+1 -1
View File
@@ -8,7 +8,7 @@ export interface User {
id: string; id: string;
email: string; email: string;
username: string; username: string;
avatarUrl?: string; avatar?: string;
discordId: string; discordId: string;
isAdmin: boolean; isAdmin: boolean;
isBanned: boolean; isBanned: boolean;
+111
View File
@@ -0,0 +1,111 @@
import type { CreateGameDto } from "./game.types";
import type { CreateBookDto } from "./book.types";
import type { CreateMusicDto } from "./music.types";
import type { CreateArtDto } from "./art.types";
import type { CreateShowDto } from "./show.types";
import type { CreateMangaDto } from "./manga.types";
export enum SuggestionEntity {
GAME = "GAME",
BOOK = "BOOK",
MUSIC = "MUSIC",
ART = "ART",
SHOW = "SHOW",
MANGA = "MANGA",
}
export enum SuggestionStatus {
UNREVIEWED = "UNREVIEWED",
ACCEPTED = "ACCEPTED",
DECLINED = "DECLINED",
}
export interface SuggestionUser {
id: string;
username: string;
avatar?: string;
inDiscord: boolean;
isVip: boolean;
isMod: boolean;
isStaff: boolean;
}
export interface Suggestion {
id: string;
userId: string;
user: SuggestionUser;
entityType: SuggestionEntity;
status: SuggestionStatus;
declineReason?: string;
title: string;
gameData?: Omit<CreateGameDto, "rating">;
bookData?: Omit<CreateBookDto, "rating">;
musicData?: Omit<CreateMusicDto, "rating">;
artData?: CreateArtDto;
showData?: Omit<CreateShowDto, "rating">;
mangaData?: Omit<CreateMangaDto, "rating">;
createdAt: Date;
updatedAt: Date;
}
export interface CreateGameSuggestionDto {
entityType: SuggestionEntity.GAME;
title: string;
platform?: string;
notes?: string;
coverImage?: string;
}
export interface CreateBookSuggestionDto {
entityType: SuggestionEntity.BOOK;
title: string;
author: string;
isbn?: string;
notes?: string;
coverImage?: string;
}
export interface CreateMusicSuggestionDto {
entityType: SuggestionEntity.MUSIC;
title: string;
artist: string;
type: string;
notes?: string;
coverArt?: string;
}
export interface CreateArtSuggestionDto {
entityType: SuggestionEntity.ART;
title: string;
artist: string;
description?: string;
imageUrl: string;
}
export interface CreateShowSuggestionDto {
entityType: SuggestionEntity.SHOW;
title: string;
type: string;
notes?: string;
coverImage?: string;
}
export interface CreateMangaSuggestionDto {
entityType: SuggestionEntity.MANGA;
title: string;
author: string;
notes?: string;
coverImage?: string;
}
export type CreateSuggestionDto =
| CreateGameSuggestionDto
| CreateBookSuggestionDto
| CreateMusicSuggestionDto
| CreateArtSuggestionDto
| CreateShowSuggestionDto
| CreateMangaSuggestionDto;
export interface DeclineSuggestionDto {
reason?: string;
}