From 27f7a43eb593f2eaddaaad565ffd30d7b41c4a0f Mon Sep 17 00:00:00 2001 From: starknetdev Date: Wed, 27 Sep 2023 13:42:04 +0100 Subject: [PATCH] - fix death dialog leaderboard score --- .../app/components/adventurer/DeathDialog.tsx | 37 ++++++++++++------- .../marketplace/MarketplaceTable.tsx | 2 - ui/src/app/page.tsx | 10 ----- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/ui/src/app/components/adventurer/DeathDialog.tsx b/ui/src/app/components/adventurer/DeathDialog.tsx index c70aee0a8..cd4f20d22 100644 --- a/ui/src/app/components/adventurer/DeathDialog.tsx +++ b/ui/src/app/components/adventurer/DeathDialog.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useEffect } from "react"; import TwitterShareButton from "../buttons/TwitterShareButtons"; import useAdventurerStore from "../../hooks/useAdventurerStore"; import useLoadingStore from "../../hooks/useLoadingStore"; @@ -10,6 +10,7 @@ import { appUrl } from "@/app/lib/constants"; import { getAdventurerByXP } from "@/app/hooks/graphql/queries"; import useCustomQuery from "@/app/hooks/useCustomQuery"; import { NullAdventurer, Adventurer } from "@/app/types"; +import { useQueriesStore } from "@/app/hooks/useQueryStore"; export const DeathDialog = () => { const deathMessage = useLoadingStore((state) => state.deathMessage); @@ -18,24 +19,23 @@ export const DeathDialog = () => { const setAdventurer = useAdventurerStore((state) => state.setAdventurer); const showDeathDialog = useUIStore((state) => state.showDeathDialog); - const adventurersByXPdata = useCustomQuery( - "adventurersByXPQuery", - getAdventurerByXP, - undefined - ); + const { data, refetch, setData } = useQueriesStore(); - const copiedAdventurersByXpData = adventurersByXPdata?.adventurers.slice(); + useCustomQuery("adventurersByXPQuery", getAdventurerByXP, undefined); - const sortedAdventurersByXPArray = copiedAdventurersByXpData?.sort( - (a: Adventurer, b: Adventurer) => (b.xp ?? 0) - (a.xp ?? 0) - ); + const handleSortXp = (xpData: any) => { + const copiedAdventurersByXpData = xpData?.adventurers.slice(); - const sortedAdventurersByXP = { adventurers: sortedAdventurersByXPArray }; + const sortedAdventurersByXPArray = copiedAdventurersByXpData?.sort( + (a: Adventurer, b: Adventurer) => (b.xp ?? 0) - (a.xp ?? 0) + ); - console.log(adventurersByXPdata); - console.log(sortedAdventurersByXP); + const sortedAdventurersByXP = { adventurers: sortedAdventurersByXPArray }; + return sortedAdventurersByXP; + }; const handleRank = () => { + const sortedAdventurersByXP = data.adventurersByXPQuery; const rank = getRankFromList( adventurer?.id ?? 0, sortedAdventurersByXP?.adventurers ?? [] @@ -47,6 +47,17 @@ export const DeathDialog = () => { const rank = handleRank(); + useEffect(() => { + refetch("adventurersByXPQuery", undefined) + .then((adventurersByXPdata) => { + const sortedAdventurersByXP = handleSortXp(adventurersByXPdata); + setData("adventurersByXPQuery", sortedAdventurersByXP); + }) + .catch((error) => console.error("Error refetching data:", error)); + }, []); + + console.log(data.adventurersByXPQuery); + return ( <>
diff --git a/ui/src/app/components/marketplace/MarketplaceTable.tsx b/ui/src/app/components/marketplace/MarketplaceTable.tsx index cea8c47a2..b2279fd00 100644 --- a/ui/src/app/components/marketplace/MarketplaceTable.tsx +++ b/ui/src/app/components/marketplace/MarketplaceTable.tsx @@ -100,8 +100,6 @@ const MarketplaceTable = ({ return sortedItems; }, [marketLatestItems, sortField, sortDirection]); - console.log(showEquipQ); - return ( <>
diff --git a/ui/src/app/page.tsx b/ui/src/app/page.tsx index 87f48e9c1..e42197cfd 100644 --- a/ui/src/app/page.tsx +++ b/ui/src/app/page.tsx @@ -327,16 +327,6 @@ export default function Home() { } }, [adventurersData]); - // useEffect(() => { - // if ((isAlive && !hasStatUpgrades) || (isAlive && hasNoXp)) { - // setScreen("play"); - // } else if (hasStatUpgrades) { - // setScreen("upgrade"); - // } else if (!adventurer || !isAlive) { - // setScreen("start"); - // } - // }, [hasStatUpgrades, isAlive, hasNoXp, adventurer]); - const mobileMenuDisabled = [ false, hasStatUpgrades,