import { IRoomSession, RoomPreviewer } from '@nitrots/nitro-renderer'; import { FC, useEffect, useState } from 'react'; import { IBotItem, LocalizeText, UnseenItemCategory, attemptBotPlacement } from '../../../../api'; import { LayoutRoomPreviewerView } from '../../../../common'; import { useInventoryBots, useInventoryUnseenTracker } from '../../../../hooks'; import { InfiniteGrid, NitroButton } from '../../../../layout'; import { InventoryCategoryEmptyView } from '../InventoryCategoryEmptyView'; import { InventoryBotItemView } from './InventoryBotItemView'; export const InventoryBotView: FC<{ roomSession: IRoomSession; roomPreviewer: RoomPreviewer; }> = props => { const { roomSession = null, roomPreviewer = null } = props; const [ isVisible, setIsVisible ] = useState(false); const { botItems = [], selectedBot = null, activate = null, deactivate = null } = useInventoryBots(); const { isUnseen = null, removeUnseen = null } = useInventoryUnseenTracker(); useEffect(() => { if(!selectedBot || !roomPreviewer) return; const botData = selectedBot.botData; roomPreviewer.reset(false); roomPreviewer.updateRoomWallsAndFloorVisibility(true, true); roomPreviewer.updateObjectRoom('111', '217', '1.1'); roomPreviewer.addAvatarIntoRoom(botData.figure, 0); }, [ roomPreviewer, selectedBot ]); useEffect(() => { if(!selectedBot || !isUnseen(UnseenItemCategory.BOT, selectedBot.botData.id)) return; removeUnseen(UnseenItemCategory.BOT, selectedBot.botData.id); }, [ selectedBot, isUnseen, removeUnseen ]); useEffect(() => { if(!isVisible) return; const id = activate(); return () => deactivate(id); }, [ isVisible, activate, deactivate ]); useEffect(() => { setIsVisible(true); return () => setIsVisible(false); }, []); if(!botItems || !botItems.length) return ; return (
columnCount={ 4 } estimateSize={ 110 } itemRender={ item => } items={ botItems } rowGap={ 4 } />
{ selectedBot &&
{ selectedBot.botData.name } { !!roomSession && attemptBotPlacement(selectedBot) }> { LocalizeText('inventory.furni.placetoroom') } }
}
); };