2021-04-22 08:45:47 +02:00
|
|
|
import { RoomSessionEvent } from 'nitro-renderer';
|
2021-04-22 05:18:44 +02:00
|
|
|
import { FC, useCallback, useState } from 'react';
|
|
|
|
import { InventoryEvent } from '../../events';
|
|
|
|
import { DraggableWindow } from '../../hooks/draggable-window/DraggableWindow';
|
2021-04-22 08:45:47 +02:00
|
|
|
import { useRoomSessionManagerEvent } from '../../hooks/events/nitro/session/room-session-manager-event';
|
2021-04-22 05:18:44 +02:00
|
|
|
import { useUiEvent } from '../../hooks/events/ui/ui-event';
|
|
|
|
import { LocalizeText } from '../../utils/LocalizeText';
|
|
|
|
import { InventoryMessageHandler } from './InventoryMessageHandler';
|
|
|
|
import { InventoryViewProps } from './InventoryView.types';
|
|
|
|
|
|
|
|
export const InventoryView: FC<InventoryViewProps> = props =>
|
|
|
|
{
|
|
|
|
const [ isVisible, setIsVisible ] = useState(false);
|
|
|
|
|
|
|
|
const onInventoryEvent = useCallback((event: InventoryEvent) =>
|
|
|
|
{
|
|
|
|
switch(event.type)
|
|
|
|
{
|
|
|
|
case InventoryEvent.SHOW_INVENTORY:
|
|
|
|
setIsVisible(true);
|
|
|
|
return;
|
|
|
|
case InventoryEvent.TOGGLE_INVENTORY:
|
|
|
|
setIsVisible(value => !value);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
useUiEvent(InventoryEvent.SHOW_INVENTORY, onInventoryEvent);
|
|
|
|
useUiEvent(InventoryEvent.TOGGLE_INVENTORY, onInventoryEvent);
|
|
|
|
|
2021-04-22 08:45:47 +02:00
|
|
|
const onRoomSessionEvent = useCallback((event: RoomSessionEvent) =>
|
|
|
|
{
|
|
|
|
switch(event.type)
|
|
|
|
{
|
|
|
|
case RoomSessionEvent.CREATED:
|
|
|
|
//
|
|
|
|
return;
|
|
|
|
case RoomSessionEvent.ENDED:
|
|
|
|
setIsVisible(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
useRoomSessionManagerEvent(RoomSessionEvent.CREATED, onRoomSessionEvent);
|
|
|
|
useRoomSessionManagerEvent(RoomSessionEvent.ENDED, onRoomSessionEvent);
|
|
|
|
|
2021-04-22 05:18:44 +02:00
|
|
|
function hideInventory(): void
|
|
|
|
{
|
|
|
|
setIsVisible(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<InventoryMessageHandler />
|
|
|
|
{ isVisible && <DraggableWindow handle=".drag-handler">
|
|
|
|
<div className="nitro-inventory d-flex flex-column bg-primary border border-black shadow rounded">
|
|
|
|
<div className="drag-handler d-flex justify-content-between align-items-center px-3 pt-3">
|
|
|
|
<div className="h6 m-0">{ LocalizeText('inventory.title') }</div>
|
|
|
|
<button type="button" className="close" onClick={ hideInventory }>
|
|
|
|
<i className="fas fa-times"></i>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div className="d-flex p-3">
|
|
|
|
content
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</DraggableWindow> }
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|