From b359e6445ccc6232eb6d3aa1cba9f03137984e8b Mon Sep 17 00:00:00 2001 From: PEDZEO Date: Wed, 21 Jan 2026 04:21:25 +0300 Subject: [PATCH] Improve admin settings UI components MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add EditIcon component to icons.tsx - Enhance SettingInput with textarea for long/JSON values - Improve SettingRow styling and long value handling - Fix CORE category translation (Ядро → Бот) - Add auto-resize for textarea and Ctrl+Enter save shortcut --- src/components/admin/FavoritesTab.tsx | 2 +- src/components/admin/SettingInput.tsx | 127 ++++++++++++++++++++--- src/components/admin/SettingRow.tsx | 140 +++++++++++++++++++------- src/components/admin/SettingsTab.tsx | 4 +- src/components/admin/icons.tsx | 6 ++ src/locales/ru.json | 2 +- 6 files changed, 226 insertions(+), 55 deletions(-) diff --git a/src/components/admin/FavoritesTab.tsx b/src/components/admin/FavoritesTab.tsx index c70709d..e3f34d8 100644 --- a/src/components/admin/FavoritesTab.tsx +++ b/src/components/admin/FavoritesTab.tsx @@ -41,7 +41,7 @@ export function FavoritesTab({ settings, isFavorite, toggleFavorite }: Favorites } return ( -
+
{settings.map((setting) => ( 50 || str.includes('\n') || str.startsWith('[') || str.startsWith('{') +} + +// Check if key suggests it's a list or JSON config +function isListOrJsonKey(key: string): boolean { + const lowerKey = key.toLowerCase() + return ( + lowerKey.includes('_items') || + lowerKey.includes('_config') || + lowerKey.includes('_keywords') || + lowerKey.includes('_list') || + lowerKey.includes('_json') || + lowerKey.includes('_template') || + lowerKey.includes('_periods') || + lowerKey.includes('_discounts') || + lowerKey.includes('_packages') + ) +} + export function SettingInput({ setting, onUpdate, disabled }: SettingInputProps) { const [isEditing, setIsEditing] = useState(false) const [value, setValue] = useState('') + const textareaRef = useRef(null) + const inputRef = useRef(null) + + const currentValue = String(setting.current ?? '') + const needsTextarea = isLongValue(currentValue) || isListOrJsonKey(setting.key) + + // Auto-resize textarea + useEffect(() => { + if (textareaRef.current && isEditing) { + textareaRef.current.style.height = 'auto' + textareaRef.current.style.height = Math.min(textareaRef.current.scrollHeight, 300) + 'px' + } + }, [value, isEditing]) const handleStart = () => { - setValue(String(setting.current ?? '')) + setValue(currentValue) setIsEditing(true) } @@ -31,10 +67,10 @@ export function SettingInput({ setting, onUpdate, disabled }: SettingInputProps) if (setting.choices && setting.choices.length > 0) { return (