feat: refactor open auth

This commit is contained in:
Zamitto
2025-01-15 23:56:37 -03:00
parent 9941460c60
commit 44fd971c95
13 changed files with 47 additions and 57 deletions

View File

@@ -7,6 +7,7 @@ import { useTranslation } from "react-i18next";
import { UserFriendModalTab } from "@renderer/pages/shared-modals/user-friend-modal";
import SteamLogo from "@renderer/assets/steam-logo.svg?react";
import { Avatar } from "../avatar/avatar";
import { AuthPage } from "@shared";
const LONG_POLLING_INTERVAL = 120_000;
@@ -26,11 +27,11 @@ export function SidebarProfile() {
const handleProfileClick = () => {
if (userDetails === null) {
window.electron.openAuthWindow();
window.electron.openAuthWindow(AuthPage.SignIn);
return;
}
navigate(`/profile/${userDetails!.id}`);
navigate(`/profile/${userDetails.id}`);
};
useEffect(() => {

View File

@@ -1,4 +1,4 @@
import type { CatalogueCategory } from "@shared";
import type { AuthPage, CatalogueCategory } from "@shared";
import type {
AppUpdaterEvent,
Game,
@@ -29,7 +29,6 @@ import type {
UserAchievement,
ComparedAchievements,
CatalogueSearchPayload,
ManageAccountPage,
} from "@types";
import type { AxiosProgressEvent } from "axios";
import type disk from "diskusage";
@@ -188,7 +187,6 @@ declare global {
/* Misc */
openExternal: (src: string) => Promise<void>;
openCheckout: () => Promise<void>;
openManageAccount: (page: ManageAccountPage) => Promise<void>;
getVersion: () => Promise<string>;
isStaging: () => Promise<boolean>;
ping: () => string;
@@ -210,7 +208,7 @@ declare global {
/* Auth */
signOut: () => Promise<void>;
openAuthWindow: () => Promise<void>;
openAuthWindow: (page: AuthPage) => Promise<void>;
getSessionHash: () => Promise<string | null>;
onSignIn: (cb: () => void) => () => Electron.IpcRenderer;
onSignOut: (cb: () => void) => () => Electron.IpcRenderer;

View File

@@ -10,7 +10,7 @@ import { Sidebar } from "./sidebar/sidebar";
import * as styles from "./game-details.css";
import { useTranslation } from "react-i18next";
import { cloudSyncContext, gameDetailsContext } from "@renderer/context";
import { steamUrlBuilder } from "@shared";
import { AuthPage, steamUrlBuilder } from "@shared";
import cloudIconAnimated from "@renderer/assets/icons/cloud-animated.gif";
import { useUserDetails } from "@renderer/hooks";
@@ -69,7 +69,7 @@ export function GameDetailsContent() {
});
const backgroundColor = output
? (new Color(output).darken(0.7).toString() as string)
? new Color(output).darken(0.7).toString()
: "";
setGameColor(backgroundColor);
@@ -101,7 +101,7 @@ export function GameDetailsContent() {
const handleCloudSaveButtonClick = () => {
if (!userDetails) {
window.electron.openAuthWindow();
window.electron.openAuthWindow(AuthPage.SignIn);
return;
}

View File

@@ -13,6 +13,7 @@ import {
XCircleFillIcon,
} from "@primer/octicons-react";
import { settingsContext } from "@renderer/context";
import { AuthPage } from "@shared";
interface FormValues {
profileVisibility: "PUBLIC" | "FRIENDS" | "PRIVATE";
@@ -128,7 +129,7 @@ export function SettingsAccount() {
<p>{userDetails.email}</p>
</div>
) : (
<p>{t("no_associated_email")}</p>
<p>{t("no_email_account")}</p>
)}
<div
@@ -142,7 +143,7 @@ export function SettingsAccount() {
>
<Button
theme="outline"
onClick={() => window.electron.openManageAccount("update-email")}
onClick={() => window.electron.openAuthWindow(AuthPage.UpdateEmail)}
>
{t("update_email")}
<MailIcon />
@@ -150,7 +151,9 @@ export function SettingsAccount() {
<Button
theme="outline"
onClick={() => window.electron.openManageAccount("update-password")}
onClick={() =>
window.electron.openAuthWindow(AuthPage.UpdatePassword)
}
>
{t("update_password")}
<KeyIcon />