bitburner-src/src/Faction/ui/FactionList.tsx

72 lines
2.0 KiB
TypeScript
Raw Normal View History

2021-09-05 01:09:30 +02:00
import React, { useState } from "react";
import { IPlayer } from "../../PersonObjects/IPlayer";
import { IEngine } from "../../IEngine";
import { Factions } from "../Factions";
import { displayFactionContent, joinFaction } from "../FactionHelpers";
interface IProps {
2021-09-05 01:09:30 +02:00
player: IPlayer;
engine: IEngine;
}
export function FactionList(props: IProps): React.ReactElement {
2021-09-05 01:09:30 +02:00
const setRerender = useState(false)[1];
2021-09-05 01:09:30 +02:00
function openFaction(faction: string): void {
props.engine.loadFactionContent();
displayFactionContent(faction);
}
2021-09-05 01:09:30 +02:00
function acceptInvitation(
event: React.MouseEvent<HTMLElement>,
faction: string,
): void {
if (!event.isTrusted) return;
joinFaction(Factions[faction]);
setRerender((x) => !x);
}
2021-09-05 01:09:30 +02:00
return (
<>
<h1>Factions</h1>
<p>Lists all factions you have joined</p>
<br />
<ul>
{props.player.factions.map((faction: string) => (
<li key={faction}>
<a
className="a-link-button"
onClick={() => openFaction(faction)}
style={{ padding: "4px", margin: "4px", display: "inline-block" }}
>
{faction}
</a>
</li>
))}
</ul>
<br />
<h1>Outstanding Faction Invitations</h1>
<p style={{ width: "70%" }}>
Lists factions you have been invited to. You can accept these faction
invitations at any time.
</p>
<ul>
{props.player.factionInvitations.map((faction: string) => (
<li key={faction} style={{ padding: "6px", margin: "6px" }}>
<p style={{ display: "inline", margin: "4px", padding: "4px" }}>
{faction}
</p>
<a
className="a-link-button"
onClick={(e) => acceptInvitation(e, faction)}
style={{ display: "inline", margin: "4px", padding: "4px" }}
>
Accept Faction Invitation
</a>
</li>
))}
</ul>
</>
);
}