feat: adding toast when signing in and out

This commit is contained in:
Chubby Granny Chaser 2024-06-20 22:02:11 +01:00
parent 633bb7820b
commit 9de7d4a61e
No known key found for this signature in database
10 changed files with 62 additions and 35 deletions

View File

@ -1,4 +1,7 @@
{ {
"app": {
"successfully_signed_in": "Successfully signed in"
},
"home": { "home": {
"featured": "Featured", "featured": "Featured",
"trending": "Trending", "trending": "Trending",
@ -243,6 +246,7 @@
"try_again": "Please, try again", "try_again": "Please, try again",
"signout_modal_title": "Are you sure?", "signout_modal_title": "Are you sure?",
"cancel": "Cancel", "cancel": "Cancel",
"signout": "Sign Out" "signout": "Sign Out",
"successfully_signed_out": "Successfully signed out"
} }
} }

View File

@ -1,4 +1,7 @@
{ {
"app": {
"successfully_signed_in": "Logado com sucesso"
},
"home": { "home": {
"featured": "Destaque", "featured": "Destaque",
"trending": "Populares", "trending": "Populares",
@ -243,6 +246,7 @@
"try_again": "Por favor, tente novamente", "try_again": "Por favor, tente novamente",
"cancel": "Cancelar", "cancel": "Cancelar",
"signout": "Sair da conta", "signout": "Sair da conta",
"signout_modal_title": "Tem certeza?" "signout_modal_title": "Tem certeza?",
"successfully_signed_out": "Deslogado com sucesso"
} }
} }

View File

@ -73,7 +73,7 @@ app.on("browser-window-created", (_, window) => {
optimizer.watchWindowShortcuts(window); optimizer.watchWindowShortcuts(window);
}); });
app.on("second-instance", (_event, commandLine) => { app.on("second-instance", (_event) => {
// Someone tried to run a second instance, we should focus our window. // Someone tried to run a second instance, we should focus our window.
if (WindowManager.mainWindow) { if (WindowManager.mainWindow) {
if (WindowManager.mainWindow.isMinimized()) if (WindowManager.mainWindow.isMinimized())
@ -84,16 +84,16 @@ app.on("second-instance", (_event, commandLine) => {
WindowManager.createMainWindow(); WindowManager.createMainWindow();
} }
const [, path] = commandLine.pop()?.split("://") ?? []; // const [, path] = commandLine.pop()?.split("://") ?? [];
if (path) { // if (path) {
WindowManager.redirect(path); // WindowManager.redirect(path);
} // }
}); });
app.on("open-url", (_event, url) => { // app.on("open-url", (_event, url) => {
const [, path] = url.split("://"); // const [, path] = url.split("://");
WindowManager.redirect(path); // WindowManager.redirect(path);
}); // });
// Quit when all windows are closed, except on macOS. There, it's common // Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits // for applications and their menu bar to stay active until the user quits

View File

@ -111,6 +111,6 @@ export const titleBar = style({
alignItems: "center", alignItems: "center",
padding: `0 ${SPACING_UNIT * 2}px`, padding: `0 ${SPACING_UNIT * 2}px`,
WebkitAppRegion: "drag", WebkitAppRegion: "drag",
zIndex: "2", zIndex: "4",
borderBottom: `1px solid ${vars.color.border}`, borderBottom: `1px solid ${vars.color.border}`,
} as ComplexStyleRule); } as ComplexStyleRule);

View File

