feat: add tags and links

This commit is contained in:
2026-02-04 19:49:27 -08:00
parent 9902c5ad45
commit b9f33bc055
21 changed files with 1873 additions and 31 deletions
@@ -12,7 +12,7 @@ import { AuthService } from '../../services/auth.service';
import { CommentsService } from '../../services/comments.service';
import { SanitizeService } from '../../services/sanitize.service';
import { SuggestionService } from '../../services/suggestion.service';
import { Game, GameStatus, CreateGameDto, UpdateGameDto, Comment, SuggestionEntity } from '@library/shared-types';
import { Game, GameStatus, CreateGameDto, UpdateGameDto, Comment, SuggestionEntity, Link } from '@library/shared-types';
@Component({
selector: 'app-games-list',
@@ -111,6 +111,52 @@ import { Game, GameStatus, CreateGameDto, UpdateGameDto, Comment, SuggestionEnti
}
</div>
<div class="form-group">
<label>Tags</label>
<div class="tags-input-container">
@for (tag of newGame.tags; track tag; let i = $index) {
<span class="tag">
{{ tag }}
<button type="button" (click)="removeTag(i, 'new')" class="tag-remove">×</button>
</span>
}
<input
type="text"
[(ngModel)]="newTagInput"
name="newTagInput"
placeholder="Add a tag and press Enter"
(keydown.enter)="addTag('new'); $event.preventDefault()"
>
</div>
</div>
<div class="form-group">
<label>External Links</label>
<div class="links-list">
@for (link of newGame.links; track link.url; let i = $index) {
<div class="link-item">
<span>{{ link.title }}: {{ link.url }}</span>
<button type="button" (click)="removeLink(i, 'new')" class="btn btn-danger btn-sm">×</button>
</div>
}
</div>
<div class="link-add-form">
<input
type="text"
[(ngModel)]="newLinkTitle"
name="newLinkTitle"
placeholder="Link title (e.g., Steam)"
>
<input
type="url"
[(ngModel)]="newLinkUrl"
name="newLinkUrl"
placeholder="https://..."
>
<button type="button" (click)="addLink('new')" class="btn btn-secondary btn-sm">Add Link</button>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">Add Game</button>
<button type="button" (click)="toggleAddForm()" class="btn btn-secondary">Cancel</button>
@@ -196,6 +242,52 @@ import { Game, GameStatus, CreateGameDto, UpdateGameDto, Comment, SuggestionEnti
}
</div>
<div class="form-group">
<label>Tags</label>
<div class="tags-input-container">
@for (tag of editGame.tags; track tag; let i = $index) {
<span class="tag">
{{ tag }}
<button type="button" (click)="removeTag(i, 'edit')" class="tag-remove">×</button>
</span>
}
<input
type="text"
[(ngModel)]="editTagInput"
name="editTagInput"
placeholder="Add a tag and press Enter"
(keydown.enter)="addTag('edit'); $event.preventDefault()"
>
</div>
</div>
<div class="form-group">
<label>External Links</label>
<div class="links-list">
@for (link of editGame.links; track link.url; let i = $index) {
<div class="link-item">
<span>{{ link.title }}: {{ link.url }}</span>
<button type="button" (click)="removeLink(i, 'edit')" class="btn btn-danger btn-sm">×</button>
</div>
}
</div>
<div class="link-add-form">
<input
type="text"
[(ngModel)]="editLinkTitle"
name="editLinkTitle"
placeholder="Link title (e.g., Steam)"
>
<input
type="url"
[(ngModel)]="editLinkUrl"
name="editLinkUrl"
placeholder="https://..."
>
<button type="button" (click)="addLink('edit')" class="btn btn-secondary btn-sm">Add Link</button>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">Save Changes</button>
<button type="button" (click)="cancelEdit()" class="btn btn-secondary">Cancel</button>
@@ -334,6 +426,24 @@ import { Game, GameStatus, CreateGameDto, UpdateGameDto, Comment, SuggestionEnti
<p class="notes">{{ game.notes }}</p>
}
@if (game.tags && game.tags.length > 0) {
<div class="tags-display">
@for (tag of game.tags; track tag) {
<span class="tag-chip">{{ tag }}</span>
}
</div>
}
@if (game.links && game.links.length > 0) {
<div class="links-display">
@for (link of game.links; track link.url) {
<a [href]="link.url" target="_blank" rel="noopener noreferrer" class="external-link">
{{ link.title }} ↗
</a>
}
</div>
}
@if (authService.isAdmin()) {
<div class="actions">
<button (click)="startEdit(game)" class="btn btn-secondary btn-sm">
@@ -747,6 +857,112 @@ import { Game, GameStatus, CreateGameDto, UpdateGameDto, Comment, SuggestionEnti
font-size: 0.9rem;
}
/* Tags and Links Styling */
.tags-input-container {
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
align-items: center;
padding: 0.5rem;
border: 1px solid #ccc;
border-radius: 4px;
background: white;
}
.tags-input-container input {
border: none;
outline: none;
flex: 1;
min-width: 150px;
padding: 0.25rem;
}
.tag {
display: inline-flex;
align-items: center;
gap: 0.25rem;
background: #ff6b6b;
color: white;
padding: 0.25rem 0.5rem;
border-radius: 12px;
font-size: 0.85rem;
}
.tag-remove {
background: none;
border: none;
color: white;
cursor: pointer;
font-size: 1rem;
line-height: 1;
padding: 0;
margin-left: 0.25rem;
}
.tag-remove:hover {
color: #fecaca;
}
.tags-display {
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
margin: 0.5rem 0;
}
.tag-chip {
background: #ff6b6b;
color: white;
padding: 0.25rem 0.75rem;
border-radius: 12px;
font-size: 0.8rem;
}
.links-list {
margin-bottom: 0.5rem;
}
.link-item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 0.25rem 0;
border-bottom: 1px solid #eee;
}
.link-add-form {
display: flex;
gap: 0.5rem;
flex-wrap: wrap;
}
.link-add-form input {
flex: 1;
min-width: 120px;
}
.links-display {
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
margin: 0.5rem 0;
}
.external-link {
color: #ff6b6b;
text-decoration: none;
font-size: 0.85rem;
padding: 0.25rem 0.5rem;
border: 1px solid #ff6b6b;
border-radius: 4px;
transition: all 0.2s;
}
.external-link:hover {
background: #ff6b6b;
color: white;
}
.comment-edit-form {
margin-top: 0.5rem;
}
@@ -858,11 +1074,21 @@ export class GamesListComponent implements OnInit {
platform: '',
status: GameStatus.backlog,
rating: undefined,
notes: ''
notes: '',
tags: [],
links: []
};
editGame: Partial<UpdateGameDto> = {};
// Tags and links input state
newTagInput = '';
editTagInput = '';
newLinkTitle = '';
newLinkUrl = '';
editLinkTitle = '';
editLinkUrl = '';
ngOnInit() {
this.loadGames();
}
@@ -906,10 +1132,60 @@ export class GamesListComponent implements OnInit {
status: GameStatus.backlog,
rating: undefined,
notes: '',
coverImage: undefined
coverImage: undefined,
tags: [],
links: []
};
this.newGameImagePreview.set(null);
this.imageError.set(null);
this.newTagInput = '';
this.newLinkTitle = '';
this.newLinkUrl = '';
}
addTag(target: 'new' | 'edit') {
const input = target === 'new' ? this.newTagInput.trim() : this.editTagInput.trim();
if (!input) return;
if (target === 'new') {
this.newGame.tags = [...(this.newGame.tags || []), input];
this.newTagInput = '';
} else {
this.editGame.tags = [...(this.editGame.tags || []), input];
this.editTagInput = '';
}
}
removeTag(index: number, target: 'new' | 'edit') {
if (target === 'new') {
this.newGame.tags = (this.newGame.tags || []).filter((_, i) => i !== index);
} else {
this.editGame.tags = (this.editGame.tags || []).filter((_, i) => i !== index);
}
}
addLink(target: 'new' | 'edit') {
const title = target === 'new' ? this.newLinkTitle.trim() : this.editLinkTitle.trim();
const url = target === 'new' ? this.newLinkUrl.trim() : this.editLinkUrl.trim();
if (!title || !url) return;
if (target === 'new') {
this.newGame.links = [...(this.newGame.links || []), { title, url }];
this.newLinkTitle = '';
this.newLinkUrl = '';
} else {
this.editGame.links = [...(this.editGame.links || []), { title, url }];
this.editLinkTitle = '';
this.editLinkUrl = '';
}
}
removeLink(index: number, target: 'new' | 'edit') {
if (target === 'new') {
this.newGame.links = (this.newGame.links || []).filter((_, i) => i !== index);
} else {
this.editGame.links = (this.editGame.links || []).filter((_, i) => i !== index);
}
}
addGame() {
@@ -921,7 +1197,9 @@ export class GamesListComponent implements OnInit {
status: this.newGame.status,
rating: this.newGame.rating,
notes: this.newGame.notes,
coverImage: this.newGame.coverImage
coverImage: this.newGame.coverImage,
tags: this.newGame.tags || [],
links: this.newGame.links || []
};
this.gamesService.createGame(gameToAdd).subscribe(() => {
@@ -946,11 +1224,16 @@ export class GamesListComponent implements OnInit {
status: game.status,
rating: game.rating,
notes: game.notes,
coverImage: game.coverImage
coverImage: game.coverImage,
tags: [...(game.tags || [])],
links: [...(game.links || [])]
};
this.editGameImagePreview.set(game.coverImage || null);
this.showAddForm.set(false);
this.imageError.set(null);
this.editTagInput = '';
this.editLinkTitle = '';
this.editLinkUrl = '';
}
cancelEdit() {
@@ -958,6 +1241,9 @@ export class GamesListComponent implements OnInit {
this.editGame = {};
this.editGameImagePreview.set(null);
this.imageError.set(null);
this.editTagInput = '';
this.editLinkTitle = '';
this.editLinkUrl = '';
}
saveEdit() {