diff --git a/src/renderer/src/components/TagEditor.tsx b/src/renderer/src/components/TagEditor.tsx index 5bb4dc63..a7ef931a 100644 --- a/src/renderer/src/components/TagEditor.tsx +++ b/src/renderer/src/components/TagEditor.tsx @@ -44,19 +44,21 @@ function TagEditor({ existingTags = emptyObject, customTags = emptyObject, editi } }, [onTagsChange]); + const saveTag = useCallback(() => { + invariant(editingTag != null); + invariant(editingTagVal != null); + const editingValTransformed = editingTag === 'language' ? editingTagVal.toLowerCase() : editingTagVal; + onTagsChange({ [editingTag]: editingValTransformed }); + setEditingTag(undefined); + }, [editingTag, editingTagVal, onTagsChange, setEditingTag]); + const onEditClick = useCallback((tag?: string) => { if (newTag) { - invariant(editingTag != null); - invariant(editingTagVal != null); - onTagsChange({ [editingTag]: editingTagVal }); - setEditingTag(undefined); + saveTag(); setNewTag(undefined); } else if (editingTag != null) { if (editingTagVal !== existingTags[editingTag]) { - invariant(editingTag != null); - invariant(editingTagVal != null); - onTagsChange({ [editingTag]: editingTagVal }); - setEditingTag(undefined); + saveTag(); } else { // If not actually changed, no need to update onResetClick(); } @@ -64,7 +66,7 @@ function TagEditor({ existingTags = emptyObject, customTags = emptyObject, editi setEditingTag(tag); setEditingTagVal(tag && String(mergedTags[tag])); } - }, [editingTag, editingTagVal, existingTags, mergedTags, newTag, onResetClick, onTagsChange, setEditingTag]); + }, [editingTag, editingTagVal, existingTags, mergedTags, newTag, onResetClick, saveTag, setEditingTag]); function onSubmit(e) { e.preventDefault(); @@ -108,7 +110,7 @@ function TagEditor({ existingTags = emptyObject, customTags = emptyObject, editi