Skip to content

Commit

Permalink
Started working on a new layout and ui for the capital city building …
Browse files Browse the repository at this point in the history
…upgrade/repair.
  • Loading branch information
AdamKyle committed Aug 29, 2024
1 parent f2a4330 commit d1b9e3b
Show file tree
Hide file tree
Showing 3 changed files with 269 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,61 @@ export default class FetchUpgradableKingdomsAjax {
(result: AxiosResponse) => {
let data = result.data;

// Filter based on repair status
if (component.props.repair) {
data = result.data.map(
data = data
.map(
(kingdom: {
map_name: any;
kingdom_name: any;
kingdom_id: number;
buildings: any[];
}) => ({
kingdom_name: kingdom.kingdom_name,
kingdom_id: kingdom.kingdom_id,
map_name: kingdom.map_name,
buildings: kingdom.buildings
.filter(
(building) =>
building.current_durability <
building.max_durability,
)
.sort((a, b) => a.level - b.level), // Sort buildings by level (lowest to highest)
}),
)
.filter(
(kingdom: any) => kingdom.buildings.length > 0, // Keep only kingdoms with buildings needing repair
);
} else {
data = data.map(
(kingdom: {
map_name: any;
kingdom_name: any;
kingdom_id: number;
buildings: any[];
}) => ({
kingdom_name: kingdom.kingdom_name,
map_name: kingdom.map_name,
kingdom_id: kingdom.kingdom_id,
buildings: kingdom.buildings.filter(
(building) =>
building.current_durability <
building.max_durability,
),
buildings: kingdom.buildings
.filter(
(building) =>
building.current_durability >=
building.max_durability,
)
.sort((a, b) => a.level - b.level), // Sort buildings by level (lowest to highest)
}),
);
}

// Set the state with the filtered and sorted data
component.setState({
loading: false,
building_data: data,
});

// Update the filtered data
component.updateFilteredBuildingData();
},
(error: AxiosError) => {
component.setState({
Expand Down
Loading

0 comments on commit d1b9e3b

Please sign in to comment.