Skip to content

Commit

Permalink
Disable 404-ed gimmick buttons instead of removing
Browse files Browse the repository at this point in the history
- Store disabled gimmicks in WarMap state
- Send their IDs to ButtonGrid props
- Use danger buttons for disabled items in ButtonGrid
  • Loading branch information
boyonthebeach2k committed Sep 4, 2023
1 parent d232e5a commit 50fcb45
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
11 changes: 10 additions & 1 deletion packages/db/src/Component/ButtonGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ interface IProps {
}[];
/** All buttons enabled by default */
defaultEnabled: boolean;
/** Buttons prevented from being interacted with */
disabledItems?: number[];
/** Title for the grid */
title: string;
/** Inline style overrides for the container of the buttons */
Expand Down Expand Up @@ -143,7 +145,14 @@ class ButtonGrid extends React.Component<IProps, IState> {
<Button
key={item.uniqueId}
className="toggle-button"
variant={this.state.buttonStates[item.uniqueId] ? "success" : "secondary"}
variant={
this.props.disabledItems?.includes(item.uniqueId)
? "danger"
: this.state.buttonStates[item.uniqueId]
? "success"
: "secondary"
}
disabled={this.props.disabledItems?.includes(item.uniqueId)}
style={this.props.buttonStyleOverride ?? {}}
onClick={this.handleClick.bind(this)}
>
Expand Down
7 changes: 4 additions & 3 deletions packages/db/src/Page/WarMap/WarMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ interface IState {
FQSpotsOnly: boolean;
isMapLoaded: boolean;
mapGimmicks: War.MapGimmick[];
disabledMapGimmickIds: number[];
OGMapGimmicks: War.MapGimmick[];
showRoads: boolean;
showSpots: boolean;
Expand Down Expand Up @@ -157,6 +158,7 @@ class WarMap extends React.Component<IProps, IState> {
this.state = {
isMapLoaded: true,
mapGimmicks: this.defaultToggleEnabled ? mapGimmicks : [],
disabledMapGimmickIds: [],
OGMapGimmicks,
FQSpotsOnly: true,
showRoads: !donotSpotroad.includes(this.props.warId) && !!this.props.spotRoads.length,
Expand Down Expand Up @@ -248,9 +250,7 @@ class WarMap extends React.Component<IProps, IState> {
alt=""
onError={() =>
this.setState({
OGMapGimmicks: this.state.OGMapGimmicks.filter(
(filterGimmick) => filterGimmick.id !== gimmick.id
),
disabledMapGimmickIds: [...this.state.disabledMapGimmickIds, gimmick.id],
})
}
src={gimmick.image}
Expand All @@ -277,6 +277,7 @@ class WarMap extends React.Component<IProps, IState> {
]}
title={"Gimmicks to display"}
defaultEnabled={this.defaultToggleEnabled}
disabledItems={this.state.disabledMapGimmickIds}
onClick={(enabledGimmicks) => {
let showRoads =
enabledGimmicks.some((gimmick) => gimmick === -Infinity) &&
Expand Down

0 comments on commit 50fcb45

Please sign in to comment.