Skip to content

Commit a2c41bd

Browse files
committed
fix(frontend/components): improve tag handling logic in JobMetadataEditor
1 parent b9635fc commit a2c41bd

1 file changed

Lines changed: 27 additions & 3 deletions

File tree

frontend/components/JobMetadataEditor.tsx

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ export default function JobMetadataEditor({ job, onUpdate, compact = false }: Jo
2020
const tagInputRef = useRef<HTMLInputElement>(null);
2121
const notesInputRef = useRef<HTMLTextAreaElement>(null);
2222

23+
// Sync local state when job prop changes
24+
useEffect(() => {
25+
setTags(job.tags || []);
26+
setNotes(job.notes || '');
27+
}, [job.tags, job.notes]);
28+
2329
// Focus input when editing starts
2430
useEffect(() => {
2531
if (isEditingTags && tagInputRef.current) {
@@ -35,10 +41,28 @@ export default function JobMetadataEditor({ job, onUpdate, compact = false }: Jo
3541

3642
const handleAddTag = () => {
3743
const trimmedTag = newTag.trim().toLowerCase();
38-
if (trimmedTag && !tags.includes(trimmedTag) && tags.length < 10) {
39-
setTags([...tags, trimmedTag]);
40-
setNewTag('');
44+
if (trimmedTag.length === 0) {
45+
return;
46+
}
47+
48+
if (trimmedTag.length > 50) {
49+
setError('Tag must be 50 characters or less');
50+
return;
4151
}
52+
53+
if (tags.includes(trimmedTag)) {
54+
setError('Tag already exists');
55+
return;
56+
}
57+
58+
if (tags.length >= 10) {
59+
setError('Maximum 10 tags allowed');
60+
return;
61+
}
62+
63+
setError(null);
64+
setTags([...tags, trimmedTag]);
65+
setNewTag('');
4266
};
4367

4468
const handleRemoveTag = (tagToRemove: string) => {

0 commit comments

Comments
 (0)