2023-06-01 08:45:43 +02:00
|
|
|
import * as React from 'react'
|
2023-06-13 02:43:52 +02:00
|
|
|
import type { Location } from '@lastres/location'
|
|
|
|
import type { PJ } from '@lastres/pj'
|
|
|
|
import type { LogLine } from '@lastres/log-line'
|
|
|
|
import PJListItem from '@lastres/components/pj-list-item'
|
2023-06-19 17:15:00 +02:00
|
|
|
import PresentationItem from '@lastres/components/presentation-item'
|
|
|
|
import Presentation from '@lastres/components/presentation'
|
|
|
|
import LogPanel from '@lastres/components/log-panel'
|
2023-06-18 20:29:42 +02:00
|
|
|
import MoveToPacket from '@lastres/output-packet/move-to'
|
2023-06-13 02:43:52 +02:00
|
|
|
|
|
|
|
interface UpperPanelProps {
|
|
|
|
connectedLocations: Location[] | null
|
|
|
|
teamPJs: PJ[] | null
|
|
|
|
currentLocation: Location | null
|
|
|
|
logLines: LogLine[] | null
|
2023-06-18 20:29:42 +02:00
|
|
|
websocket: WebSocket | null
|
2023-06-19 17:15:00 +02:00
|
|
|
logPresentationRef: React.RefObject<HTMLDivElement>
|
2023-06-13 02:43:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export default function UpperPanel (props: UpperPanelProps): JSX.Element {
|
|
|
|
const connectedLocations = props.connectedLocations
|
|
|
|
const teamPJs = props.teamPJs
|
|
|
|
const currentLocation = props.currentLocation
|
|
|
|
const logLines = props.logLines
|
2023-06-18 20:29:42 +02:00
|
|
|
const websocket = props.websocket
|
2023-06-19 17:15:00 +02:00
|
|
|
const logPresentationRef = props.logPresentationRef
|
2023-06-13 02:43:52 +02:00
|
|
|
if (!(teamPJs !== null && currentLocation !== null && connectedLocations !== null)) {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<p>Esperando datos...</p>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
2023-06-18 20:29:42 +02:00
|
|
|
|
|
|
|
function onClickLocation (item: Location): void {
|
|
|
|
const moveToPacket = new MoveToPacket(item)
|
|
|
|
if (websocket !== null) {
|
|
|
|
moveToPacket.send(websocket)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-01 08:45:43 +02:00
|
|
|
return (
|
2023-06-19 17:15:00 +02:00
|
|
|
<Presentation>
|
|
|
|
<PresentationItem>
|
2023-06-13 02:43:52 +02:00
|
|
|
{
|
|
|
|
teamPJs.map((item, i) => {
|
|
|
|
return <PJListItem key={i} pj={item}/>
|
|
|
|
})
|
|
|
|
}
|
2023-06-19 17:15:00 +02:00
|
|
|
</PresentationItem>
|
|
|
|
<PresentationItem presentationItemRef={logPresentationRef}>
|
|
|
|
<LogPanel logLines={logLines}/>
|
|
|
|
</PresentationItem>
|
|
|
|
<PresentationItem>
|
2023-06-13 02:43:52 +02:00
|
|
|
<p>Estás en {currentLocation.area.name}/{currentLocation.location.name}.</p>
|
|
|
|
<p>Puedes ir a:</p>
|
|
|
|
<ul>
|
|
|
|
{
|
|
|
|
connectedLocations.map((item, i) => {
|
|
|
|
return <li key={i}>
|
2023-06-18 20:29:42 +02:00
|
|
|
<a href="#" onClick={() => {
|
|
|
|
onClickLocation(item)
|
|
|
|
}}>{item.area.name}/{item.location.name}</a>
|
2023-06-13 02:43:52 +02:00
|
|
|
</li>
|
|
|
|
})
|
|
|
|
}
|
|
|
|
</ul>
|
2023-06-19 17:15:00 +02:00
|
|
|
</PresentationItem>
|
|
|
|
</Presentation>
|
2023-06-01 08:45:43 +02:00
|
|
|
)
|
|
|
|
}
|