mirror of
https://github.com/zimplexing/OrionTV.git
synced 2026-03-07 03:07:29 +08:00
feat: enhance LoginModal with TV event handling and input focus management
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { create } from "zustand";
|
||||
import Cookies from "@react-native-cookies/cookies";
|
||||
import { api } from "@/services/api";
|
||||
import { api, ServerConfig } from "@/services/api";
|
||||
|
||||
interface AuthState {
|
||||
isLoggedIn: boolean;
|
||||
@@ -22,23 +22,18 @@ const useAuthStore = create<AuthState>((set) => ({
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await api.login();
|
||||
set({ isLoginModalVisible: true });
|
||||
} catch {
|
||||
try {
|
||||
const cookies = await Cookies.get(api.baseURL);
|
||||
const isLoggedIn = cookies && !!cookies.auth;
|
||||
set({ isLoggedIn });
|
||||
if (!isLoggedIn) {
|
||||
set({ isLoginModalVisible: true });
|
||||
}
|
||||
} catch (error) {
|
||||
console.info("Failed to check login status:", error);
|
||||
if (error instanceof Error && error.message === "UNAUTHORIZED") {
|
||||
set({ isLoggedIn: false, isLoginModalVisible: true });
|
||||
} else {
|
||||
set({ isLoggedIn: false });
|
||||
}
|
||||
const cookies = await Cookies.get(api.baseURL);
|
||||
const isLoggedIn = cookies && !!cookies.auth;
|
||||
set({ isLoggedIn });
|
||||
if (!isLoggedIn) {
|
||||
set({ isLoginModalVisible: true });
|
||||
}
|
||||
} catch (error) {
|
||||
console.info("Failed to check login status:", error);
|
||||
if (error instanceof Error && error.message === "UNAUTHORIZED") {
|
||||
set({ isLoggedIn: false, isLoginModalVisible: true });
|
||||
} else {
|
||||
set({ isLoggedIn: false });
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -122,7 +122,7 @@ const useDetailStore = create<DetailState>((set, get) => ({
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn(`Failed to fetch from ${resource.name}:`, error);
|
||||
console.info(`Failed to fetch from ${resource.name}:`, error);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -133,11 +133,11 @@ const useDetailStore = create<DetailState>((set, get) => ({
|
||||
set({ error: "未找到任何播放源" });
|
||||
}
|
||||
|
||||
if (get().detail) {
|
||||
const { source, id } = get().detail!;
|
||||
const isFavorited = await FavoriteManager.isFavorited(source, id.toString());
|
||||
set({ isFavorited });
|
||||
}
|
||||
// if (get().detail) {
|
||||
// const { source, id } = get().detail!;
|
||||
// const isFavorited = await FavoriteManager.isFavorited(source, id.toString());
|
||||
// set({ isFavorited });
|
||||
// }
|
||||
} catch (e) {
|
||||
if ((e as Error).name !== "AbortError") {
|
||||
set({ error: e instanceof Error ? e.message : "获取数据失败" });
|
||||
@@ -151,9 +151,9 @@ const useDetailStore = create<DetailState>((set, get) => ({
|
||||
|
||||
setDetail: async (detail) => {
|
||||
set({ detail });
|
||||
const { source, id } = detail;
|
||||
const isFavorited = await FavoriteManager.isFavorited(source, id.toString());
|
||||
set({ isFavorited });
|
||||
// const { source, id } = detail;
|
||||
// const isFavorited = await FavoriteManager.isFavorited(source, id.toString());
|
||||
// set({ isFavorited });
|
||||
},
|
||||
|
||||
abort: () => {
|
||||
|
||||
Reference in New Issue
Block a user