chore: added isRefreshing state for account refresh button

This commit is contained in:
Toil 2026-09-22 00:19:44 +03:00
parent af895862cc
commit 244ef76e8a
No known key found for this signature in database
GPG key ID: 57248E2819D32070
5 changed files with 16 additions and 7 deletions

View file

@ -1,7 +1,8 @@
import { type JSX, mergeProps } from "solid-js";
import { produce } from "solid-js/store";
import "./AccountLogin.scss";
import { produce } from "solid-js/store";
import { YANDEX_TOKEN_DEFAULT_LIFETIME } from "../../config/auth";
import { t } from "../../localization/localizationProvider";
import { setAccount } from "../../stores/account";
import { votStorage } from "../../utils/storage";
@ -15,8 +16,6 @@ export type AccountLoginProps = {
onClickLogin?: () => void;
};
const TOKEN_LIFETIME = 31_534_180_000; // 1 year in milliseconds
export function AccountLogin(props: AccountLoginProps): JSX.Element {
const finalProps = mergeProps(
{ disableExternalLogin: votStorage.isSupportOnlyLS },
@ -50,12 +49,11 @@ export function AccountLogin(props: AccountLoginProps): JSX.Element {
const data = value
? {
token: value,
expires: Date.now() + TOKEN_LIFETIME,
expires: Date.now() + YANDEX_TOKEN_DEFAULT_LIFETIME,
}
: {};
const isLoggedIn = Boolean(value);
// TODO: add get account info via token and set username and avatarId
await votStorage.set("account", { ...data });
setAccount(
produce((state) => {

View file

@ -1,7 +1,7 @@
import type { JSX } from "solid-js";
import { updateAccountInfo } from "../../core/auth/yandex";
import { t } from "../../localization/localizationProvider";
import { updateAccountFromStorage } from "../../stores/account";
import { account, updateAccountFromStorage } from "../../stores/account";
import { IconButton } from "../Button/IconButton";
import { RefreshIcon } from "../Icons/RefreshIcon";
@ -16,7 +16,12 @@ export function AccountRefreshButton(
<IconButton
ref={props.ref}
ariaLabel={t("VOTRefresh")}
disabled={account.isRefreshing}
onClick={async () => {
if (account.isRefreshing) {
return;
}
try {
await updateAccountInfo();
} catch {

View file

@ -6,3 +6,4 @@ export const YANDEX_AUTH_TOKEN_URL = `${YANDEX_AUTH_ORIGIN}/token`;
export const YANDEX_AUTH_AVATAR_BASE =
"https://avatars.mds.yandex.net/get-yapic";
export const YANDEX_USER_INFO_URL = "https://login.yandex.ru/info";
export const YANDEX_TOKEN_DEFAULT_LIFETIME = 31_534_180_000; // 1 year in milliseconds

View file

@ -7,7 +7,7 @@ import {
YANDEX_AUTH_URL,
YANDEX_USER_INFO_URL,
} from "../../config/auth";
import { updateAccount } from "../../stores/account";
import { setAccount, updateAccount } from "../../stores/account";
import type { AuthMessageData } from "../../types/core/auth/message";
import type {
AuthError,
@ -105,6 +105,7 @@ export async function updateAccountInfo() {
let username: string;
let avatarId: string;
try {
setAccount("isRefreshing", true);
const userInfo = await getUserInfo(account.token);
username = userInfo.login;
avatarId = userInfo.default_avatar_id;
@ -120,6 +121,8 @@ export async function updateAccountInfo() {
});
} catch (err) {
console.error("[VOT] Failed to fetch user info:", err);
} finally {
setAccount("isRefreshing", false);
}
}

View file

@ -4,6 +4,7 @@ import { hasValidAccountToken } from "../utils/account";
import { votStorage } from "../utils/storage";
export type AccountStore = {
isRefreshing: boolean;
isLoggedIn: boolean;
username?: string;
avatarId?: string;
@ -13,6 +14,7 @@ export type AccountStore = {
function createInitialState(): AccountStore {
return {
isRefreshing: false,
isLoggedIn: false,
username: undefined,
avatarId: undefined,