refactor(frontend): rename booklore-ui to frontend

- Frontend path:
  - rename the tracked Angular app tree from `booklore-ui/` to `frontend/`
  - preserve file contents during the move so this commit stays focused on the path change itself
- Frontend docs:
  - update the moved frontend README and contribution guide where they refer to the renamed folder
  - keep those edits limited to path references introduced by the directory rename
This commit is contained in:
James Cox
2026-04-22 17:26:39 -04:00
committed by Zach Yale
parent c99aa87877
commit 874b013f75
1493 changed files with 3 additions and 3 deletions
@@ -0,0 +1,249 @@
<div class="icon-picker">
<header class="dialog-header">
<div class="header-content">
<div class="header-icon">
<i class="pi pi-palette"></i>
</div>
<div class="header-text">
<h1>Choose an Icon</h1>
<p>Select from library or add custom SVGs</p>
</div>
</div>
<p-button
icon="pi pi-times"
[text]="true"
[rounded]="true"
severity="secondary"
(onClick)="ref.close()"
/>
</header>
<div class="dialog-body">
<p-tabs [(value)]="activeTabIndex">
<p-tablist>
<p-tab value="0">
<i class="pi pi-prime"></i>
<span>Prime Icons</span>
</p-tab>
<p-tab value="1">
<i class="pi pi-images"></i>
<span>SVG Library</span>
</p-tab>
@if (canManageIcons) {
<p-tab value="2">
<i class="pi pi-plus-circle"></i>
<span>Add Custom</span>
</p-tab>
}
</p-tablist>
<p-tabpanels>
<!-- Prime Icons Tab -->
<p-tabpanel value="0">
<div class="tab-content">
<div class="search-container">
<i class="pi pi-search search-icon"></i>
<input
type="text"
pInputText
placeholder="Search Prime icons..."
[(ngModel)]="searchText"
class="search-input"
/>
</div>
<div class="icon-grid">
@for (icon of filteredIcons(); track icon) {
<div
class="icon-item"
(click)="selectIcon(icon)"
[class.selected]="icon === selectedIcon"
[title]="icon"
>
<i [class]="icon"></i>
</div>
}
</div>
</div>
</p-tabpanel>
<!-- SVG Library Tab -->
<p-tabpanel value="1">
<div class="tab-content">
@if (isLoadingSvgIcons) {
<div class="loading-state">
<i class="pi pi-spin pi-spinner"></i>
<span>Loading icons...</span>
</div>
} @else if (svgIconsError) {
<div class="error-state">
<i class="pi pi-exclamation-triangle"></i>
<span>{{ svgIconsError }}</span>
</div>
} @else {
<div class="search-container">
<i class="pi pi-search search-icon"></i>
<input
type="text"
pInputText
placeholder="Search SVG icons..."
[(ngModel)]="svgSearchText"
class="search-input"
/>
</div>
<div class="icon-grid">
@for (iconName of filteredSvgIcons(); track iconName) {
<div
class="icon-item svg-icon-item"
(click)="selectSvgIcon(iconName)"
[class.selected]="iconName === selectedSvgIcon"
[title]="iconName"
draggable="true"
(dragstart)="onSvgIconDragStart(iconName)"
(dragend)="onSvgIconDragEnd()"
>
<div class="svg-icon-inline" [innerHTML]="getSvgContent(iconName)"></div>
</div>
}
</div>
@if (canManageIcons) {
<div class="trash-zone-container">
<div
class="trash-zone"
[class.active]="isTrashHover"
(dragover)="onTrashDragOver($event)"
(dragleave)="onTrashDragLeave($event)"
(drop)="onTrashDrop($event)"
>
<i class="pi pi-trash"></i>
<span>Drop here to delete</span>
</div>
</div>
}
}
</div>
</p-tabpanel>
<!-- Add Custom SVG Tab -->
@if (canManageIcons) {
<p-tabpanel value="2">
<div class="tab-content">
<section class="form-section">
<div class="section-header">
<i class="pi pi-code"></i>
<span>SVG Input</span>
</div>
<div class="form-fields">
<div class="form-field">
<label>Icon Name</label>
<input
type="text"
pInputText
[(ngModel)]="svgName"
placeholder="e.g., my-custom-icon"
class="input-full"
/>
</div>
<div class="form-field">
<label>SVG Code</label>
<textarea
pInputTextarea
[(ngModel)]="svgContent"
(ngModelChange)="onSvgContentChange()"
placeholder="<svg>...</svg>"
[rows]="6"
class="code-textarea"
></textarea>
</div>
@if (svgContent && svgPreview) {
<div class="preview-card">
<div class="preview-label">Preview</div>
<div class="preview-content" [innerHTML]="svgPreview"></div>
</div>
}
@if (errorMessage) {
<div class="error-message">
<i class="pi pi-exclamation-circle"></i>
<span>{{ errorMessage }}</span>
</div>
}
</div>
<div class="form-actions">
<p-button
label="Add to Queue"
icon="pi pi-plus"
[outlined]="true"
[disabled]="!svgContent || !svgName"
(onClick)="addSvgEntry()"
/>
</div>
</section>
@if (svgEntries.length > 0) {
<section class="form-section queue-section">
<div class="section-header">
<i class="pi pi-list"></i>
<span>Queue</span>
<span class="section-badge">{{ svgEntries.length }}</span>
<div class="section-actions">
<p-button
label="Clear All"
icon="pi pi-times"
severity="danger"
[text]="true"
size="small"
(onClick)="clearAllEntries()"
/>
</div>
</div>
<div class="queue-grid">
@for (entry of svgEntries; track entry.name; let i = $index) {
<div class="queue-item" [class.has-error]="entry.error">
<div class="queue-item-header">
<span class="queue-item-name">{{ entry.name }}</span>
<button class="queue-item-remove" (click)="removeSvgEntry(i)" type="button">
<i class="pi pi-times"></i>
</button>
</div>
<div class="queue-item-preview" [innerHTML]="entry.preview"></div>
@if (entry.error) {
<div class="queue-item-error">{{ entry.error }}</div>
}
</div>
}
</div>
@if (batchErrorMessage) {
<div class="error-message">
<i class="pi pi-exclamation-circle"></i>
<span>{{ batchErrorMessage }}</span>
</div>
}
<div class="form-actions">
<p-button
label="Save All Icons"
icon="pi pi-save"
severity="success"
[loading]="isSavingBatch"
[disabled]="svgEntries.length === 0"
(onClick)="saveAllSvgs()"
/>
</div>
</section>
}
</div>
</p-tabpanel>
}
</p-tabpanels>
</p-tabs>
</div>
</div>
@@ -0,0 +1,550 @@
.icon-picker {
display: flex;
flex-direction: column;
height: 80dvh;
background: var(--card-background);
border: 1px solid var(--border-color);
border-radius: 12px;
overflow: hidden;
}
// Header
.dialog-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 1.25rem 1.5rem;
background: var(--overlay-background);
border-bottom: 1px solid var(--border-color);
flex-shrink: 0;
.header-content {
display: flex;
align-items: center;
gap: 0.875rem;
}
.header-icon {
display: flex;
align-items: center;
justify-content: center;
width: 42px;
height: 42px;
background: var(--primary-color);
border-radius: 10px;
i {
font-size: 1.25rem;
color: var(--primary-contrast-color);
}
}
.header-text {
h1 {
margin: 0;
font-size: 1.25rem;
font-weight: 600;
color: var(--text-color);
}
p {
margin: 0.125rem 0 0;
font-size: 0.875rem;
color: var(--text-secondary-color);
}
}
}
// Body
.dialog-body {
flex: 1;
overflow: hidden;
display: flex;
flex-direction: column;
min-height: 0;
::ng-deep {
.p-tabs {
display: flex;
flex-direction: column;
height: 100%;
}
.p-tablist {
background: var(--overlay-background);
border-bottom: 1px solid var(--border-color);
padding: 0 1rem;
}
.p-tab {
display: flex;
align-items: center;
gap: 0.5rem;
padding: 0.875rem 1rem;
font-size: 0.875rem;
font-weight: 500;
i {
font-size: 0.9rem;
}
}
.p-tabpanels {
flex: 1;
overflow: hidden;
min-height: 0;
}
.p-tabpanel {
height: 100%;
padding: 0;
}
}
}
// Tab content
.tab-content {
display: flex;
flex-direction: column;
height: 100%;
padding: 1.25rem 1.5rem;
overflow-y: auto;
gap: 1.25rem;
&::-webkit-scrollbar {
width: 6px;
}
&::-webkit-scrollbar-track {
background: transparent;
}
&::-webkit-scrollbar-thumb {
background: var(--border-color);
border-radius: 3px;
&:hover {
background: var(--primary-color);
}
}
}
// Search
.search-container {
position: relative;
flex-shrink: 0;
.search-icon {
position: absolute;
left: 0.875rem;
top: 50%;
transform: translateY(-50%);
font-size: 0.9rem;
color: var(--text-secondary-color);
pointer-events: none;
z-index: 1;
}
.search-input {
width: 100%;
padding: 0.75rem 1rem 0.75rem 2.5rem;
}
}
// Icon grid
.icon-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
gap: 0.5rem;
flex: 1;
align-content: start;
}
.icon-item {
display: flex;
align-items: center;
justify-content: center;
width: 44px;
height: 44px;
background: var(--ground-background);
border: 1px solid transparent;
border-radius: 8px;
cursor: pointer;
transition: all 0.15s ease;
> i {
font-size: 1.25rem;
color: var(--text-color);
transition: color 0.15s ease;
}
&:hover {
border-color: var(--border-color);
background: var(--overlay-background);
> i {
color: var(--primary-color);
}
}
&.selected {
border-color: var(--primary-color);
background: rgba(var(--primary-color-rgb, 59, 130, 246), 0.1);
> i {
color: var(--primary-color);
}
}
&.svg-icon-item {
.svg-icon-inline {
display: flex;
align-items: center;
justify-content: center;
width: 24px;
height: 24px;
::ng-deep svg {
width: 100%;
height: 100%;
}
}
}
}
// States
.loading-state,
.error-state {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 0.75rem;
padding: 3rem;
color: var(--text-secondary-color);
font-size: 0.9rem;
i {
font-size: 1.5rem;
}
}
.error-state {
color: var(--p-red-400);
}
// Trash zone
.trash-zone-container {
position: sticky;
bottom: 0;
padding-top: 1rem;
margin-top: auto;
}
.trash-zone {
display: flex;
align-items: center;
justify-content: center;
gap: 0.625rem;
padding: 0.875rem 1.25rem;
background: var(--ground-background);
border: 2px dashed var(--border-color);
border-radius: 8px;
color: var(--text-secondary-color);
font-size: 0.875rem;
transition: all 0.2s ease;
i {
font-size: 1rem;
color: var(--p-red-400);
}
&.active {
border-color: var(--p-red-400);
background: rgba(239, 68, 68, 0.08);
color: var(--p-red-400);
}
}
// Form sections
.form-section {
background: var(--ground-background);
border: 1px solid var(--border-color);
border-radius: 8px;
padding: 1.25rem;
.section-header {
display: flex;
align-items: center;
gap: 0.5rem;
margin-bottom: 1rem;
font-size: 0.85rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.03em;
color: var(--text-secondary-color);
> i {
font-size: 0.9rem;
color: var(--primary-color);
}
.section-badge {
display: flex;
align-items: center;
justify-content: center;
min-width: 20px;
height: 20px;
padding: 0 0.375rem;
background: var(--primary-color);
color: var(--primary-contrast-color);
border-radius: 10px;
font-size: 0.7rem;
font-weight: 600;
}
.section-actions {
margin-left: auto;
}
}
&.queue-section {
margin-top: 1rem;
}
}
// Form fields
.form-fields {
display: flex;
flex-direction: column;
gap: 1rem;
}
.form-field {
display: flex;
flex-direction: column;
gap: 0.5rem;
label {
font-size: 0.875rem;
font-weight: 500;
color: var(--text-color);
}
.input-full {
width: 100%;
padding: 0.75rem 1rem;
}
.code-textarea {
width: 100%;
padding: 0.75rem 1rem;
font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
font-size: 0.875rem;
resize: vertical;
line-height: 1.5;
}
}
// Preview
.preview-card {
background: var(--card-background);
border: 1px solid var(--border-color);
border-radius: 8px;
overflow: hidden;
.preview-label {
padding: 0.5rem 0.75rem;
font-size: 0.75rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.03em;
color: var(--text-secondary-color);
background: var(--overlay-background);
border-bottom: 1px solid var(--border-color);
}
.preview-content {
display: flex;
align-items: center;
justify-content: center;
padding: 1.5rem;
min-height: 120px;
::ng-deep svg {
max-width: 100%;
max-height: 100px;
width: auto;
height: auto;
}
}
}
// Error message
.error-message {
display: flex;
align-items: center;
gap: 0.5rem;
padding: 0.75rem 1rem;
background: rgba(239, 68, 68, 0.1);
border: 1px solid rgba(239, 68, 68, 0.2);
border-radius: 6px;
color: var(--p-red-400);
font-size: 0.875rem;
font-weight: 500;
i {
font-size: 0.9rem;
}
}
// Form actions
.form-actions {
display: flex;
justify-content: flex-end;
margin-top: 1rem;
padding-top: 1rem;
border-top: 1px solid var(--border-color);
}
// Queue grid
.queue-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
gap: 0.75rem;
max-height: 280px;
overflow-y: auto;
padding: 0.25rem;
&::-webkit-scrollbar {
width: 4px;
}
&::-webkit-scrollbar-thumb {
background: var(--border-color);
border-radius: 2px;
}
}
.queue-item {
background: var(--card-background);
border: 1px solid var(--border-color);
border-radius: 8px;
overflow: hidden;
transition: all 0.2s ease;
&:hover {
border-color: var(--primary-color);
}
&.has-error {
border-color: var(--p-red-400);
}
.queue-item-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 0.5rem 0.625rem;
background: var(--overlay-background);
border-bottom: 1px solid var(--border-color);
}
.queue-item-name {
font-size: 0.75rem;
font-weight: 600;
color: var(--text-color);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.queue-item-remove {
display: flex;
align-items: center;
justify-content: center;
width: 20px;
height: 20px;
background: transparent;
border: none;
border-radius: 4px;
color: var(--text-secondary-color);
cursor: pointer;
transition: all 0.15s ease;
&:hover {
background: rgba(239, 68, 68, 0.15);
color: var(--p-red-400);
}
i {
font-size: 0.625rem;
}
}
.queue-item-preview {
display: flex;
align-items: center;
justify-content: center;
padding: 0.75rem;
min-height: 60px;
::ng-deep svg {
max-width: 48px;
max-height: 48px;
width: auto;
height: auto;
}
}
.queue-item-error {
padding: 0.5rem 0.625rem;
font-size: 0.6875rem;
color: var(--p-red-400);
background: rgba(239, 68, 68, 0.08);
border-top: 1px solid rgba(239, 68, 68, 0.15);
}
}
// Responsive
@media (max-width: 520px) {
.icon-picker {
border-radius: 0;
height: 100dvh;
}
.dialog-header {
padding: 1rem;
.header-icon {
width: 36px;
height: 36px;
i {
font-size: 1rem;
}
}
.header-text h1 {
font-size: 1.125rem;
}
}
.tab-content {
padding: 1rem;
}
.icon-grid {
grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
gap: 0.375rem;
}
.icon-item {
width: 40px;
height: 40px;
}
.queue-grid {
grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
}
}
@@ -0,0 +1,396 @@
import {Component, inject, OnInit} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {DynamicDialogRef} from 'primeng/dynamicdialog';
import {IconService} from '../../services/icon.service';
import {IconCacheService} from '../../services/icon-cache.service';
import {DomSanitizer, SafeHtml} from '@angular/platform-browser';
import DOMPurify from 'dompurify';
import {UrlHelperService} from '../../service/url-helper.service';
import {MessageService} from 'primeng/api';
import {IconCategoriesHelper} from '../../helpers/icon-categories.helper';
import {Button} from 'primeng/button';
import {TabsModule} from 'primeng/tabs';
import {UserService} from '../../../features/settings/user-management/user.service';
import {from, of} from 'rxjs';
import {catchError, mergeMap, toArray} from 'rxjs/operators';
interface SvgEntry {
name: string;
content: string;
preview: SafeHtml | null;
error: string;
}
interface IconSaveResult {
iconName: string;
success: boolean;
errorMessage: string;
}
interface SvgIconBatchResponse {
totalRequested: number;
successCount: number;
failureCount: number;
results: IconSaveResult[];
}
@Component({
selector: 'app-icon-picker-component',
imports: [
FormsModule,
Button,
TabsModule
],
templateUrl: './icon-picker-component.html',
styleUrl: './icon-picker-component.scss'
})
export class IconPickerComponent implements OnInit {
private hasLoadedSvgIcons = false;
private readonly MAX_ICON_NAME_LENGTH = 255;
private readonly MAX_SVG_SIZE = 1048576; // 1MB
private readonly ICON_NAME_PATTERN = /^[a-zA-Z0-9_-]+$/;
private readonly ERROR_MESSAGES = {
NO_CONTENT: 'Please paste SVG content',
NO_NAME: 'Please provide a name for the icon',
INVALID_NAME: 'Icon name can only contain alphanumeric characters and hyphens',
NAME_TOO_LONG: `Icon name must not exceed ${this.MAX_ICON_NAME_LENGTH} characters`,
INVALID_SVG: 'Invalid SVG content. Please paste valid SVG code.',
MISSING_SVG_TAG: 'Content must include <svg> tag',
SVG_TOO_LARGE: 'SVG content must not exceed 1MB',
PARSE_ERROR: 'Failed to parse SVG content',
LOAD_ICONS_ERROR: 'Failed to load SVG icons. Please try again.',
DELETE_ERROR: 'Failed to delete icon. Please try again.'
};
ref = inject(DynamicDialogRef);
iconService = inject(IconService);
iconCache = inject(IconCacheService);
sanitizer = inject(DomSanitizer);
urlHelper = inject(UrlHelperService);
messageService = inject(MessageService);
userService = inject(UserService);
searchText: string = '';
selectedIcon: string | null = null;
icons: string[] = IconCategoriesHelper.createIconList();
private _activeTabIndex: string = '0';
get activeTabIndex(): string {
return this._activeTabIndex;
}
set activeTabIndex(value: string) {
this._activeTabIndex = value;
if (value === '1' && !this.hasLoadedSvgIcons && !this.isLoadingSvgIcons) {
this.loadSvgIcons();
}
}
svgContent: string = '';
svgName: string = '';
svgPreview: SafeHtml | null = null;
errorMessage: string = '';
svgEntries: SvgEntry[] = [];
isSavingBatch: boolean = false;
batchErrorMessage: string = '';
svgIcons: string[] = [];
svgSearchText: string = '';
isLoadingSvgIcons: boolean = false;
svgIconsError: string = '';
selectedSvgIcon: string | null = null;
draggedSvgIcon: string | null = null;
isTrashHover: boolean = false;
get canManageIcons(): boolean {
const user = this.userService.getCurrentUser();
return user?.permissions.canManageIcons || user?.permissions.admin || false;
}
ngOnInit(): void {
if (this.activeTabIndex === '1' && !this.hasLoadedSvgIcons && !this.isLoadingSvgIcons) {
this.loadSvgIcons();
}
}
filteredIcons(): string[] {
if (!this.searchText) return this.icons;
return this.icons.filter(icon => icon.toLowerCase().includes(this.searchText.toLowerCase()));
}
filteredSvgIcons(): string[] {
if (!this.svgSearchText) return this.svgIcons;
return this.svgIcons.filter(icon => icon.toLowerCase().includes(this.svgSearchText.toLowerCase()));
}
selectIcon(icon: string): void {
this.selectedIcon = icon;
this.ref.close({type: 'PRIME_NG', value: icon});
}
private loadSvgIcons(): void {
this.isLoadingSvgIcons = true;
this.svgIconsError = '';
this.iconService.getIconNames().subscribe({
next: (names) => {
this.hasLoadedSvgIcons = true;
if (names.length === 0) {
this.svgIcons = [];
this.isLoadingSvgIcons = false;
return;
}
from(names).pipe(
mergeMap(name =>
this.iconCache.getCachedSanitized(name)
? of(null)
: this.iconService.getSvgIconContent(name).pipe(catchError(() => of(null))),
5
),
toArray()
).subscribe(() => {
this.svgIcons = names;
this.isLoadingSvgIcons = false;
});
},
error: () => {
this.isLoadingSvgIcons = false;
this.hasLoadedSvgIcons = false;
this.svgIconsError = this.ERROR_MESSAGES.LOAD_ICONS_ERROR;
}
});
}
getSvgContent(iconName: string): SafeHtml | null {
return this.iconCache.getCachedSanitized(iconName) || null;
}
selectSvgIcon(iconName: string): void {
this.selectedSvgIcon = iconName;
this.ref.close({type: 'CUSTOM_SVG', value: iconName});
}
onSvgContentChange(): void {
this.errorMessage = '';
if (!this.svgContent.trim()) {
this.svgPreview = null;
return;
}
const trimmedContent = this.svgContent.trim();
if (!trimmedContent.includes('<svg')) {
this.svgPreview = null;
this.errorMessage = this.ERROR_MESSAGES.MISSING_SVG_TAG;
return;
}
try {
const sanitized = DOMPurify.sanitize(this.svgContent, {
USE_PROFILES: { svg: true },
FORBID_TAGS: ['script', 'style', 'foreignObject']
});
this.svgPreview = this.sanitizer.bypassSecurityTrustHtml(sanitized);
} catch {
this.svgPreview = null;
this.errorMessage = this.ERROR_MESSAGES.PARSE_ERROR;
}
}
addSvgEntry(): void {
const validationError = this.validateSvgInput();
if (validationError) {
this.errorMessage = validationError;
return;
}
const existingIndex = this.svgEntries.findIndex(entry => entry.name === this.svgName);
if (existingIndex !== -1) {
this.svgEntries[existingIndex] = {
name: this.svgName,
content: this.svgContent,
preview: this.svgPreview,
error: ''
};
} else {
this.svgEntries.push({
name: this.svgName,
content: this.svgContent,
preview: this.svgPreview,
error: ''
});
}
this.resetSvgForm();
this.errorMessage = '';
}
removeSvgEntry(index: number): void {
this.svgEntries.splice(index, 1);
}
clearAllEntries(): void {
this.svgEntries = [];
this.batchErrorMessage = '';
}
saveAllSvgs(): void {
if (this.svgEntries.length === 0) {
this.batchErrorMessage = 'No SVG icons to save';
return;
}
this.isSavingBatch = true;
this.batchErrorMessage = '';
this.svgEntries.forEach(entry => entry.error = '');
const svgData = this.svgEntries.map(entry => ({
svgName: entry.name,
svgData: entry.content
}));
this.iconService.saveBatchSvgIcons(svgData).subscribe({
next: (response: SvgIconBatchResponse) => {
this.isSavingBatch = false;
let successCount = 0;
let failureCount = 0;
response.results.forEach(result => {
if (result.success) {
successCount++;
} else {
failureCount++;
const entry = this.svgEntries.find(e => e.name === result.iconName);
if (entry) {
entry.error = result.errorMessage;
}
}
});
if (successCount > 0 && failureCount === 0) {
this.messageService.add({
severity: 'success',
summary: 'Icons Saved',
detail: `${successCount} SVG icon${successCount > 1 ? 's' : ''} saved successfully.`,
life: 2500
});
} else if (successCount > 0 && failureCount > 0) {
this.messageService.add({
severity: 'warn',
summary: 'Partial Success',
detail: `${successCount} SVG icon${successCount > 1 ? 's' : ''} saved, ${failureCount} failed.`,
life: 3500
});
} else if (failureCount > 0) {
this.messageService.add({
severity: 'error',
summary: 'Save Failed',
detail: `Failed to save ${failureCount} SVG icon${failureCount > 1 ? 's' : ''}.`,
life: 4000
});
}
this.clearAllEntries();
this.hasLoadedSvgIcons = false;
this.loadSvgIcons();
},
error: () => {
this.isSavingBatch = false;
this.batchErrorMessage = 'Failed to save SVG icons. Please try again.';
}
});
}
private deleteSvgIcon(iconName: string): void {
this.isLoadingSvgIcons = true;
this.iconService.deleteSvgIcon(iconName).subscribe({
next: () => {
this.messageService.add({
severity: 'success',
summary: 'Icon Deleted',
detail: 'SVG icon deleted successfully.',
life: 2500
});
this.svgIcons = this.svgIcons.filter(name => name !== iconName);
this.isLoadingSvgIcons = false;
},
error: (error) => {
this.isLoadingSvgIcons = false;
this.messageService.add({
severity: 'error',
summary: 'Delete Failed',
detail: error.error?.message || this.ERROR_MESSAGES.DELETE_ERROR,
life: 4000
});
}
});
}
private validateSvgInput(): string | null {
if (!this.svgContent.trim()) {
return this.ERROR_MESSAGES.NO_CONTENT;
}
if (!this.svgName.trim()) {
return this.ERROR_MESSAGES.NO_NAME;
}
if (this.svgName.length > this.MAX_ICON_NAME_LENGTH) {
return this.ERROR_MESSAGES.NAME_TOO_LONG;
}
if (!this.ICON_NAME_PATTERN.test(this.svgName)) {
return this.ERROR_MESSAGES.INVALID_NAME;
}
const svgSize = new Blob([this.svgContent]).size;
if (svgSize > this.MAX_SVG_SIZE) {
return this.ERROR_MESSAGES.SVG_TOO_LARGE;
}
return null;
}
private resetSvgForm(): void {
this.svgContent = '';
this.svgName = '';
this.svgPreview = null;
this.errorMessage = '';
}
onSvgIconDragStart(iconName: string): void {
this.draggedSvgIcon = iconName;
}
onSvgIconDragEnd(): void {
this.draggedSvgIcon = null;
}
onTrashDragOver(event: DragEvent): void {
event.preventDefault();
this.isTrashHover = true;
}
onTrashDragLeave(event: DragEvent): void {
event.preventDefault();
this.isTrashHover = false;
}
onTrashDrop(event: DragEvent): void {
event.preventDefault();
this.isTrashHover = false;
if (this.draggedSvgIcon) {
this.deleteSvgIcon(this.draggedSvgIcon);
this.draggedSvgIcon = null;
}
}
}