Skip to content

Commit

Permalink
save rank to globalStore
Browse files Browse the repository at this point in the history
  • Loading branch information
Manwe-777 committed May 12, 2024
1 parent c8a60d9 commit f313dee
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/background/onLabel/InEventGetCombinedRankInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface CombinedRankInfo {
limitedLeaderboardPlace: number;
}

const rankClass: Record<number, string> = {
export const rankClass: Record<number, string> = {
"-1": "Unranked",
"0": "Beginner",
"1": "Bronze",
Expand All @@ -49,8 +49,8 @@ export default function InEventGetCombinedRankInfo(entry: Entry): void {
type: "UPSERT_DB_RANK",
value: {
...memoryRank,
constructedClass: rankClass[memoryRank.constructedClass],
limitedClass: rankClass[memoryRank.limitedClass],
constructedClass: memoryRank.constructedClass,
limitedClass: memoryRank.limitedClass,
},
});
} else {
Expand Down
21 changes: 17 additions & 4 deletions src/reader/readRank.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import {
CombinedRankInfo,
rankClass,
} from "../background/onLabel/InEventGetCombinedRankInfo";
import globalStore from "../background/store";
import isElectron from "../utils/electron/isElectron";

interface CombinedRankInfo {
interface _ReturnedRankInfo {
constructedClass: number;
constructedLeaderboardPlace: number;
constructedLevel: number;
Expand Down Expand Up @@ -37,9 +42,17 @@ export default function readRank(): CombinedRankInfo | undefined {
"_combinedRankInfo",
]);

if (rank.error) return undefined;
if (rank.error || Object.keys(rank).length === 0) {
if (globalStore.rank) return globalStore.rank;

if (Object.keys(rank).length === 0) return undefined;
return undefined;
}

return rank;
globalStore.rank = {
...rank,
constructedClass: rankClass[rank.constructedClass],
limitedClass: rankClass[rank.limitedClass],
};

return globalStore.rank;
}

0 comments on commit f313dee

Please sign in to comment.