import { FC, useCallback, useEffect, useState } from 'react'; import { Button, Column, Flex, Text } from '../../../common'; import { CatalogRef, FurniDetail } from '../../../hooks/furni-editor'; interface FurniEditorEditViewProps { item: FurniDetail; catalogItems: CatalogRef[]; furniDataEntry: Record | null; interactions: string[]; loading: boolean; onUpdate: (id: number, fields: Record) => Promise; onDelete: (id: number) => Promise; onBack: () => void; onRefresh: (id: number) => void; } export const FurniEditorEditView: FC = props => { const { item, catalogItems, furniDataEntry, interactions, loading, onUpdate, onDelete, onBack, onRefresh } = props; const [ form, setForm ] = useState({ itemName: '', publicName: '', spriteId: 0, 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); useEffect(() => { if(!item) return; setForm({ itemName: item.itemName || '', publicName: item.publicName || '', spriteId: item.spriteId || 0, 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 ]); const setField = useCallback((key: string, value: unknown) => { setForm(prev => ({ ...prev, [key]: value })); }, []); const handleSave = useCallback(async () => { const ok = await onUpdate(item.id, form); if(ok) onRefresh(item.id); }, [ item, form, onUpdate, onRefresh ]); const handleDelete = useCallback(async () => { if(!confirmDelete) return setConfirmDelete(true); const ok = await onDelete(item.id); if(ok) onBack(); }, [ confirmDelete, item, onDelete, onBack ]); const inputClass = 'form-control form-control-sm'; const labelClass = 'text-[11px] font-bold text-[#333] mb-0'; return ( { item.id } | { item.spriteId } ({ item.usageCount } in use) { /* Basic Info */ }
Basic Info
setField('itemName', e.target.value) } />
setField('publicName', e.target.value) } />
setField('spriteId', Number(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) } />
{ /* Catalog References */ } { catalogItems.length > 0 &&
Catalog ({ catalogItems.length })
{ catalogItems.map(ci => (
{ ci.catalogName } (page: { ci.pageName }) { ci.costCredits }c + { ci.costPoints }p
)) }
} { /* FurniData.json Entry */ } { furniDataEntry &&
FurniData.json
{ Object.entries(furniDataEntry).map(([ key, value ]) => (
{ key } { String(value ?? '') }
)) }
} { /* Actions */ }
); };