Skip to content

Commit

Permalink
Refactor app page achievement bar
Browse files Browse the repository at this point in the history
  • Loading branch information
candela97 committed Mar 23, 2024
1 parent 43fd472 commit 8ee1899
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 73 deletions.
4 changes: 0 additions & 4 deletions src/js/Background/Modules/SteamCommunityApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ class SteamCommunityApi extends Api {
return SteamCommunityApi.getPage(`/my/gamecards/${appid}`, border ? {"border": 1} : {}, true);
}

static stats(path, appid) {
return SteamCommunityApi.getPage(`${path}/stats/${appid}`, {}, true);
}

static async getInventory(contextId) {
const login = LocalStorage.get("login");
if (!login.steamId) {
Expand Down
1 change: 0 additions & 1 deletion src/js/Background/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ const actionCallbacks = new Map([
["logout", SteamCommunityApi.logout],
["storecountry", SteamCommunityApi.storeCountry],
["cards", SteamCommunityApi.cards],
["stats", SteamCommunityApi.stats],
["coupon", SteamCommunityApi.getCoupon],
["hasgiftsandpasses", SteamCommunityApi.hasGiftsAndPasses],
["hascoupon", SteamCommunityApi.hasCoupon],
Expand Down
37 changes: 32 additions & 5 deletions src/js/Content/Features/Store/App/FAchievementBar.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {HTML, SyncedStorage} from "../../../../modulesCore";
import {Feature, Stats} from "../../../modulesContent";
import {HTML, Localization, SyncedStorage} from "../../../../modulesCore";
import {Feature, RequestData, User} from "../../../modulesContent";

export default class FAchievementBar extends Feature {

Expand All @@ -10,12 +10,39 @@ export default class FAchievementBar extends Feature {
}

async apply() {
const achieveBar = await Stats.getAchievementBar("/my", this.context.communityAppid);
if (!achieveBar) {

let response;

try {
const token = await User.accessToken;
response = await RequestData.post(
`https://api.steampowered.com/IPlayerService/GetAchievementsProgress/v1/?access_token=${token}`,
{"steamid": User.steamId, "appids[0]": this.context.appid},
{"credentials": "omit"}
);
} catch (err) {
console.error(err);
}

response = response?.response?.achievement_progress?.[0];

if (!response) {
console.warn("Failed to retrieve achievement stats");
return;
}

HTML.afterBegin("#my_activity", `<div class="es-achieveBar-store">${achieveBar}</div>`);
const {unlocked, total, percentage} = response;
const achievementStr = Localization.str.achievements.summary
.replace("__unlocked__", unlocked)
.replace("__total__", total)
.replace("__percentage__", Math.round(percentage));

HTML.afterBegin("#my_activity",
`<div class="es-achieveBar-store">
<div>${achievementStr}</div>
<div class="achieveBar">
<div style="width: ${percentage}%;" class="achieveBarProgress"></div>
</div>
</div>`);
}
}
62 changes: 0 additions & 62 deletions src/js/Content/Modules/Stats.js

This file was deleted.

1 change: 0 additions & 1 deletion src/js/Content/modulesContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export {Messenger} from "./Modules/Messenger";
export {Price} from "./Modules/Price";
export {Prices} from "./Modules/Prices/Prices";
export {RequestData} from "./Modules/RequestData";
export {Stats} from "./Modules/Stats";
export {SteamId, SteamIdDetail} from "./Modules/SteamId";
export {UpdateHandler} from "./Modules/UpdateHandler";
export {User} from "./Modules/User";

0 comments on commit 8ee1899

Please sign in to comment.