@studyllm/resume-preview 0.0.0-stage → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,152 @@
1
+ /**
2
+ * Page Renderer
3
+ * Single Responsibility: Generic page rendering with template composition
4
+ * Open/Closed Principle: Easy to add new pages without modifying this code
5
+ */
6
+ import { readFile } from "fs/promises";
7
+ import { join } from "path";
8
+ import { fileURLToPath } from "url";
9
+ import { dirname } from "path";
10
+ import { ROUTES, DEFAULT_UI_LOCALE } from "./constants.js";
11
+ import { webLogger } from "./logger.js";
12
+ import { escapeHtml } from "./html-utils.js";
13
+ import { getDictionary, getHtmlLang, renderLanguageSwitcher, t } from "./i18n.js";
14
+ export { escapeHtml };
15
+ const __filename = fileURLToPath(import.meta.url);
16
+ const __dirname = dirname(__filename);
17
+ const PREVIEW_DIR = join(__dirname, "preview");
18
+ // Template cache for performance
19
+ const templateCache = new Map();
20
+ /**
21
+ * Loads a template file with caching
22
+ * @param filename Template filename
23
+ * @returns Template content
24
+ */
25
+ async function loadTemplate(filename) {
26
+ if (templateCache.has(filename)) {
27
+ return templateCache.get(filename);
28
+ }
29
+ const filePath = join(PREVIEW_DIR, filename);
30
+ const content = await readFile(filePath, "utf-8");
31
+ templateCache.set(filename, content);
32
+ webLogger.debug(`Loaded template: ${filename}`);
33
+ return content;
34
+ }
35
+ /**
36
+ * Replaces template variables with actual values
37
+ * @param template Template string
38
+ * @param data Data object with variable values
39
+ * @param escape Whether to HTML-escape values (default: true)
40
+ * @returns Processed template
41
+ */
42
+ function replaceVariables(template, data, escape = true) {
43
+ let result = template;
44
+ for (const [key, value] of Object.entries(data)) {
45
+ const placeholder = `{{${key}}}`;
46
+ const stringValue = String(value ?? "");
47
+ const processedValue = escape ? escapeHtml(stringValue) : stringValue;
48
+ result = result.replaceAll(placeholder, processedValue);
49
+ }
50
+ return result;
51
+ }
52
+ /**
53
+ * Replaces `{{i18n:some.key}}` placeholders with the translation of that key.
54
+ *
55
+ * Templates use this instead of a template variable per string, so adding a
56
+ * translated label does not mean touching the constants and the type of the
57
+ * page data.
58
+ */
59
+ function replaceI18nPlaceholders(template, dictionary) {
60
+ return template.replace(/\{\{i18n:([A-Za-z0-9_.]+)\}\}/g, (_match, key) => escapeHtml(t(dictionary, key)));
61
+ }
62
+ /**
63
+ * Generates navigation HTML
64
+ * @param port Server port for links
65
+ * @param dictionary Translations for the current locale
66
+ * @returns Navigation HTML
67
+ */
68
+ function generateNav(port, dictionary) {
69
+ const baseUrl = `http://localhost:${port}`;
70
+ return `
71
+ <nav class="nav">
72
+ <a href="${baseUrl}${ROUTES.GALLERY}" class="nav-link">${escapeHtml(t(dictionary, "gallery.navGallery"))}</a>
73
+ </nav>
74
+ `;
75
+ }
76
+ /**
77
+ * Generates footer HTML
78
+ * @param dictionary Translations for the current locale
79
+ * @returns Footer HTML
80
+ */
81
+ function generateFooter(dictionary) {
82
+ return `
83
+ <footer class="footer">
84
+ <p>${escapeHtml(t(dictionary, "gallery.footerText"))}</p>
85
+ </footer>
86
+ `;
87
+ }
88
+ /**
89
+ * Renders a complete page with layout
90
+ * @param contentTemplate Name of the content template file
91
+ * @param data Data for template variables
92
+ * @param options Rendering options
93
+ * @returns Complete HTML page
94
+ */
95
+ export async function renderPage(contentTemplate, data, options = {}) {
96
+ const { title, titleKey, styles = [], scripts = [], includeNav = true, includeFooter = false, locale = DEFAULT_UI_LOCALE, path = ROUTES.ROOT, } = options;
97
+ try {
98
+ const dictionary = await getDictionary(locale);
99
+ // Load content template
100
+ const contentHtml = await loadTemplate(contentTemplate);
101
+ // Generate style links
102
+ const styleLinks = styles.map((style) => `<link rel="stylesheet" href="${style}">`).join("\n");
103
+ // Generate script tags. The i18n module comes first — the other scripts
104
+ // wait for its dictionary before they render runtime strings.
105
+ const scriptTags = [
106
+ `<script src="${ROUTES.I18N_SCRIPT}"></script>`,
107
+ ...scripts.map((script) => `<script src="${script}"></script>`),
108
+ ].join("\n");
109
+ // Generate navigation if requested
110
+ const nav = includeNav && data.PORT ? generateNav(Number(data.PORT), dictionary) : "";
111
+ // Generate footer if requested
112
+ const footer = includeFooter ? generateFooter(dictionary) : "";
113
+ // Combine data with layout components
114
+ const pageData = {
115
+ ...data,
116
+ PAGE_TITLE: titleKey
117
+ ? t(dictionary, titleKey)
118
+ : (title ?? t(dictionary, "gallery.pageTitle")),
119
+ PAGE_STYLES: styleLinks,
120
+ PAGE_SCRIPTS: scriptTags,
121
+ NAV: nav,
122
+ FOOTER: footer,
123
+ LANG: getHtmlLang(dictionary, locale),
124
+ LANG_SWITCH: renderLanguageSwitcher(dictionary, locale, path),
125
+ };
126
+ // Replace variables in content template (content may include HTML, don't escape)
127
+ const processedContent = replaceI18nPlaceholders(replaceVariables(contentHtml, pageData, false), dictionary);
128
+ webLogger.debug(`Rendered page: ${contentTemplate}`, {
129
+ hasNav: includeNav,
130
+ hasFooter: includeFooter,
131
+ stylesCount: styles.length,
132
+ scriptsCount: scripts.length,
133
+ locale,
134
+ });
135
+ return processedContent;
136
+ }
137
+ catch (error) {
138
+ webLogger.error(`Failed to render page: ${contentTemplate}`, {
139
+ error: error instanceof Error ? error.message : String(error),
140
+ });
141
+ throw new Error(`Page rendering failed: ${error instanceof Error ? error.message : String(error)}`);
142
+ }
143
+ }
144
+ /**
145
+ * Clears the template cache
146
+ * Useful for development when templates are modified
147
+ */
148
+ export function clearTemplateCache() {
149
+ templateCache.clear();
150
+ webLogger.debug("Template cache cleared");
151
+ }
152
+ //# sourceMappingURL=page-renderer.js.map
@@ -0,0 +1,23 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64">
2
+ <defs>
3
+ <linearGradient id="g" x1="0" y1="0" x2="1" y2="1">
4
+ <stop offset="0%" stop-color="#ff3670"/>
5
+ <stop offset="100%" stop-color="#ff7c9c"/>
6
+ </linearGradient>
7
+ </defs>
8
+ <!-- The mark is an A4 page: outline, a name line, and two body lines. -->
9
+ <rect x="2" y="2" width="60" height="60" rx="14" fill="url(#g)"/>
10
+ <rect
11
+ x="18.4"
12
+ y="12.4"
13
+ width="27.2"
14
+ height="39.2"
15
+ rx="4"
16
+ fill="none"
17
+ stroke="#ffffff"
18
+ stroke-width="4.2"
19
+ />
20
+ <rect x="24.4" y="21.6" width="15.2" height="4.4" rx="2.2" fill="#ffffff"/>
21
+ <rect x="24.4" y="30.8" width="15.2" height="3.6" rx="1.8" fill="#ffffff" opacity="0.85"/>
22
+ <rect x="24.4" y="38.8" width="10" height="3.6" rx="1.8" fill="#ffffff" opacity="0.85"/>
23
+ </svg>
@@ -0,0 +1,217 @@
1
+ /**
2
+ * Gallery-specific styles
3
+ * Extends shared.css with gallery page components
4
+ */
5
+
6
+ body {
7
+ min-height: 100vh;
8
+ display: flex;
9
+ flex-direction: column;
10
+ }
11
+
12
+ /* ===== Gallery Header ===== */
13
+ .gallery-header {
14
+ margin-bottom: var(--spacing-lg);
15
+ }
16
+
17
+ .gallery-title {
18
+ margin: 0;
19
+ font-size: 32px;
20
+ font-weight: 700;
21
+ color: var(--text-primary);
22
+ }
23
+
24
+ .gallery-title-row {
25
+ display: flex;
26
+ align-items: center;
27
+ gap: var(--spacing-md);
28
+ flex-wrap: wrap;
29
+ }
30
+
31
+ .gallery-subtitle {
32
+ margin: var(--spacing-sm) 0 0 0;
33
+ font-size: 16px;
34
+ color: var(--text-secondary);
35
+ }
36
+
37
+ /* ===== Gallery Stats ===== */
38
+ .gallery-stats {
39
+ display: flex;
40
+ align-items: center;
41
+ justify-content: space-between;
42
+ padding: var(--spacing-sm) 0;
43
+ }
44
+
45
+ /* ===== Gallery Grid ===== */
46
+ .gallery-grid {
47
+ display: grid;
48
+ grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
49
+ gap: var(--spacing-lg);
50
+ margin-bottom: var(--spacing-xl);
51
+ }
52
+
53
+ /* ===== Resume Card ===== */
54
+ .resume-card {
55
+ background: var(--bg-card);
56
+ border: 1px solid var(--border-color);
57
+ border-radius: var(--border-radius-md);
58
+ overflow: hidden;
59
+ transition: all var(--transition-fast);
60
+ color: inherit;
61
+ display: flex;
62
+ flex-direction: column;
63
+ position: relative;
64
+ }
65
+
66
+ .resume-card:hover {
67
+ border-color: var(--border-color-hover);
68
+ transform: translateY(-4px);
69
+ box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
70
+ }
71
+
72
+ .resume-card-link {
73
+ text-decoration: none;
74
+ color: inherit;
75
+ display: flex;
76
+ flex-direction: column;
77
+ flex: 1;
78
+ cursor: pointer;
79
+ }
80
+
81
+ /* ===== Resume Actions ===== */
82
+ .resume-actions {
83
+ position: absolute;
84
+ top: var(--spacing-sm);
85
+ right: var(--spacing-sm);
86
+ display: flex;
87
+ gap: var(--spacing-xs);
88
+ z-index: 10;
89
+ opacity: 0;
90
+ transition: opacity var(--transition-fast);
91
+ }
92
+
93
+ .resume-card:hover .resume-actions {
94
+ opacity: 1;
95
+ }
96
+
97
+ .resume-action-btn {
98
+ background: rgba(0, 0, 0, 0.7);
99
+ border: none;
100
+ border-radius: var(--border-radius-sm);
101
+ width: 32px;
102
+ height: 32px;
103
+ display: flex;
104
+ align-items: center;
105
+ justify-content: center;
106
+ cursor: pointer;
107
+ font-size: 16px;
108
+ transition: all var(--transition-fast);
109
+ backdrop-filter: blur(4px);
110
+ }
111
+
112
+ .resume-action-btn:hover {
113
+ background: rgba(0, 0, 0, 0.9);
114
+ transform: scale(1.1);
115
+ }
116
+
117
+ .resume-action-btn:active {
118
+ transform: scale(0.95);
119
+ }
120
+
121
+ .delete-btn:hover {
122
+ background: rgba(220, 53, 69, 0.9);
123
+ }
124
+
125
+ /* ===== Resume Preview Placeholder ===== */
126
+ .resume-preview {
127
+ width: 100%;
128
+ height: 120px;
129
+ background: var(--bg-secondary);
130
+ display: flex;
131
+ align-items: center;
132
+ justify-content: center;
133
+ overflow: hidden;
134
+ position: relative;
135
+ border-bottom: 1px solid var(--border-color);
136
+ }
137
+
138
+ .resume-preview-icon {
139
+ color: var(--text-tertiary);
140
+ font-size: 48px;
141
+ opacity: 0.35;
142
+ }
143
+
144
+ .resume-info {
145
+ padding: var(--spacing-md);
146
+ flex: 1;
147
+ display: flex;
148
+ flex-direction: column;
149
+ }
150
+
151
+ .resume-id {
152
+ font-size: 16px;
153
+ font-weight: 600;
154
+ color: var(--text-primary);
155
+ margin: 0 0 var(--spacing-sm) 0;
156
+ word-break: break-word;
157
+ }
158
+
159
+ .resume-meta {
160
+ display: flex;
161
+ flex-wrap: wrap;
162
+ gap: var(--spacing-sm);
163
+ margin-top: auto;
164
+ }
165
+
166
+ .resume-meta-item {
167
+ display: flex;
168
+ align-items: center;
169
+ gap: 4px;
170
+ font-size: 12px;
171
+ color: var(--text-tertiary);
172
+ }
173
+
174
+ .resume-template {
175
+ text-transform: uppercase;
176
+ font-weight: 600;
177
+ color: var(--accent-color);
178
+ }
179
+
180
+ /* ===== Responsive Design ===== */
181
+ @media (max-width: 768px) {
182
+ .gallery-title {
183
+ font-size: 24px;
184
+ }
185
+
186
+ .gallery-subtitle {
187
+ font-size: 14px;
188
+ }
189
+
190
+ .gallery-grid {
191
+ grid-template-columns: 1fr;
192
+ gap: var(--spacing-md);
193
+ }
194
+
195
+ .container {
196
+ padding: var(--spacing-md);
197
+ }
198
+ }
199
+
200
+ @media (min-width: 769px) and (max-width: 1024px) {
201
+ .gallery-grid {
202
+ grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
203
+ }
204
+ }
205
+
206
+ /* ===== Touch device actions ===== */
207
+ @media (hover: none) {
208
+ .resume-actions {
209
+ opacity: 1;
210
+ }
211
+
212
+ .resume-action-btn {
213
+ width: 40px;
214
+ height: 40px;
215
+ font-size: 18px;
216
+ }
217
+ }
@@ -0,0 +1,59 @@
1
+ <!doctype html>
2
+ <html lang="{{LANG}}">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>{{PAGE_TITLE}}</title>
7
+ <link rel="icon" href="/favicon.svg" type="image/svg+xml" />
8
+ <link rel="stylesheet" href="/shared.css" />
9
+ <link rel="stylesheet" href="/gallery.css" />
10
+ </head>
11
+ <body>
12
+ {{NAV}}
13
+
14
+ <div class="container">
15
+ <header class="gallery-header">
16
+ <div class="gallery-title-row">
17
+ <h1 class="gallery-title">{{i18n:gallery.title}}</h1>
18
+ {{LANG_SWITCH}}
19
+ </div>
20
+ <p class="gallery-subtitle">{{i18n:gallery.subtitle}}</p>
21
+
22
+ <div class="search-bar mt-lg">
23
+ <span class="search-icon">🔍</span>
24
+ <input
25
+ type="text"
26
+ id="searchInput"
27
+ class="input search-input"
28
+ placeholder="{{i18n:gallery.searchPlaceholder}}"
29
+ autocomplete="off"
30
+ />
31
+ </div>
32
+ </header>
33
+
34
+ <div class="gallery-stats mt-md">
35
+ <span class="text-muted" id="resumeCount">{{i18n:gallery.loading}}</span>
36
+ </div>
37
+
38
+ <div id="gallery" class="gallery-grid mt-lg">
39
+ <div class="loading">
40
+ <div class="loading-spinner"></div>
41
+ </div>
42
+ </div>
43
+
44
+ <div id="emptyState" class="empty-state" style="display: none">
45
+ <div class="empty-state-icon">📄</div>
46
+ <h2 class="empty-state-title">{{i18n:gallery.emptyTitle}}</h2>
47
+ <p class="empty-state-description">{{i18n:gallery.emptyDesc}}</p>
48
+ </div>
49
+
50
+ <div id="noResults" class="empty-state" style="display: none">
51
+ <div class="empty-state-icon">🔍</div>
52
+ <h2 class="empty-state-title">{{i18n:gallery.noResultsTitle}}</h2>
53
+ <p class="empty-state-description">{{i18n:gallery.noResultsDesc}}</p>
54
+ </div>
55
+ </div>
56
+
57
+ {{FOOTER}} {{PAGE_SCRIPTS}}
58
+ </body>
59
+ </html>
@@ -0,0 +1,259 @@
1
+ /**
2
+ * Gallery Client-Side Logic
3
+ * Handles resume loading, search, and interaction
4
+ *
5
+ * Strings that are produced at runtime are looked up in the translation
6
+ * dictionary; the static labels are rendered by the server in the request
7
+ * language.
8
+ */
9
+
10
+ // State
11
+ let allResumes = [];
12
+ let filteredResumes = [];
13
+
14
+ // DOM Elements
15
+ const galleryEl = document.getElementById("gallery");
16
+ const emptyStateEl = document.getElementById("emptyState");
17
+ const noResultsEl = document.getElementById("noResults");
18
+ const searchInput = document.getElementById("searchInput");
19
+ const resumeCountEl = document.getElementById("resumeCount");
20
+
21
+ /**
22
+ * Looks up a translated string. Falls back to the key when the i18n module
23
+ * is unavailable, so a broken script shows a key instead of an empty page.
24
+ */
25
+ function t(key, vars) {
26
+ const i18n = window.RPI18n;
27
+ return i18n ? i18n.t(key, vars) : key;
28
+ }
29
+
30
+ /**
31
+ * Formats a date as relative time (e.g. "2 minutes ago"). The plural rules
32
+ * and the wording come from the browser's Intl implementation.
33
+ */
34
+ function formatRelativeTime(date) {
35
+ const i18n = window.RPI18n;
36
+ return i18n ? i18n.relativeTime(date) : new Date(date).toLocaleString();
37
+ }
38
+
39
+ /**
40
+ * Formats file size in human-readable format
41
+ */
42
+ function formatFileSize(bytes) {
43
+ if (bytes < 1024) return `${bytes} B`;
44
+ if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
45
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
46
+ }
47
+
48
+ /**
49
+ * Creates a resume card element
50
+ */
51
+ function createResumeCard(resume) {
52
+ const card = document.createElement("div");
53
+ card.className = "resume-card";
54
+ card.dataset.resumeId = resume.id;
55
+
56
+ // Action buttons
57
+ const actions = document.createElement("div");
58
+ actions.className = "resume-actions";
59
+
60
+ const deleteBtn = document.createElement("button");
61
+ deleteBtn.className = "resume-action-btn delete-btn";
62
+ deleteBtn.innerHTML = "🗑️";
63
+ deleteBtn.title = t("gallery.deleteTitle");
64
+ deleteBtn.onclick = (e) => {
65
+ e.preventDefault();
66
+ e.stopPropagation();
67
+ deleteResume(resume.id);
68
+ };
69
+
70
+ actions.appendChild(deleteBtn);
71
+
72
+ // Card link wrapper for the preview and the info
73
+ const cardLink = document.createElement("a");
74
+ cardLink.href = `/resume/view/${resume.id}`;
75
+ cardLink.className = "resume-card-link";
76
+
77
+ // Preview section — a resume has no thumbnail, so it shows a document mark
78
+ const preview = document.createElement("div");
79
+ preview.className = "resume-preview";
80
+ preview.innerHTML = '<div class="resume-preview-icon">📄</div>';
81
+
82
+ // Info section
83
+ const info = document.createElement("div");
84
+ info.className = "resume-info";
85
+
86
+ const id = document.createElement("h3");
87
+ id.className = "resume-id";
88
+ id.textContent = resume.id;
89
+
90
+ const meta = document.createElement("div");
91
+ meta.className = "resume-meta";
92
+
93
+ const template = document.createElement("span");
94
+ template.className = "resume-meta-item";
95
+ template.innerHTML = `<span class="resume-template">${resume.template}</span>`;
96
+
97
+ const modified = document.createElement("span");
98
+ modified.className = "resume-meta-item";
99
+ modified.innerHTML = `📅 ${formatRelativeTime(resume.modifiedAt)}`;
100
+
101
+ const size = document.createElement("span");
102
+ size.className = "resume-meta-item";
103
+ size.innerHTML = `💾 ${formatFileSize(resume.sizeBytes)}`;
104
+
105
+ meta.appendChild(template);
106
+ meta.appendChild(modified);
107
+ meta.appendChild(size);
108
+
109
+ info.appendChild(id);
110
+ info.appendChild(meta);
111
+
112
+ cardLink.appendChild(preview);
113
+ cardLink.appendChild(info);
114
+
115
+ card.appendChild(actions);
116
+ card.appendChild(cardLink);
117
+
118
+ return card;
119
+ }
120
+
121
+ /**
122
+ * Renders the gallery with the current filtered resumes
123
+ */
124
+ function renderGallery() {
125
+ // Clear gallery
126
+ galleryEl.innerHTML = "";
127
+
128
+ // Update count
129
+ const count = filteredResumes.length;
130
+ resumeCountEl.textContent =
131
+ count === 1 ? t("gallery.countOne", { n: count }) : t("gallery.count", { n: count });
132
+
133
+ // Show appropriate state
134
+ if (allResumes.length === 0) {
135
+ // No resumes at all
136
+ galleryEl.style.display = "none";
137
+ emptyStateEl.style.display = "block";
138
+ noResultsEl.style.display = "none";
139
+ } else if (filteredResumes.length === 0) {
140
+ // No results from search
141
+ galleryEl.style.display = "none";
142
+ emptyStateEl.style.display = "none";
143
+ noResultsEl.style.display = "block";
144
+ } else {
145
+ // Show resumes
146
+ galleryEl.style.display = "grid";
147
+ emptyStateEl.style.display = "none";
148
+ noResultsEl.style.display = "none";
149
+
150
+ filteredResumes.forEach((resume) => {
151
+ const card = createResumeCard(resume);
152
+ galleryEl.appendChild(card);
153
+ });
154
+ }
155
+ }
156
+
157
+ /**
158
+ * Filters resumes based on search query
159
+ */
160
+ function filterResumes(query) {
161
+ if (!query || !query.trim()) {
162
+ filteredResumes = [...allResumes];
163
+ } else {
164
+ const normalizedQuery = query.toLowerCase().trim();
165
+ filteredResumes = allResumes.filter((resume) =>
166
+ resume.id.toLowerCase().includes(normalizedQuery)
167
+ );
168
+ }
169
+ renderGallery();
170
+ }
171
+
172
+ /**
173
+ * Loads resumes from the API
174
+ */
175
+ async function loadResumes() {
176
+ try {
177
+ const response = await fetch("/api/resumes");
178
+
179
+ if (!response.ok) {
180
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
181
+ }
182
+
183
+ const data = await response.json();
184
+ allResumes = data.resumes || [];
185
+ filteredResumes = [...allResumes];
186
+
187
+ renderGallery();
188
+ } catch (error) {
189
+ console.error("Failed to load resumes:", error);
190
+ galleryEl.innerHTML = `
191
+ <div class="empty-state">
192
+ <div class="empty-state-icon">⚠️</div>
193
+ <h2 class="empty-state-title">${t("gallery.loadFailedTitle")}</h2>
194
+ <p class="empty-state-description">${error.message}</p>
195
+ </div>
196
+ `;
197
+ }
198
+ }
199
+
200
+ /**
201
+ * Deletes a resume
202
+ */
203
+ async function deleteResume(resumeId) {
204
+ if (!confirm(t("gallery.deleteConfirm", { id: resumeId }))) {
205
+ return;
206
+ }
207
+
208
+ try {
209
+ const response = await fetch(`/api/resumes/${resumeId}`, {
210
+ method: "DELETE",
211
+ });
212
+
213
+ if (!response.ok) {
214
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
215
+ }
216
+
217
+ // Remove from the list
218
+ const index = allResumes.findIndex((r) => r.id === resumeId);
219
+ if (index !== -1) {
220
+ allResumes.splice(index, 1);
221
+ }
222
+
223
+ // Re-filter and render
224
+ filterResumes(searchInput.value);
225
+ } catch (error) {
226
+ console.error("Failed to delete resume:", error);
227
+ alert(t("gallery.deleteFailed", { message: error.message }));
228
+ }
229
+ }
230
+
231
+ /**
232
+ * Debounce function for search input
233
+ */
234
+ function debounce(func, wait) {
235
+ let timeout;
236
+ return function executedFunction(...args) {
237
+ const later = () => {
238
+ clearTimeout(timeout);
239
+ func(...args);
240
+ };
241
+ clearTimeout(timeout);
242
+ timeout = setTimeout(later, wait);
243
+ };
244
+ }
245
+
246
+ // Event Listeners
247
+ searchInput.addEventListener(
248
+ "input",
249
+ debounce((e) => {
250
+ filterResumes(e.target.value);
251
+ }, 300)
252
+ );
253
+
254
+ // Initialize. The dictionary has to be in place before any runtime string
255
+ // is rendered.
256
+ const i18nReady = window.RPI18n ? window.RPI18n.ready : Promise.resolve();
257
+ i18nReady.then(() => {
258
+ loadResumes();
259
+ });