Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix small ui bugs #1142

Merged
merged 2 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 77 additions & 90 deletions client/src/hooks/helpers/useQuests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,32 @@ export enum QuestStatus {
export const useQuests = () => {
const questDependencies = useQuestDependencies();

const createQuest = useCallback(
(questId: QuestId) => {
const dependency = questDependencies[questId];
return {
const createQuest = (questId: QuestId) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good optimization. Using useMemo for each quest creation will prevent unnecessary re-renders.

const dependency = questDependencies[questId];
return useMemo(
() => ({
id: questId,
...questDetails.get(questId)!,
status: dependency.status,
};
},
[questDependencies],
);
}),
[questDependencies[questId]],
);
};

const quests = useMemo(
() => [
createQuest(QuestId.Settle),
createQuest(QuestId.BuildFarm),
createQuest(QuestId.BuildResource),
createQuest(QuestId.CreateTrade),
createQuest(QuestId.CreateArmy),
createQuest(QuestId.Travel),
createQuest(QuestId.BuildWorkersHut),
createQuest(QuestId.Market),
createQuest(QuestId.Pillage),
createQuest(QuestId.Mine),
createQuest(QuestId.Contribution),
createQuest(QuestId.Hyperstructure),
],
[createQuest],
);
const quests = [
createQuest(QuestId.Settle),
createQuest(QuestId.BuildFarm),
createQuest(QuestId.BuildResource),
createQuest(QuestId.CreateTrade),
createQuest(QuestId.CreateArmy),
createQuest(QuestId.Travel),
createQuest(QuestId.BuildWorkersHut),
createQuest(QuestId.Market),
createQuest(QuestId.Pillage),
createQuest(QuestId.Mine),
createQuest(QuestId.Contribution),
createQuest(QuestId.Hyperstructure),
];

return { quests };
};
Expand Down Expand Up @@ -135,103 +132,93 @@ const useQuestDependencies = () => {
},
[QuestId.BuildFarm]: {
value: questClaimStatus[QuestId.BuildFarm] ? null : buildingQuantities.farms,
status:
buildingQuantities.farms > 0
? questClaimStatus[QuestId.BuildFarm]
? QuestStatus.Claimed
: QuestStatus.Completed
: QuestStatus.InProgress,
status: questClaimStatus[QuestId.BuildFarm]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This refactoring improves readability and reduces nesting. It's a good change.

? QuestStatus.Claimed
: buildingQuantities.farms > 0
? QuestStatus.Completed
: QuestStatus.InProgress,
},
[QuestId.BuildResource]: {
value: questClaimStatus[QuestId.BuildResource] ? null : buildingQuantities.resource,
status:
buildingQuantities.resource > 0
? questClaimStatus[QuestId.BuildResource]
? QuestStatus.Claimed
: QuestStatus.Completed
: QuestStatus.InProgress,
status: questClaimStatus[QuestId.BuildResource]
? QuestStatus.Claimed
: buildingQuantities.resource > 0
? QuestStatus.Completed
: QuestStatus.InProgress,
},
[QuestId.CreateTrade]: {
value: questClaimStatus[QuestId.CreateTrade] ? null : orders.length,
status:
orders.length > 0
? questClaimStatus[QuestId.CreateTrade]
? QuestStatus.Claimed
: QuestStatus.Completed
: QuestStatus.InProgress,
status: questClaimStatus[QuestId.CreateTrade]
? QuestStatus.Claimed
: orders.length > 0
? QuestStatus.Completed
: QuestStatus.InProgress,
},
[QuestId.CreateArmy]: {
value: questClaimStatus[QuestId.CreateArmy]
? { armyCount: null, hasTroops: null }
: { armyCount: entityArmies.length, hasTroops },
status:
entityArmies.length > 0 && hasTroops
? questClaimStatus[QuestId.CreateArmy]
? QuestStatus.Claimed
: QuestStatus.Completed
: QuestStatus.InProgress,
status: questClaimStatus[QuestId.CreateArmy]
? QuestStatus.Claimed
: entityArmies.length > 0 && hasTroops
? QuestStatus.Completed
: QuestStatus.InProgress,
},
[QuestId.Travel]: {
value: questClaimStatus[QuestId.Travel] ? null : hasTraveled,
status: hasTraveled
? questClaimStatus[QuestId.Travel]
? QuestStatus.Claimed
: QuestStatus.Completed
status: questClaimStatus[QuestId.Travel]
? QuestStatus.Claimed
: hasTraveled
? QuestStatus.Completed
: QuestStatus.InProgress,
},
[QuestId.BuildWorkersHut]: {
value: questClaimStatus[QuestId.BuildWorkersHut] ? null : buildingQuantities.workersHut,
status:
buildingQuantities.workersHut > 0
? questClaimStatus[QuestId.BuildWorkersHut]
? QuestStatus.Claimed
: QuestStatus.Completed
: QuestStatus.InProgress,
status: questClaimStatus[QuestId.BuildWorkersHut]
? QuestStatus.Claimed
: buildingQuantities.workersHut > 0
? QuestStatus.Completed
: QuestStatus.InProgress,
},
[QuestId.Market]: {
value: questClaimStatus[QuestId.Market] ? null : buildingQuantities.markets,
status:
buildingQuantities.markets > 0
? questClaimStatus[QuestId.Market]
? QuestStatus.Claimed
: QuestStatus.Completed
: QuestStatus.InProgress,
status: questClaimStatus[QuestId.Market]
? QuestStatus.Claimed
: buildingQuantities.markets > 0
? QuestStatus.Completed
: QuestStatus.InProgress,
},
[QuestId.Pillage]: {
value: questClaimStatus[QuestId.Pillage] ? null : pillageHistoryLength,
status:
pillageHistoryLength > 0
? questClaimStatus[QuestId.Pillage]
? QuestStatus.Claimed
: QuestStatus.Completed
: QuestStatus.InProgress,
status: questClaimStatus[QuestId.Pillage]
? QuestStatus.Claimed
: pillageHistoryLength > 0
? QuestStatus.Completed
: QuestStatus.InProgress,
},
[QuestId.Mine]: {
value: questClaimStatus[QuestId.Mine] ? null : fragmentMines,
status:
fragmentMines > 0
? questClaimStatus[QuestId.Mine]
? QuestStatus.Claimed
: QuestStatus.Completed
: QuestStatus.InProgress,
status: questClaimStatus[QuestId.Mine]
? QuestStatus.Claimed
: fragmentMines > 0
? QuestStatus.Completed
: QuestStatus.InProgress,
},
[QuestId.Contribution]: {
value: questClaimStatus[QuestId.Contribution] ? null : hyperstructureContributions,
status:
hyperstructureContributions > 0
? questClaimStatus[QuestId.Contribution]
? QuestStatus.Claimed
: QuestStatus.Completed
: QuestStatus.InProgress,
status: questClaimStatus[QuestId.Contribution]
? QuestStatus.Claimed
: hyperstructureContributions > 0
? QuestStatus.Completed
: QuestStatus.InProgress,
},
[QuestId.Hyperstructure]: {
value: questClaimStatus[QuestId.Hyperstructure] ? null : hyperstructures,
status:
hyperstructures > 0
? questClaimStatus[QuestId.Hyperstructure]
? QuestStatus.Claimed
: QuestStatus.Completed
: QuestStatus.InProgress,
status: questClaimStatus[QuestId.Hyperstructure]
? QuestStatus.Claimed
: hyperstructures > 0
? QuestStatus.Completed
: QuestStatus.InProgress,
},
}),
[questClaimStatus, unclaimedQuestsCount > 0 ? entityUpdate : null, unclaimedQuestsCount > 0 ? orders : null],
Expand Down Expand Up @@ -324,4 +311,4 @@ const armyHasTraveled = (entityArmies: ArmyInfo[], realmPosition: { x: number; y
return entityArmies[0].position.x != realmPosition.x || entityArmies[0].position.y != realmPosition.y;
}
return false;
};
};
2 changes: 1 addition & 1 deletion client/src/ui/components/quest/QuestList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const SkipTutorial = ({ entityId }: { entityId: bigint }) => {

const questResources = getQuestResources();

const unclaimedQuests = quests?.filter((quest) => quest.status === QuestStatus.InProgress);
const unclaimedQuests = quests?.filter((quest) => quest.status !== QuestStatus.Claimed);
edisontim marked this conversation as resolved.
Show resolved Hide resolved

const resourcesToMint =
unclaimedQuests?.flatMap((quest: Quest) =>
Expand Down
2 changes: 1 addition & 1 deletion client/src/ui/modules/navigation/LeftNavigationModule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export const LeftNavigationModule = () => {
item.name === MenuEnum.construction ||
item.name === MenuEnum.worldStructures,
);
}, [location, view, openedPopups, selectedQuest, armiesCanMoveCount]);
}, [location, view, openedPopups, selectedQuest, armiesCanMoveCount, questClaimStatus]);
edisontim marked this conversation as resolved.
Show resolved Hide resolved

if (realmEntityId === undefined) {
return null;
Expand Down
Loading