mirror of
https://github.com/zimplexing/OrionTV.git
synced 2026-02-04 03:36:29 +08:00
feat(home): enhance HomeScreen with API configuration checks and error handling
This commit is contained in:
@@ -10,6 +10,7 @@ import { Search, Settings, LogOut, Heart } from "lucide-react-native";
|
||||
import { StyledButton } from "@/components/StyledButton";
|
||||
import useHomeStore, { RowItem, Category } from "@/stores/homeStore";
|
||||
import useAuthStore from "@/stores/authStore";
|
||||
import { useSettingsStore } from "@/stores/settingsStore";
|
||||
import CustomScrollView from "@/components/CustomScrollView";
|
||||
import { useResponsiveLayout } from "@/hooks/useResponsiveLayout";
|
||||
import { getCommonResponsiveStyles } from "@/utils/ResponsiveStyles";
|
||||
@@ -40,8 +41,10 @@ export default function HomeScreen() {
|
||||
loadMoreData,
|
||||
selectCategory,
|
||||
refreshPlayRecords,
|
||||
clearError,
|
||||
} = useHomeStore();
|
||||
const { isLoggedIn, logout } = useAuthStore();
|
||||
const { apiBaseUrl } = useSettingsStore();
|
||||
|
||||
useFocusEffect(
|
||||
useCallback(() => {
|
||||
@@ -50,20 +53,33 @@ export default function HomeScreen() {
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (selectedCategory && !selectedCategory.tags) {
|
||||
// 只有在 apiBaseUrl 存在时才调用 fetchInitialData,避免时序问题
|
||||
if (selectedCategory && !selectedCategory.tags && apiBaseUrl) {
|
||||
fetchInitialData();
|
||||
} else if (selectedCategory?.tags && !selectedCategory.tag) {
|
||||
const defaultTag = selectedCategory.tags[0];
|
||||
setSelectedTag(defaultTag);
|
||||
selectCategory({ ...selectedCategory, tag: defaultTag });
|
||||
}
|
||||
}, [selectedCategory, fetchInitialData, selectCategory]);
|
||||
}, [selectedCategory, fetchInitialData, selectCategory, apiBaseUrl]);
|
||||
|
||||
useEffect(() => {
|
||||
if (selectedCategory && selectedCategory.tag) {
|
||||
// 只有在 apiBaseUrl 存在时才调用 fetchInitialData,避免时序问题
|
||||
if (selectedCategory && selectedCategory.tag && apiBaseUrl) {
|
||||
fetchInitialData();
|
||||
}
|
||||
}, [fetchInitialData, selectedCategory, selectedCategory.tag]);
|
||||
}, [fetchInitialData, selectedCategory, selectedCategory.tag, apiBaseUrl]);
|
||||
|
||||
// 检查是否需要显示API配置提示
|
||||
const shouldShowApiConfig = !apiBaseUrl && selectedCategory && !selectedCategory.tags;
|
||||
|
||||
// 清除错误状态,当API未配置时
|
||||
useEffect(() => {
|
||||
if (shouldShowApiConfig && error) {
|
||||
// 如果需要显示API配置提示,清除之前的错误状态
|
||||
clearError();
|
||||
}
|
||||
}, [shouldShowApiConfig, error, clearError]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!loading && contentData.length > 0) {
|
||||
@@ -262,7 +278,13 @@ export default function HomeScreen() {
|
||||
)}
|
||||
|
||||
{/* 内容网格 */}
|
||||
{loading ? (
|
||||
{shouldShowApiConfig ? (
|
||||
<View style={commonStyles.center}>
|
||||
<ThemedText type="subtitle" style={{ padding: spacing, textAlign: 'center' }}>
|
||||
请点击右上角设置按钮,配置您的服务器地址
|
||||
</ThemedText>
|
||||
</View>
|
||||
) : loading ? (
|
||||
<View style={commonStyles.center}>
|
||||
<ActivityIndicator size="large" />
|
||||
</View>
|
||||
|
||||
@@ -6,8 +6,8 @@ export const UPDATE_CONFIG = {
|
||||
CHECK_INTERVAL: 12 * 60 * 60 * 1000, // 12小时
|
||||
|
||||
// GitHub相关URL
|
||||
GITHUB_RAW_URL: 'https://raw.githubusercontent.com/zimplexing/OrionTV/refs/heads/master/package.json',
|
||||
GITHUB_RELEASE_URL_TEMPLATE: 'https://github.com/zimplexing/OrionTV/releases/download/v{version}/orionTV.{version}.apk',
|
||||
GITHUB_RAW_URL: 'https://ghfast.top/https://raw.githubusercontent.com/zimplexing/OrionTV/refs/heads/master/package.json',
|
||||
GITHUB_RELEASE_URL_TEMPLATE: 'https://ghfast.top/https://github.com/zimplexing/OrionTV/releases/download/v{version}/orionTV.{version}.apk',
|
||||
|
||||
// 是否显示更新日志
|
||||
SHOW_RELEASE_NOTES: true,
|
||||
|
||||
@@ -68,6 +68,7 @@ interface HomeState {
|
||||
loadMoreData: () => Promise<void>;
|
||||
selectCategory: (category: Category) => void;
|
||||
refreshPlayRecords: () => Promise<void>;
|
||||
clearError: () => void;
|
||||
}
|
||||
|
||||
// 内存缓存,应用生命周期内有效
|
||||
@@ -261,6 +262,10 @@ const useHomeStore = create<HomeState>((set, get) => ({
|
||||
|
||||
get().fetchInitialData();
|
||||
},
|
||||
|
||||
clearError: () => {
|
||||
set({ error: null });
|
||||
},
|
||||
}));
|
||||
|
||||
export default useHomeStore;
|
||||
|
||||
Reference in New Issue
Block a user