1
0
mirror of https://github.com/mifi/lossless-cut.git synced 2024-11-22 10:22:31 +01:00

improve tag editor

This commit is contained in:
Mikael Finstad 2024-05-03 23:58:46 +02:00
parent 9ea438052f
commit 3ec3384760
No known key found for this signature in database
GPG Key ID: 25AB36E3E81CBC26

View File

@ -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
<td style={{ display: 'flex', alignItems: 'center' }}>
{editingThis ? (
<form style={{ display: 'inline' }} onSubmit={onSubmit}>
<TextInput ref={ref} placeholder={t('Enter value')} value={editingTagVal || ''} onChange={(e) => setEditingTagVal(e.target.value)} />
<TextInput ref={ref} placeholder={t('Enter value')} value={editingTagVal || ''} onChange={(e) => setEditingTagVal(e.target.value)} style={{ textTransform: editingTag === 'language' ? 'lowercase' : undefined }} />
</form>
) : (
<span style={{ padding: '.5em 0', color: thisTagCustom ? activeColor : undefined, fontWeight: thisTagCustom ? 'bold' : undefined }}>{mergedTags[tag] ? String(mergedTags[tag]) : `<${t('empty')}>`}</span>