From eb49a8eabda50f57da21a32cae23aacf162a6502 Mon Sep 17 00:00:00 2001 From: cwastche Date: Fri, 26 Jul 2024 18:23:55 +0200 Subject: [PATCH 1/2] fix small ui bugs --- client/src/hooks/helpers/useQuests.tsx | 167 ++++++++---------- client/src/ui/components/quest/QuestList.tsx | 2 +- .../navigation/LeftNavigationModule.tsx | 2 +- 3 files changed, 79 insertions(+), 92 deletions(-) diff --git a/client/src/hooks/helpers/useQuests.tsx b/client/src/hooks/helpers/useQuests.tsx index 16c56d13a..6ea29b818 100644 --- a/client/src/hooks/helpers/useQuests.tsx +++ b/client/src/hooks/helpers/useQuests.tsx @@ -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) => { + 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 }; }; @@ -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] + ? 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], @@ -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; -}; +}; \ No newline at end of file diff --git a/client/src/ui/components/quest/QuestList.tsx b/client/src/ui/components/quest/QuestList.tsx index 26815435d..bdf08bf9b 100644 --- a/client/src/ui/components/quest/QuestList.tsx +++ b/client/src/ui/components/quest/QuestList.tsx @@ -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); const resourcesToMint = unclaimedQuests?.flatMap((quest: Quest) => diff --git a/client/src/ui/modules/navigation/LeftNavigationModule.tsx b/client/src/ui/modules/navigation/LeftNavigationModule.tsx index 54e45945e..7d14300d6 100644 --- a/client/src/ui/modules/navigation/LeftNavigationModule.tsx +++ b/client/src/ui/modules/navigation/LeftNavigationModule.tsx @@ -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]); if (realmEntityId === undefined) { return null; From bf44827969d6be69690ff5979410cc1776669bcf Mon Sep 17 00:00:00 2001 From: cwastche Date: Fri, 26 Jul 2024 18:29:16 +0200 Subject: [PATCH 2/2] prettier --- client/src/hooks/helpers/useQuests.tsx | 46 +++++++++++++------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/client/src/hooks/helpers/useQuests.tsx b/client/src/hooks/helpers/useQuests.tsx index 6ea29b818..18dab39dd 100644 --- a/client/src/hooks/helpers/useQuests.tsx +++ b/client/src/hooks/helpers/useQuests.tsx @@ -135,24 +135,24 @@ const useQuestDependencies = () => { status: questClaimStatus[QuestId.BuildFarm] ? QuestStatus.Claimed : buildingQuantities.farms > 0 - ? QuestStatus.Completed - : QuestStatus.InProgress, + ? QuestStatus.Completed + : QuestStatus.InProgress, }, [QuestId.BuildResource]: { value: questClaimStatus[QuestId.BuildResource] ? null : buildingQuantities.resource, status: questClaimStatus[QuestId.BuildResource] ? QuestStatus.Claimed : buildingQuantities.resource > 0 - ? QuestStatus.Completed - : QuestStatus.InProgress, + ? QuestStatus.Completed + : QuestStatus.InProgress, }, [QuestId.CreateTrade]: { value: questClaimStatus[QuestId.CreateTrade] ? null : orders.length, status: questClaimStatus[QuestId.CreateTrade] ? QuestStatus.Claimed : orders.length > 0 - ? QuestStatus.Completed - : QuestStatus.InProgress, + ? QuestStatus.Completed + : QuestStatus.InProgress, }, [QuestId.CreateArmy]: { value: questClaimStatus[QuestId.CreateArmy] @@ -161,64 +161,64 @@ const useQuestDependencies = () => { status: questClaimStatus[QuestId.CreateArmy] ? QuestStatus.Claimed : entityArmies.length > 0 && hasTroops - ? QuestStatus.Completed - : QuestStatus.InProgress, + ? QuestStatus.Completed + : QuestStatus.InProgress, }, [QuestId.Travel]: { value: questClaimStatus[QuestId.Travel] ? null : hasTraveled, status: questClaimStatus[QuestId.Travel] ? QuestStatus.Claimed : hasTraveled - ? QuestStatus.Completed - : QuestStatus.InProgress, + ? QuestStatus.Completed + : QuestStatus.InProgress, }, [QuestId.BuildWorkersHut]: { value: questClaimStatus[QuestId.BuildWorkersHut] ? null : buildingQuantities.workersHut, status: questClaimStatus[QuestId.BuildWorkersHut] ? QuestStatus.Claimed : buildingQuantities.workersHut > 0 - ? QuestStatus.Completed - : QuestStatus.InProgress, + ? QuestStatus.Completed + : QuestStatus.InProgress, }, [QuestId.Market]: { value: questClaimStatus[QuestId.Market] ? null : buildingQuantities.markets, status: questClaimStatus[QuestId.Market] ? QuestStatus.Claimed : buildingQuantities.markets > 0 - ? QuestStatus.Completed - : QuestStatus.InProgress, + ? QuestStatus.Completed + : QuestStatus.InProgress, }, [QuestId.Pillage]: { value: questClaimStatus[QuestId.Pillage] ? null : pillageHistoryLength, status: questClaimStatus[QuestId.Pillage] ? QuestStatus.Claimed : pillageHistoryLength > 0 - ? QuestStatus.Completed - : QuestStatus.InProgress, + ? QuestStatus.Completed + : QuestStatus.InProgress, }, [QuestId.Mine]: { value: questClaimStatus[QuestId.Mine] ? null : fragmentMines, status: questClaimStatus[QuestId.Mine] ? QuestStatus.Claimed : fragmentMines > 0 - ? QuestStatus.Completed - : QuestStatus.InProgress, + ? QuestStatus.Completed + : QuestStatus.InProgress, }, [QuestId.Contribution]: { value: questClaimStatus[QuestId.Contribution] ? null : hyperstructureContributions, status: questClaimStatus[QuestId.Contribution] ? QuestStatus.Claimed : hyperstructureContributions > 0 - ? QuestStatus.Completed - : QuestStatus.InProgress, + ? QuestStatus.Completed + : QuestStatus.InProgress, }, [QuestId.Hyperstructure]: { value: questClaimStatus[QuestId.Hyperstructure] ? null : hyperstructures, status: questClaimStatus[QuestId.Hyperstructure] ? QuestStatus.Claimed : hyperstructures > 0 - ? QuestStatus.Completed - : QuestStatus.InProgress, + ? QuestStatus.Completed + : QuestStatus.InProgress, }, }), [questClaimStatus, unclaimedQuestsCount > 0 ? entityUpdate : null, unclaimedQuestsCount > 0 ? orders : null], @@ -311,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; -}; \ No newline at end of file +};