From bb5adb4b6de640cf47fbecbd374fb31f3199ecb5 Mon Sep 17 00:00:00 2001 From: Sanna Hautala Date: Sun, 25 Feb 2024 16:21:37 +0200 Subject: [PATCH] feat: add missing fleet and ship data, make fleet table scalable (#9) - Add missing fleet and ship data - Make fleet table scalable --- src/components/Fleet.js | 30 +++++++++++++++++------------- src/components/Ship.css | 4 ++++ src/components/Ship.js | 25 +++++++++++++++++++++---- 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/src/components/Fleet.js b/src/components/Fleet.js index 77a013c..de6e51c 100644 --- a/src/components/Fleet.js +++ b/src/components/Fleet.js @@ -17,7 +17,7 @@ const getFleet = async () => { export default function Fleet() { const [fleet, setFleet] = React.useState([]); const [page, setPage] = React.useState(1); - const [sizePerPage, setSizePerPage] = React.useState(10); + const [sizePerPage, setSizePerPage] = React.useState(15); React.useEffect(() => { getFleet().then(data => setFleet(data)); @@ -32,7 +32,7 @@ export default function Fleet() { text: 'Row', formatter: getRowIndex, headerStyle: () => { - return { width: '50px', textAlign: 'center' }; + return { width: '2%', textAlign: 'center' }; }, align: 'center' }, { @@ -40,6 +40,9 @@ export default function Fleet() { text: 'Name', sort: true, filter: textFilter(), + headerStyle: () => { + return { width: '10%', textAlign: 'left' }; + }, formatter: (cell, row) => { return {cell} } @@ -47,6 +50,9 @@ export default function Fleet() { dataField: 'id', text: 'ID', sort: true, + headerStyle: () => { + return { width: '10%', textAlign: 'left' }; + }, filter: textFilter() }, { dataField: 'description', @@ -67,18 +73,24 @@ export default function Fleet() { dataField: 'type', text: 'Type', sort: true, + headerStyle: () => { + return { width: '10%', textAlign: 'left' }; + }, filter: textFilter() }, { dataField: 'position.name', text: 'Position', sort: true, + headerStyle: () => { + return { width: '10%', textAlign: 'left' }; + }, filter: textFilter() }, { dataField: 'fighter_count', text: 'Fighter Count', sort: true, headerStyle: () => { - return { width: '100px', textAlign: 'center' }; + return { width: '5%', textAlign: 'center' }; }, align: 'center' }, { @@ -86,7 +98,7 @@ export default function Fleet() { text: 'Transporter Count', sort: true, headerStyle: () => { - return { width: '100px', textAlign: 'center' }; + return { width: '5%', textAlign: 'center' }; }, align: 'center' }, { @@ -94,15 +106,7 @@ export default function Fleet() { text: 'Person Count', sort: true, headerStyle: () => { - return { width: '100px', textAlign: 'center' }; - }, - align: 'center' - }, { - dataField: 'is_visible', - text: 'Is Visible', - sort: true, - headerStyle: () => { - return { width: '100px', textAlign: 'center' }; + return { width: '5%', textAlign: 'center' }; }, align: 'center' }]; diff --git a/src/components/Ship.css b/src/components/Ship.css index f1086bd..fb923dd 100644 --- a/src/components/Ship.css +++ b/src/components/Ship.css @@ -24,3 +24,7 @@ h1.ship { .ship .data-found { color: #f26bf7; } + +.ship span { + white-space: pre-line; + } \ No newline at end of file diff --git a/src/components/Ship.js b/src/components/Ship.js index 134a1b6..3c4dbbc 100644 --- a/src/components/Ship.js +++ b/src/components/Ship.js @@ -19,7 +19,11 @@ const getArtifacts = async (id) => { } const getCaptain = async (id) => { - const response = await fetch(apiUrl(`/person?show_hidden=true&ship_id=${id}&title=Star%20Captain`)); + let title = encodeURI('Star Captain') + if (id === 'aurora') { + title = encodeURI('Grand Admiral of the EOC starfleet') + } + const response = await fetch(apiUrl(`/person?show_hidden=true&ship_id=${id}&title=${title}`)); let captain = await response.json(); captain = captain.persons; // On Odysseus there are two Star Captains. We want Zeya Cook id 20112. @@ -29,10 +33,17 @@ const getCaptain = async (id) => { return captain[0]; } +const getPassangers = async (id) => { + const response = await fetch(apiUrl(`/person?show_hidden=true&is_character=false&ship_id=${id}`)); + const passangers = await response.json(); + return passangers; +} + export default function Ship(props) { const [ship, setShip] = React.useState(null); const [captain, setCaptain] = React.useState(null); const [artifacts, setArtifacts] = React.useState(null); + const [passangers, setPassangers] = React.useState(null); const params = useParams(); React.useEffect(() => { @@ -50,6 +61,11 @@ export default function Ship(props) { getCaptain(params.id).then((s) => setCaptain(s)); }, [params.id, setCaptain]); + React.useEffect(() => { + if (!params.id) return; + getPassangers(params.id).then((s) => setPassangers(s)); + }, [params.id, setPassangers]); + React.useEffect(() => { props.changeTab('Fleet'); }, [props]); @@ -58,6 +74,7 @@ export default function Ship(props) { if (!ship) return null; if (!artifacts) return null; if (!captain) return null; + if (!passangers) return null; return (
@@ -88,7 +105,7 @@ export default function Ship(props) { Description - {artifacts.filter(artifact => artifact.name === ship.class)[0].text} + {artifacts.filter(artifact => artifact.name === ship.class)[0].text.split('![]')[0].trim()}   @@ -142,9 +159,9 @@ export default function Ship(props) {   - Persons on Ship (Characters / NPCs) + NPCs on Ship ({passangers.persons.length}) - {
  • Link to Character name
  • Link to NPC 1 (Knows: Character Name 1, Character Name 2)
  • Link to NPC 2 (Knows: Character Name 1, Character Name 2)
} + {
    {passangers.persons?.map(person =>
  • props.changeTab('Characters')} to={`/characters/${person.id}`}>{person.full_name}
  • )}
}
)