Skip to content

Commit

Permalink
Merge pull request #2026 from candela97/add-link-demo-appid-to-parent
Browse files Browse the repository at this point in the history
FWaitlistDropdown: link a demo app's appid to its parent appid
  • Loading branch information
tfedor authored Aug 27, 2024
2 parents f423ad8 + f6df7f9 commit 9614be1
Show file tree
Hide file tree
Showing 31 changed files with 70 additions and 40 deletions.
46 changes: 34 additions & 12 deletions src/js/Content/Features/Store/App/FWaitlistDropdown.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import {L} from "@Core/Localization/Localization";
import {
__addFullgameToWaitlist,
__addFullgameToWishlist,
__addToWaitlist,
__addToWishlist,
__onWaitlist,
__onWishlistAndWaitlist,
__removeFromWaitlistTooltip,
__removeFromWishlistAndWaitlistTooltip,
__removeFullgameFromWaitlistTooltip,
__removeFullgameFromWishlistAndWaitlistTooltip,
__theworddefault,
__wishlist,
} from "@Strings/_strings";
Expand All @@ -17,6 +21,7 @@ import HTML from "@Core/Html/Html";
import ExtensionResources from "@Core/ExtensionResources";
import SteamFacade from "@Content/Modules/Facades/SteamFacade";
import DOMHelper from "@Content/Modules/DOMHelper";
import AppId from "@Core/GameId/AppId";

