Skip to content

Commit 5778122

Browse files
committed
login spinner
1 parent a74538d commit 5778122

6 files changed

Lines changed: 38 additions & 10 deletions

File tree

src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ const AppContent = () => {
100100
} = useWine();
101101

102102
const byondLoginVisible = useByondStore((s) => s.loginVisible);
103+
const byondLoggingIn = useByondStore((s) => s.loggingIn);
103104

104105
const [settingsVisible, setSettingsVisible] = useState(false);
105106
const [relayDropdownOpen, setRelayDropdownOpen] = useState(false);
@@ -198,6 +199,7 @@ const AppContent = () => {
198199
)}
199200
<ByondLoginModal
200201
visible={byondLoginVisible}
202+
loggingIn={byondLoggingIn}
201203
onClose={() => commands.cancelByondLogin()}
202204
/>
203205
{config?.features.direct_connect && (

src/components/ByondLoginModal.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
import { useTranslation } from "react-i18next";
2-
import { Modal, ModalCloseButton } from "./Modal";
2+
import { Modal, ModalCloseButton, ModalSpinner } from "./Modal";
33

44
interface ByondLoginModalProps {
55
visible: boolean;
6+
loggingIn: boolean;
67
onClose: () => void;
78
}
89

9-
export const ByondLoginModal = ({ visible, onClose }: ByondLoginModalProps) => {
10+
export const ByondLoginModal = ({ visible, loggingIn, onClose }: ByondLoginModalProps) => {
1011
const { t } = useTranslation();
12+
const showSpinner = !visible && loggingIn;
1113

1214
return (
13-
<Modal visible={visible} onClose={onClose} className="auth-modal byond-login-modal" closeOnOverlayClick>
15+
<Modal visible={visible || showSpinner} onClose={onClose} className="auth-modal byond-login-modal" closeOnOverlayClick={showSpinner}>
1416
<ModalCloseButton onClick={onClose} />
1517
<h2>{t("settings.loginToByond")}</h2>
18+
{showSpinner && (
19+
<div className="byond-login-spinner">
20+
<p>{t("settings.byondWaiting")}</p>
21+
<ModalSpinner />
22+
</div>
23+
)}
1624
</Modal>
1725
);
1826
};

src/hooks/useAuthHandlers.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,21 @@ export function useAuthHandlers() {
4646
}
4747
}, [logout, showError]);
4848

49+
const setLoggingIn = useByondStore((s) => s.setLoggingIn);
4950
const handleByondLogin = useCallback(async () => {
50-
const result = await commands.startByondLogin();
51-
if (result.status === "error") {
52-
if (result.error.type === "cancelled") return;
53-
try { unwrap(result); } catch (err) {
54-
showError(err instanceof Error ? err.message : String(err));
51+
setLoggingIn(true);
52+
try {
53+
const result = await commands.startByondLogin();
54+
if (result.status === "error") {
55+
if (result.error.type === "cancelled") return;
56+
try { unwrap(result); } catch (err) {
57+
showError(err instanceof Error ? err.message : String(err));
58+
}
5559
}
60+
} finally {
61+
setLoggingIn(false);
5662
}
57-
}, [showError]);
63+
}, [showError, setLoggingIn]);
5864

5965
const setLoggingOut = useByondStore((s) => s.setLoggingOut);
6066
const handleByondLogout = useCallback(async () => {

src/i18n/locales/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
"reportIssue": "Report an issue",
100100
"loginToByond": "BYOND Login",
101101
"byondPagerWarning": "BYOND pager is not running. You can either open BYOND and log in, or use web login below.",
102-
"byondWaiting": "Waiting for BYOND login... (check the login window)",
102+
"byondWaiting": "Logging in to BYOND...",
103103
"byondSuccess": "Logged in to BYOND successfully!",
104104
"byondLoginFailed": "Login failed: {{error}}",
105105
"language": "Language",

src/stores/byondStore.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ interface ByondStore {
77
username: string | null;
88
pagerRunning: boolean | null;
99
loginVisible: boolean;
10+
loggingIn: boolean;
1011
loggingOut: boolean;
1112
setUsername: (username: string | null) => void;
1213
setPagerRunning: (running: boolean | null) => void;
14+
setLoggingIn: (loggingIn: boolean) => void;
1315
setLoggingOut: (loggingOut: boolean) => void;
1416
checkStatus: () => Promise<void>;
1517
checkSession: () => Promise<void>;
@@ -20,10 +22,12 @@ export const useByondStore = create<ByondStore>()((set) => ({
2022
username: null,
2123
pagerRunning: null,
2224
loginVisible: false,
25+
loggingIn: false,
2326
loggingOut: false,
2427

2528
setUsername: (username) => set({ username }),
2629
setPagerRunning: (pagerRunning) => set({ pagerRunning }),
30+
setLoggingIn: (loggingIn) => set({ loggingIn }),
2731
setLoggingOut: (loggingOut) => set({ loggingOut }),
2832

2933
checkStatus: async () => {

src/styles/base.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,14 @@ body {
11471147
align-items: center;
11481148
justify-content: flex-start;
11491149
padding-top: 16px;
1150+
1151+
.byond-login-spinner {
1152+
flex: 1;
1153+
display: flex;
1154+
flex-direction: column;
1155+
align-items: center;
1156+
justify-content: center;
1157+
}
11501158
}
11511159

11521160
h2 {

0 commit comments

Comments
 (0)