import { FC, useCallback, useEffect, useState } from 'react'; import { FaSave, FaSync, FaTrash, FaArrowLeft } from 'react-icons/fa'; import { Column } from '../../../common'; import { LayoutFurniIconImageView } from '../../../common/layout/LayoutFurniIconImageView'; import { CatalogRef, FurniDetail } from '../../../hooks/furni-editor'; interface FurniEditorEditViewProps { item: FurniDetail; catalogItems: CatalogRef[]; furniDataEntry: Record | null; interactions: string[]; loading: boolean; lastResult: { success: boolean; message: string; id: number } | null; onUpdate: (id: number, fields: Record) => void; onDelete: (id: number) => void; onBack: () => void; onRefresh: (id: number) => void; } const ic = 'text-[13px] border border-[#c5cdd6] rounded px-2 py-1 bg-white focus:outline-none focus:border-[#1e7295] focus:shadow-[0_0_0_1px_rgba(30,114,149,0.15)] transition-all w-full'; const ro = 'text-[13px] border border-[#d5dbe0] rounded px-2 py-1 bg-[#f0f2f4] text-[#777] w-full cursor-not-allowed'; const lb = 'text-[11px] text-[#1e7295] uppercase font-bold tracking-wider leading-none'; const sectionTitle = 'text-[12px] text-[#1e7295] uppercase font-bold tracking-wider'; export const FurniEditorEditView: FC = props => { const { item, catalogItems, furniDataEntry, interactions, loading, lastResult, onUpdate, onDelete, onBack, onRefresh } = props; const [ form, setForm ] = useState({ publicName: '', type: 's', width: 1, length: 1, stackHeight: 0, allowStack: true, allowWalk: false, allowSit: false, allowLay: false, allowGift: true, allowTrade: true, allowRecycle: true, allowMarketplaceSell: true, allowInventoryStack: true, interactionType: '', interactionModesCount: 0, customparams: '', }); const [ confirmDelete, setConfirmDelete ] = useState(false); const [ toast, setToast ] = useState<{ type: 'success' | 'error'; message: string } | null>(null); useEffect(() => { if(!item) return; setForm({ publicName: item.publicName || '', type: item.type || 's', width: item.width || 1, length: item.length || 1, stackHeight: item.stackHeight || 0, allowStack: !!item.allowStack, allowWalk: !!item.allowWalk, allowSit: !!item.allowSit, allowLay: !!item.allowLay, allowGift: !!item.allowGift, allowTrade: !!item.allowTrade, allowRecycle: !!item.allowRecycle, allowMarketplaceSell: !!item.allowMarketplaceSell, allowInventoryStack: !!item.allowInventoryStack, interactionType: item.interactionType || '', interactionModesCount: item.interactionModesCount || 0, customparams: item.customparams || '', }); setConfirmDelete(false); }, [ item ]); useEffect(() => { if(!lastResult) return; setToast({ type: lastResult.success ? 'success' : 'error', message: lastResult.message }); if(lastResult.success && lastResult.id > 0) onRefresh(lastResult.id); const timer = setTimeout(() => setToast(null), 3000); return () => clearTimeout(timer); }, [ lastResult ]); const setField = useCallback((key: string, value: unknown) => { setForm(prev => ({ ...prev, [key]: value })); }, []); const handleSave = useCallback(() => { onUpdate(item.id, form); }, [ item, form, onUpdate ]); const handleDelete = useCallback(() => { if(!confirmDelete) return setConfirmDelete(true); onDelete(item.id); }, [ confirmDelete, item, onDelete ]); return ( { toast &&
{ toast.message }
} { /* Header */ }
{ item.publicName }
{ navigator.clipboard.writeText(String(item.id)); setToast({ type: 'success', message: `ID ${item.id} copied!` }); } }>#{item.id} | sprite:{ item.spriteId } | { item.itemName } { item.type === 's' ? 'FLOOR' : 'WALL' } { item.usageCount > 0 && { item.usageCount } in use }
{ /* Basic Info */ }
setField('publicName', e.target.value) } />
{ /* Dimensions */ }
Dimensions
setField('width', Number(e.target.value)) } />
setField('length', Number(e.target.value)) } />
setField('stackHeight', Number(e.target.value)) } />
{ /* Permissions */ }
Permissions
{ [ 'allowStack', 'allowWalk', 'allowSit', 'allowLay', 'allowGift', 'allowTrade', 'allowRecycle', 'allowMarketplaceSell', 'allowInventoryStack' ].map(key => ( )) }
{ /* Interaction */ }
Interaction
setField('interactionModesCount', Number(e.target.value)) } />
setField('customparams', e.target.value) } />
{ /* Actions */ }
); };