fix: migrating hltb to api

This commit is contained in:
Chubby Granny Chaser 2024-12-02 17:58:13 +00:00
parent 7f600a0cbf
commit 0fc6d69851
No known key found for this signature in database
14 changed files with 85 additions and 173 deletions

View file

@ -8,10 +8,6 @@
http-equiv="Content-Security-Policy"
content="default-src 'self' 'unsafe-inline' *;"
/>
<script
type="text/javascript"
src="%RENDERER_VITE_EXTERNAL_RESOURCES_URL%"
></script>
</head>
<body>
<div id="root"></div>

View file

@ -62,25 +62,6 @@ export function App() {
clearUserDetails,
} = useUserDetails();
useEffect(() => {
if (userDetails) {
const $existingScript = document.getElementById("user-details");
const content = `window.userDetails = ${JSON.stringify(userDetails)};`;
if ($existingScript) {
$existingScript.textContent = content;
} else {
const $script = document.createElement("script");
$script.id = "user-details";
$script.type = "text/javascript";
$script.textContent = content;
document.head.appendChild($script);
}
}
}, [userDetails]);
const dispatch = useAppDispatch();
const navigate = useNavigate();
@ -133,12 +114,33 @@ export function App() {
dispatch(setProfileBackground(profileBackground));
}
fetchUserDetails().then((response) => {
if (response) {
updateUserDetails(response);
syncFriendRequests();
}
});
fetchUserDetails()
.then((response) => {
if (response) {
updateUserDetails(response);
syncFriendRequests();
const $existingScript = document.getElementById("user-details");
const content = `window.userDetails = ${JSON.stringify(response)};`;
if ($existingScript) {
$existingScript.textContent = content;
} else {
const $script = document.createElement("script");
$script.id = "user-details";
$script.type = "text/javascript";
$script.textContent = content;
document.head.appendChild($script);
}
}
})
.finally(() => {
const $script = document.createElement("script");
$script.src = import.meta.env.RENDERER_VITE_EXTERNAL_RESOURCES_URL;
document.head.appendChild($script);
});
}, [fetchUserDetails, syncFriendRequests, updateUserDetails, dispatch]);
const onSignIn = useCallback(() => {

View file

@ -181,6 +181,7 @@ export function GameDetailsContextProvider({
shop,
i18n.language,
userDetails,
userPreferences,
]);
useEffect(() => {

View file

@ -60,7 +60,8 @@ declare global {
) => Promise<ShopDetails | null>;
getRandomGame: () => Promise<Steam250Game>;
getHowLongToBeat: (
title: string
objectId: string,
shop: GameShop
) => Promise<HowLongToBeatCategory[] | null>;
getGames: (take?: number, skip?: number) => Promise<CatalogueEntry[]>;
searchGameRepacks: (query: string) => Promise<GameRepack[]>;
@ -162,6 +163,7 @@ declare global {
openExternal: (src: string) => Promise<void>;
openCheckout: () => Promise<void>;
getVersion: () => Promise<string>;
isStaging: () => Promise<boolean>;
ping: () => string;
getDefaultDownloadsPath: () => Promise<string>;
isPortableVersion: () => Promise<boolean>;
@ -231,8 +233,6 @@ declare global {
/* Notifications */
publishNewRepacksNotification: (newRepacksCount: number) => Promise<void>;
isStaging: boolean;
}
interface Window {

View file

@ -97,8 +97,10 @@ export function Sidebar() {
});
} else {
try {
const howLongToBeat =
await window.electron.getHowLongToBeat(gameTitle);
const howLongToBeat = await window.electron.getHowLongToBeat(
objectId,
shop
);
if (howLongToBeat) {
howLongToBeatEntriesTable.add({

View file

@ -45,22 +45,25 @@ export function ProfileContent() {
return userProfile?.relation?.status === "ACCEPTED";
}, [userProfile]);
const buildUserGameDetailsPath = (game: UserGame) => {
if (!userProfile?.hasActiveSubscription || game.achievementCount === 0) {
return buildGameDetailsPath({
...game,
objectId: game.objectId,
});
}
const buildUserGameDetailsPath = useCallback(
(game: UserGame) => {
if (!userProfile?.hasActiveSubscription || game.achievementCount === 0) {
return buildGameDetailsPath({
...game,
objectId: game.objectId,
});
}
const userParams = userProfile
? {
userId: userProfile.id,
}
: undefined;
const userParams = userProfile
? {
userId: userProfile.id,
}
: undefined;
return buildGameAchievementPath({ ...game }, userParams);
};
return buildGameAchievementPath({ ...game }, userParams);
},
[userProfile]
);
const formatPlayTime = useCallback(
(playTimeInSeconds = 0) => {
@ -259,6 +262,7 @@ export function ProfileContent() {
userStats,
numberFormatter,
t,
buildUserGameDetailsPath,
formatPlayTime,
navigate,
]);

View file

@ -1,2 +1,10 @@
/// <reference types="vite/client" />
/// <reference types="vite-plugin-svgr/client" />
interface ImportMetaEnv {
readonly RENDERER_VITE_EXTERNAL_RESOURCES_URL: string;
}
interface ImportMeta {
readonly env: ImportMetaEnv;
}