import { useState } from 'react'; import { __ } from '@wordpress/i18n'; import { toast } from 'sonner'; import { Switch } from '../ui/switch'; import { Input } from '../ui/input'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '../ui/select'; import ProAlert from '../ui/pro-alert'; import { PluginSettings, savePluginSettings } from '../../api'; import Card from '../ui/card'; interface GeneralProps { settings: PluginSettings | null; onSave?: () => void; } export default function General({ settings, onSave }: GeneralProps) { const [saving, setSaving] = useState(false); const [imageEditorAlertOpen, setImageEditorAlertOpen] = useState(false); const [replaceImagesAlertOpen, setReplaceImagesAlertOpen] = useState(false); const [rightClickDisabled, setRightClickDisabled] = useState( settings?.right_click_disable ?? false, ); const [lazyLoad, setLazyLoad] = useState(settings?.lazy_load ?? false); const [hotlinkProtection, setHotlinkProtection] = useState( settings?.hotlink_protection ?? false, ); const [imageEditor, setImageEditor] = useState( settings?.image_editor ?? false, ); const [replaceImages, setReplaceImages] = useState( settings?.replace_images ?? false, ); const [maxSize, setMaxSize] = useState(settings?.max_size ?? ''); const [sizeUnit, setSizeUnit] = useState(settings?.max_size_unit ?? 'KB'); const [maxWidth, setMaxWidth] = useState(settings?.max_width ?? ''); const [maxHeight, setMaxHeight] = useState(settings?.max_height ?? ''); const [autoSetFeaturedImage, setAutoSetFeaturedImage] = useState( settings?.auto_set_featured_image ?? false, ); const isProActive = window.THUMBPRESS?.pro_active; const handleSave = async () => { setSaving(true); try { await savePluginSettings({ right_click_disable: rightClickDisabled, lazy_load: lazyLoad, hotlink_protection: hotlinkProtection, image_editor: imageEditor, replace_images: replaceImages, max_size: maxSize, max_size_unit: sizeUnit, max_width: maxWidth, max_height: maxHeight, auto_set_featured_image: autoSetFeaturedImage, }); toast.success(__( 'Settings saved successfully.', 'image-sizes' )); onSave?.(); } catch { toast.error(__( 'Failed to save settings.', 'image-sizes' )); } finally { setSaving(false); } }; const handleReset = () => { setRightClickDisabled(false); setLazyLoad(false); setHotlinkProtection(false); setImageEditor(false); setReplaceImages(false); setMaxSize(''); setSizeUnit('KB'); setMaxWidth(''); setMaxHeight(''); setAutoSetFeaturedImage(false); toast.success(__( 'Settings reset successfully.', 'image-sizes' )); }; return (
Enhance images with filters and adjustments to showcase their best versions.
Upload new versions of images and replace the old ones without any issues.
Prevent visitors from downloading your images by turning off the right-click option on your website.
Set a limit for maximum image upload size.
Set a limit for maximum image upload dimensions (in pixels).
{__( 'Load images only when they enter the user\'s viewport, improving page speed and reducing bandwidth usage.', 'image-sizes' )}
{__( 'Block other websites from embedding your images directly, preventing bandwidth theft from external hotlinking.', 'image-sizes' )}
{__( 'Automatically use the first image in post content as the featured image if none is set.', 'image-sizes' )}