mirror of
https://github.com/ilyhalight/voice-over-translation.git
synced 2026-10-19 07:43:33 +00:00
chore: added isRefreshing state for account refresh button
This commit is contained in:
parent
af895862cc
commit
244ef76e8a
5 changed files with 16 additions and 7 deletions
|
|
@ -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) => {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue