LasTres/js-src/components/pj-selection-menu.tsx

48 lines
1.6 KiB
TypeScript
Raw Normal View History

2023-06-01 08:45:43 +02:00
import * as React from 'react'
import PJCreationMenu from '@lastres/components/pj-creation-menu'
2023-06-08 09:02:32 +02:00
import PJListSelection from '@lastres/components/pj-list-selection'
2023-06-22 21:54:28 +02:00
import { fetchMyPjs } from '@lastres/pj'
import type { PJ } from '@lastres/pj'
2023-06-01 08:45:43 +02:00
export interface PJSelectionMenuProps {
2023-06-08 09:02:32 +02:00
setSelectedPJ: (set: PJ | null) => void
2023-06-01 08:45:43 +02:00
setUserWantsToCreatePJ: (set: boolean) => void
userWantsToCreatePJ: boolean
error: string | null
setError: (set: string | null) => void
}
export default function PJSelectionMenu (props: PJSelectionMenuProps): JSX.Element {
2023-06-08 09:02:32 +02:00
const [pjs, setPJs] = React.useState<PJ[] | null>(null)
2023-06-01 08:45:43 +02:00
const createPJ = (): void => {
props.setUserWantsToCreatePJ(true)
}
if (props.userWantsToCreatePJ) {
return (
<PJCreationMenu
setSelectedPJ={props.setSelectedPJ}
setUserWantsToCreatePJ={props.setUserWantsToCreatePJ}
error={props.error}
2023-06-22 21:54:28 +02:00
setError={props.setError}
setPJs={setPJs}/>
2023-06-01 08:45:43 +02:00
)
}
2023-06-08 09:02:32 +02:00
if (pjs === null) {
fetchMyPjs(props.setError)
2023-06-22 21:54:28 +02:00
.then((pjs) => { setPJs(pjs) })
.catch((error) => { console.log(error) })
2023-06-08 09:02:32 +02:00
}
2023-06-01 08:45:43 +02:00
return (
<div className="pj-selection-menu">
<div className="pj-selection-menu-container">
<h1>L3TDE</h1>
<h2>Selecciona un Personaje</h2>
<div className="pj-list">
<a onClick={createPJ} href="#">Crear un nuevo personaje</a>
2023-06-08 09:02:32 +02:00
<PJListSelection setSelectedPJ={props.setSelectedPJ} pjs={pjs}/>
2023-06-01 08:45:43 +02:00
</div>
</div>
</div>
)
}