@ -7,6 +7,7 @@ import {
useAppSelector, useAppSelector,
useDownload, useDownload,
useLibrary, useLibrary,
useToast,
useUserDetails, useUserDetails,
} from "@renderer/hooks"; } from "@renderer/hooks";
@ -22,6 +23,7 @@ import {
setUserDetails, setUserDetails,
setProfileBackground, setProfileBackground,
} from "@renderer/features"; } from "@renderer/features";
import { useTranslation } from "react-i18next";
export interface AppProps { export interface AppProps {
children: React.ReactNode; children: React.ReactNode;
@ -31,6 +33,8 @@ export function App() {
const contentRef = useRef<HTMLDivElement>(null); const contentRef = useRef<HTMLDivElement>(null);
const { updateLibrary } = useLibrary(); const { updateLibrary } = useLibrary();
const { t } = useTranslation("app");
const { clearDownload, setLastPacket } = useDownload(); const { clearDownload, setLastPacket } = useDownload();
const { fetchUserDetails, updateUserDetails, clearUserDetails } = const { fetchUserDetails, updateUserDetails, clearUserDetails } =
@ -49,6 +53,8 @@ export function App() {
const toast = useAppSelector((state) => state.toast); const toast = useAppSelector((state) => state.toast);
const { showSuccessToast } = useToast();
useEffect(() => { useEffect(() => {
Promise.all([window.electron.getUserPreferences(), updateLibrary()]).then( Promise.all([window.electron.getUserPreferences(), updateLibrary()]).then(
([preferences]) => { ([preferences]) => {
@ -95,25 +101,28 @@ export function App() {
}); });
}, [dispatch, fetchUserDetails]); }, [dispatch, fetchUserDetails]);
const onSignIn = useCallback(() => {
fetchUserDetails().then((response) => {
if (response) {
updateUserDetails(response);
showSuccessToast(t("successfully_signed_in"));
}
});
}, [fetchUserDetails, t, showSuccessToast, updateUserDetails]);
useEffect(() => { useEffect(() => {
const listeners = [ const listeners = [
window.electron.onSignIn(() => { window.electron.onSignIn(onSignIn),
fetchUserDetails().then((response) => {
if (response) updateUserDetails(response);
});
}),
window.electron.onLibraryBatchComplete(() => { window.electron.onLibraryBatchComplete(() => {
updateLibrary(); updateLibrary();
}), }),
window.electron.onSignOut(() => { window.electron.onSignOut(() => clearUserDetails()),
clearUserDetails();
}),
]; ];
return () => { return () => {
listeners.forEach((unsubscribe) => unsubscribe()); listeners.forEach((unsubscribe) => unsubscribe());
}; };
}, [fetchUserDetails, updateUserDetails, updateLibrary, clearUserDetails]); }, [onSignIn, updateLibrary, clearUserDetails]);
const handleSearch = useCallback( const handleSearch = useCallback(
(query: string) => { (query: string) => {
@ -167,6 +176,13 @@ export function App() {
</div> </div>
)} )}
<Toast
visible={toast.visible}
message={toast.message}
type={toast.type}
onClose={handleToastClose}
/>
<main> <main>
<Sidebar /> <Sidebar />
@ -184,13 +200,6 @@ export function App() {
</main> </main>
<BottomPanel /> <BottomPanel />
<Toast
visible={toast.visible}
message={toast.message}
type={toast.type}
onClose={handleToastClose}
/>
</> </>
); );
} }

View File

@ -1,7 +1,7 @@
import { keyframes } from "@vanilla-extract/css"; import { keyframes } from "@vanilla-extract/css";
import { recipe } from "@vanilla-extract/recipes"; import { recipe } from "@vanilla-extract/recipes";
import { SPACING_UNIT } from "../../theme.css"; import { SPACING_UNIT, vars } from "../../theme.css";
export const backdropFadeIn = keyframes({ export const backdropFadeIn = keyframes({
"0%": { backdropFilter: "blur(0px)", backgroundColor: "rgba(0, 0, 0, 0.5)" }, "0%": { backdropFilter: "blur(0px)", backgroundColor: "rgba(0, 0, 0, 0.5)" },
@ -30,8 +30,8 @@ export const backdrop = recipe({
display: "flex", display: "flex",
justifyContent: "center", justifyContent: "center",
alignItems: "center", alignItems: "center",
zIndex: 1, zIndex: vars.zIndex.backdrop,
top: 0, top: "0",
padding: `${SPACING_UNIT * 3}px`, padding: `${SPACING_UNIT * 3}px`,
backdropFilter: "blur(2px)", backdropFilter: "blur(2px)",
transition: "all ease 0.2s", transition: "all ease 0.2s",

View File

@ -12,7 +12,7 @@ export const bottomPanel = style({
transition: "all ease 0.2s", transition: "all ease 0.2s",
justifyContent: "space-between", justifyContent: "space-between",
position: "relative", position: "relative",
zIndex: "1", zIndex: vars.zIndex.bottomPanel,
}); });
export const downloadsButton = style({ export const downloadsButton = style({

View File

@ -31,7 +31,7 @@ export const toast = recipe({
display: "flex", display: "flex",
flexDirection: "column", flexDirection: "column",
justifyContent: "space-between", justifyContent: "space-between",
zIndex: "0", zIndex: vars.zIndex.toast,
maxWidth: "500px", maxWidth: "500px",
}, },
variants: { variants: {

View File

@ -6,7 +6,7 @@ import { SPACING_UNIT, vars } from "@renderer/theme.css";
import { useMemo, useState } from "react"; import { useMemo, useState } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import SteamLogo from "@renderer/assets/steam-logo.svg?react"; import SteamLogo from "@renderer/assets/steam-logo.svg?react";
import { useDate, useUserDetails } from "@renderer/hooks"; import { useDate, useToast, useUserDetails } from "@renderer/hooks";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import { buildGameDetailsPath } from "@renderer/helpers"; import { buildGameDetailsPath } from "@renderer/helpers";
import { PersonIcon, TelescopeIcon } from "@primer/octicons-react"; import { PersonIcon, TelescopeIcon } from "@primer/octicons-react";
@ -28,6 +28,7 @@ export function UserContent({
const { t, i18n } = useTranslation("user_profile"); const { t, i18n } = useTranslation("user_profile");
const { userDetails, profileBackground, signOut } = useUserDetails(); const { userDetails, profileBackground, signOut } = useUserDetails();
const { showSuccessToast } = useToast();
const [showEditProfileModal, setShowEditProfileModal] = useState(false); const [showEditProfileModal, setShowEditProfileModal] = useState(false);
const [showSignOutModal, setShowSignOutModal] = useState(false); const [showSignOutModal, setShowSignOutModal] = useState(false);
@ -68,7 +69,10 @@ export function UserContent({
}; };
const handleConfirmSignout = async () => { const handleConfirmSignout = async () => {
signOut(); await signOut();
showSuccessToast(t("successfully_signed_out"));
navigate("/"); navigate("/");
}; };

View File

@ -21,4 +21,10 @@ export const vars = createGlobalTheme(":root", {
body: "14px", body: "14px",
small: "12px", small: "12px",
}, },
zIndex: {
toast: "2",
bottomPanel: "3",
titleBar: "4",
backdrop: "4",
},
}); });