Skip to content

Commit

Permalink
- fix death dialog leaderboard score
Browse files Browse the repository at this point in the history
  • Loading branch information
starknetdev committed Sep 27, 2023
1 parent 98585fa commit 27f7a43
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
37 changes: 24 additions & 13 deletions ui/src/app/components/adventurer/DeathDialog.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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);
Expand All @@ -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 ?? []
Expand All @@ -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 (
<>
<div className="top-0 left-0 fixed text-center h-full w-full z-40">
Expand Down
2 changes: 0 additions & 2 deletions ui/src/app/components/marketplace/MarketplaceTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ const MarketplaceTable = ({
return sortedItems;
}, [marketLatestItems, sortField, sortDirection]);

console.log(showEquipQ);

return (
<>
<div>
Expand Down
10 changes: 0 additions & 10 deletions ui/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

1 comment on commit 27f7a43

@vercel
Copy link

@vercel vercel bot commented on 27f7a43 Sep 27, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.