export default class FWaitlistDropdown extends Feature<CApp> {

Expand All @@ -33,6 +38,22 @@ export default class FWaitlistDropdown extends Feature<CApp> {
return;
}

/**
* Link a demo app's appid to its parent appid.
* Steam does so when wishlisting, but we'll use the real appid for convenience.
*/
let appid: number = this.context.appid;
let storeid: string = this.context.storeid;

const isDemoApp = document.querySelector("img[src$='/ico_demo.gif']") !== null;
if (isDemoApp) {
const communityBtn = document.querySelector<HTMLAnchorElement>("a[href^='https://steamcommunity.com/app/']");
if (communityBtn) {
appid = AppId.fromUrl(communityBtn.href)!;
storeid = `app/${appid}`;
}
}

const wishlistArea = parent.querySelector<HTMLElement>("#add_to_wishlist_area")!;
const wishlistSuccessArea = parent.querySelector<HTMLElement>("#add_to_wishlist_area_success")!;

Expand Down Expand Up @@ -67,7 +88,7 @@ export default class FWaitlistDropdown extends Feature<CApp> {
</div>
<div class="queue_menu_option_label">
<div class="option_title">${L(__wishlist)} (${L(__theworddefault)})</div>
<div class="option_subtitle">${L(__addToWishlist)}</div>
<div class="option_subtitle">${isDemoApp ? L(__addFullgameToWishlist) : L(__addToWishlist)}</div>
</div>
</div>
<div class="queue_menu_option" id="queue_menu_option_on_waitlist">
Expand All @@ -77,7 +98,7 @@ export default class FWaitlistDropdown extends Feature<CApp> {
</div>
<div class="queue_menu_option_label">
<div class="option_title">Waitlist</div>
<div class="option_subtitle">${L(__addToWaitlist)}</div>
<div class="option_subtitle">${isDemoApp ? L(__addFullgameToWaitlist) : L(__addToWaitlist)}</div>
</div>
</div>
</div>
Expand All @@ -101,15 +122,15 @@ export default class FWaitlistDropdown extends Feature<CApp> {
DOMHelper.insertScript("scriptlets/Store/App/wishlistHandlers.js");

let wishlisted: boolean = wishlistArea.style.display === "none";
let waitlisted: boolean = (await ITADApiFacade.inWaitlist([this.context.storeid]))[this.context.storeid] ?? false;
let waitlisted: boolean = (await ITADApiFacade.inWaitlist([storeid]))[storeid] ?? false;

const menu = parent.querySelector(".as_btn_wishlist_menu")!;
const menuArrow = menu.querySelector(".queue_menu_arrow")!;
const wishlistOption = parent.querySelector("#queue_menu_option_on_wishlist")!;
const waitlistOption = parent.querySelector("#queue_menu_option_on_waitlist")!;

// Native localized text
const removeFromWishlistLabel = wishlistSuccessArea.querySelector("span")!.lastChild!.textContent;
const removeFromWishlistLabel = wishlistSuccessArea.querySelector("span")!.lastChild!.textContent!;
const removeFromWishlistTooltip = wishlistSuccessArea.querySelector("a")!.dataset.tooltipText;

function updateDiv() {
Expand All @@ -125,16 +146,17 @@ export default class FWaitlistDropdown extends Feature<CApp> {
wishlistArea.style.display = oneActive ? "none" : "";
wishlistSuccessArea.style.display = oneActive ? "" : "none";

let text, tooltip;
let text: string|undefined = undefined;
let tooltip: string|undefined = undefined;
if (wishlisted && !waitlisted) {
text = removeFromWishlistLabel;
tooltip = removeFromWishlistTooltip;
} else if (!wishlisted && waitlisted) {
text = L(__onWaitlist);
tooltip = L(__removeFromWaitlistTooltip);
tooltip = isDemoApp ? L(__removeFullgameFromWaitlistTooltip) : L(__removeFromWaitlistTooltip);
} else if (wishlisted && waitlisted) {
text = L(__onWishlistAndWaitlist);
tooltip = L(__removeFromWishlistAndWaitlistTooltip);
tooltip = isDemoApp ? L(__removeFullgameFromWishlistAndWaitlistTooltip) : L(__removeFromWishlistAndWaitlistTooltip);
} else {
tooltip = removeFromWishlistTooltip;
}
Expand Down Expand Up @@ -193,7 +215,7 @@ export default class FWaitlistDropdown extends Feature<CApp> {
}

if (waitlisted) {
await ITADApiFacade.removeFromWaitlist(this.context.appid);
await ITADApiFacade.removeFromWaitlist(appid);
waitlisted = !waitlisted;
}

Expand Down Expand Up @@ -224,14 +246,14 @@ export default class FWaitlistDropdown extends Feature<CApp> {

if (wishlisted) {
SteamFacade.removeFromWishlist(
this.context.appid,
appid,
"add_to_wishlist_area_success",
"add_to_wishlist_area",
"add_to_wishlist_area_fail"
);
} else {
SteamFacade.addToWishlist(
this.context.appid,
appid,
"add_to_wishlist_area",
"add_to_wishlist_area_success",
"add_to_wishlist_area_fail"
Expand All @@ -245,9 +267,9 @@ export default class FWaitlistDropdown extends Feature<CApp> {
parent.classList.add("loading");

if (waitlisted) {
await ITADApiFacade.removeFromWaitlist(this.context.appid);
await ITADApiFacade.removeFromWaitlist(appid);
} else {
await ITADApiFacade.addToWaitlist(this.context.appid);
await ITADApiFacade.addToWaitlist(appid);
}

waitlisted = !waitlisted;
Expand Down
4 changes: 4 additions & 0 deletions src/localization/compiled/_strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,13 @@ export const __drmThirdParty = "drmThirdParty";
export const __hoursShort = "hoursShort";
export const __spamCommentShow = "spamCommentShow";
export const __addToWishlist = "addToWishlist";
export const __addFullgameToWishlist = "addFullgameToWishlist";
export const __addToWaitlist = "addToWaitlist";
export const __addFullgameToWaitlist = "addFullgameToWaitlist";
export const __removeFromWaitlistTooltip = "removeFromWaitlistTooltip";
export const __removeFullgameFromWaitlistTooltip = "removeFullgameFromWaitlistTooltip";
export const __removeFromWishlistAndWaitlistTooltip = "removeFromWishlistAndWaitlistTooltip";
export const __removeFullgameFromWishlistAndWaitlistTooltip = "removeFullgameFromWishlistAndWaitlistTooltip";
export const __language = "language";
export const __theworddefault = "theworddefault";
export const __thewordclear = "thewordclear";
Expand Down
2 changes: 1 addition & 1 deletion src/localization/compiled/bg.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/localization/compiled/cs.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/localization/compiled/da.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/localization/compiled/de.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/localization/compiled/el.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/localization/compiled/en.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/localization/compiled/es-419.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/localization/compiled/es-ES.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/localization/compiled/fi.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/localization/compiled/fr.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/localization/compiled/hu.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/localization/compiled/it.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/localization/compiled/ja.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/localization/compiled/ko.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/localization/compiled/nl.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/localization/compiled/no.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/localization/compiled/pl.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/localization/compiled/pt-BR.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/localization/compiled/pt-PT.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/localization/compiled/ro.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/localization/compiled/ru.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/localization/compiled/sv-SE.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/localization/compiled/th.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/localization/compiled/tr.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/localization/compiled/ua.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/localization/compiled/vi.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/localization/compiled/zh-CN.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/localization/compiled/zh-TW.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/localization/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,13 @@
"hours_short": "__hours__ hrs",
"spam_comment_show": "__num__ spam comments hidden on this page. Click here to show them.",
"add_to_wishlist": "Add to your wishlist",
"add_fullgame_to_wishlist": "Add full game to your wishlist",
"add_to_waitlist": "Add to your Waitlist",
"add_fullgame_to_waitlist": "Add full game to your Waitlist",
"remove_from_waitlist_tooltip": "Remove from your Waitlist",
"remove_fullgame_from_waitlist_tooltip": "Remove full game from your Waitlist",
"remove_from_wishlist_and_waitlist_tooltip": "Remove from both your wishlist and Waitlist",
"remove_fullgame_from_wishlist_and_waitlist_tooltip": "Remove full game from both your wishlist and Waitlist",
"language": "Language",
"theworddefault": "Default",
"thewordclear": "Clear",
Expand Down

0 comments on commit 9614be1

Please sign in to comment.