-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor out: FactionDetails.tsx, FactionActions.tsx
- Loading branch information
Konrad Jamrozik
committed
Jun 29, 2024
1 parent
d844de0
commit 9d1845f
Showing
4 changed files
with
107 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Stack } from '@mui/material' | ||
import type { GameState } from '../../lib/codesync/GameState' | ||
import SliderWithButton from '../SliderWithButton/SliderWithButton' | ||
import type { ManageFactionDialogProps } from './ManageFactionDialog' | ||
|
||
export function FactionActions( | ||
props: ManageFactionDialogProps & { gs: GameState }, | ||
): React.JSX.Element { | ||
// eslint-disable-next-line unicorn/consistent-function-scoping | ||
function investIntel(amount: number): void { | ||
console.log(`investIntel(${amount}) NOT IMPLEMENTED`) | ||
} | ||
|
||
return ( | ||
<Stack direction="column" spacing={1} display="flex" alignItems="center"> | ||
<SliderWithButton | ||
defaultValue={Math.floor(props.gs.Assets.Intel * 0.2)} | ||
onClick={async (intel: number) => { | ||
await Promise.resolve() | ||
investIntel(intel) | ||
}} | ||
minValue={0} | ||
maxValue={props.gs.Assets.Intel} | ||
iconName="Intel" | ||
label="Invest $TargetID intel" | ||
/> | ||
<SliderWithButton | ||
defaultValue={Math.floor(props.gs.Assets.Intel * 0.5)} | ||
onClick={async (intel: number) => { | ||
await Promise.resolve() | ||
investIntel(intel) | ||
}} | ||
minValue={0} | ||
maxValue={props.gs.Assets.Intel} | ||
iconName="Intel" | ||
label="Invest $TargetID intel" | ||
/> | ||
</Stack> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import type { SxProps, Theme } from '@mui/material' | ||
import Grid from '@mui/material/Unstable_Grid2' | ||
import _ from 'lodash' | ||
import { Fragment } from 'react/jsx-runtime' | ||
import { getNormalizedPower } from '../../lib/codesync/ruleset' | ||
import { factionNameRenderMap } from '../../lib/rendering/renderFactions' | ||
import { getSx } from '../../lib/rendering/renderUtils' | ||
import { Label } from '../Label' | ||
import type { ManageFactionDialogProps } from './ManageFactionDialog' | ||
|
||
const gridMaxWidthPx = 300 | ||
|
||
export function FactionDetails( | ||
props: ManageFactionDialogProps, | ||
): React.JSX.Element { | ||
const entries = getFactionDetailsEntries(props) | ||
return ( | ||
<Grid | ||
container | ||
spacing={1} | ||
// bgcolor="rgba(100,200,100,0.2)" | ||
width={gridMaxWidthPx} | ||
> | ||
{_.map(entries, (entry, index) => ( | ||
<Fragment key={index}> | ||
<Grid xs={6}> | ||
<Label sx={entry.labelSx ?? {}}>{entry.label}</Label> | ||
</Grid> | ||
<Grid xs={6}> | ||
<Label sx={entry.valueSx ?? {}}>{entry.value}</Label> | ||
</Grid> | ||
</Fragment> | ||
))} | ||
</Grid> | ||
) | ||
} | ||
|
||
function getFactionDetailsEntries( | ||
props: ManageFactionDialogProps, | ||
): FactionDetailsEntry[] { | ||
const name = factionNameRenderMap[props.faction.Name].display | ||
const power = getNormalizedPower(props.faction) | ||
const intel = props.faction.IntelInvested | ||
|
||
// prettier-ignore | ||
const entries: FactionDetailsEntry[] = [ | ||
{ label: 'Faction', value: name, valueSx: getSx(props.faction.Name) }, | ||
{ label: 'Power', value: power, valueSx: getSx('Difficulty') }, | ||
{ label: 'Intel', value: intel, valueSx: getSx('Intel') }, | ||
] | ||
|
||
return entries | ||
} | ||
|
||
type FactionDetailsEntry = { | ||
label: string | ||
value: string | number | undefined | ||
labelSx?: SxProps<Theme> | ||
valueSx?: SxProps<Theme> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters