mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-16 21:50:35 +02:00
re-add visualizer preset update functionality
This commit is contained in:
+64
-2
@@ -390,6 +390,7 @@ const PresetSettings = () => {
|
|||||||
const { setSettings } = useSettingsStoreActions();
|
const { setSettings } = useSettingsStoreActions();
|
||||||
const [selectedPreset, setSelectedPreset] = useState<null | string>(null);
|
const [selectedPreset, setSelectedPreset] = useState<null | string>(null);
|
||||||
const [isSaving, setIsSaving] = useState(false);
|
const [isSaving, setIsSaving] = useState(false);
|
||||||
|
const [isRenaming, setIsRenaming] = useState(false);
|
||||||
const [newPresetName, setNewPresetName] = useState('');
|
const [newPresetName, setNewPresetName] = useState('');
|
||||||
const [isPasting, setIsPasting] = useState(false);
|
const [isPasting, setIsPasting] = useState(false);
|
||||||
const [pasteValue, setPasteValue] = useState('');
|
const [pasteValue, setPasteValue] = useState('');
|
||||||
@@ -584,12 +585,33 @@ const PresetSettings = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleUpdatePreset = () => {
|
const handleUpdatePreset = () => {
|
||||||
if (!selectedPreset) return;
|
if (!selectedPreset || !newPresetName.trim()) return;
|
||||||
|
|
||||||
|
let trimmedName = newPresetName.trim();
|
||||||
|
const isRenaming = trimmedName !== selectedPreset;
|
||||||
|
|
||||||
|
if (isRenaming) {
|
||||||
|
const existingNames = visualizer.audiomotionanalyzer.presets
|
||||||
|
.filter((p) => p.name !== selectedPreset)
|
||||||
|
.map((p) => p.name);
|
||||||
|
|
||||||
|
if (existingNames.includes(trimmedName)) {
|
||||||
|
const pattern = /^(.+?)(\s+\((\d+)\))?$/;
|
||||||
|
const match = trimmedName.match(pattern);
|
||||||
|
const baseName = match ? match[1] : trimmedName;
|
||||||
|
let counter = 1;
|
||||||
|
while (existingNames.includes(`${baseName} (${counter})`)) {
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
trimmedName = `${baseName} (${counter})`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const updatedPresets = visualizer.audiomotionanalyzer.presets.map((p) =>
|
const updatedPresets = visualizer.audiomotionanalyzer.presets.map((p) =>
|
||||||
p.name === selectedPreset
|
p.name === selectedPreset
|
||||||
? {
|
? {
|
||||||
...p,
|
...p,
|
||||||
|
name: trimmedName,
|
||||||
value: getCurrentSettingsAsPresetValue(),
|
value: getCurrentSettingsAsPresetValue(),
|
||||||
}
|
}
|
||||||
: p,
|
: p,
|
||||||
@@ -604,6 +626,10 @@ const PresetSettings = () => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
setNewPresetName('');
|
||||||
|
setIsRenaming(false);
|
||||||
|
setSelectedPreset(trimmedName);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDeletePreset = () => {
|
const handleDeletePreset = () => {
|
||||||
@@ -792,6 +818,36 @@ const PresetSettings = () => {
|
|||||||
</Button>
|
</Button>
|
||||||
</Group>
|
</Group>
|
||||||
</Group>
|
</Group>
|
||||||
|
) : isRenaming ? (
|
||||||
|
<Group grow>
|
||||||
|
<TextInput
|
||||||
|
autoFocus
|
||||||
|
label={t('visualizer.presetName')}
|
||||||
|
onChange={(e) => setNewPresetName(e.currentTarget.value)}
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === 'Enter') {
|
||||||
|
handleUpdatePreset();
|
||||||
|
} else if (e.key === 'Escape') {
|
||||||
|
setIsRenaming(false);
|
||||||
|
setNewPresetName('');
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
placeholder={t('visualizer.presetNamePlaceholder')}
|
||||||
|
value={newPresetName}
|
||||||
|
/>
|
||||||
|
<Group style={{ alignSelf: 'flex-end' }}>
|
||||||
|
<Button onClick={() => setIsRenaming(false)} variant="subtle">
|
||||||
|
{t('common.cancel', { postProcess: 'titleCase' })}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
disabled={!newPresetName.trim()}
|
||||||
|
onClick={handleUpdatePreset}
|
||||||
|
variant="filled"
|
||||||
|
>
|
||||||
|
{t('common.save', { postProcess: 'titleCase' })}
|
||||||
|
</Button>
|
||||||
|
</Group>
|
||||||
|
</Group>
|
||||||
) : isPasting ? (
|
) : isPasting ? (
|
||||||
<Stack>
|
<Stack>
|
||||||
<Textarea
|
<Textarea
|
||||||
@@ -827,7 +883,13 @@ const PresetSettings = () => {
|
|||||||
</Button>
|
</Button>
|
||||||
{selectedPreset && (
|
{selectedPreset && (
|
||||||
<>
|
<>
|
||||||
<Button onClick={handleUpdatePreset} variant="default">
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
setNewPresetName(selectedPreset);
|
||||||
|
setIsRenaming(true);
|
||||||
|
}}
|
||||||
|
variant="default"
|
||||||
|
>
|
||||||
{t('visualizer.updatePreset')}
|
{t('visualizer.updatePreset')}
|
||||||
</Button>
|
</Button>
|
||||||
<Button onClick={handleDeletePreset} variant="subtle">
|
<Button onClick={handleDeletePreset} variant="subtle">
|
||||||
|
|||||||
Reference in New Issue
Block a user