mirror of
https://github.com/zimplexing/OrionTV.git
synced 2026-05-22 10:07:34 +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 { StyledButton } from "@/components/StyledButton";
|
||||||
import useHomeStore, { RowItem, Category } from "@/stores/homeStore";
|
import useHomeStore, { RowItem, Category } from "@/stores/homeStore";
|
||||||
import useAuthStore from "@/stores/authStore";
|
import useAuthStore from "@/stores/authStore";
|
||||||
|
import { useSettingsStore } from "@/stores/settingsStore";
|
||||||
import CustomScrollView from "@/components/CustomScrollView";
|
import CustomScrollView from "@/components/CustomScrollView";
|
||||||
import { useResponsiveLayout } from "@/hooks/useResponsiveLayout";
|
import { useResponsiveLayout } from "@/hooks/useResponsiveLayout";
|
||||||
import { getCommonResponsiveStyles } from "@/utils/ResponsiveStyles";
|
import { getCommonResponsiveStyles } from "@/utils/ResponsiveStyles";
|
||||||
@@ -40,8 +41,10 @@ export default function HomeScreen() {
|
|||||||
loadMoreData,
|
loadMoreData,
|
||||||
selectCategory,
|
selectCategory,
|
||||||
refreshPlayRecords,
|
refreshPlayRecords,
|
||||||
|
clearError,
|
||||||
} = useHomeStore();
|
} = useHomeStore();
|
||||||
const { isLoggedIn, logout } = useAuthStore();
|
const { isLoggedIn, logout } = useAuthStore();
|
||||||
|
const { apiBaseUrl } = useSettingsStore();
|
||||||
|
|
||||||
useFocusEffect(
|
useFocusEffect(
|
||||||
useCallback(() => {
|
useCallback(() => {
|
||||||
@@ -50,20 +53,33 @@ export default function HomeScreen() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedCategory && !selectedCategory.tags) {
|
// 只有在 apiBaseUrl 存在时才调用 fetchInitialData,避免时序问题
|
||||||
|
if (selectedCategory && !selectedCategory.tags && apiBaseUrl) {
|
||||||
fetchInitialData();
|
fetchInitialData();
|
||||||
} else if (selectedCategory?.tags && !selectedCategory.tag) {
|
} else if (selectedCategory?.tags && !selectedCategory.tag) {
|
||||||
const defaultTag = selectedCategory.tags[0];
|
const defaultTag = selectedCategory.tags[0];
|
||||||
setSelectedTag(defaultTag);
|
setSelectedTag(defaultTag);
|
||||||
selectCategory({ ...selectedCategory, tag: defaultTag });
|
selectCategory({ ...selectedCategory, tag: defaultTag });
|
||||||
}
|
}
|
||||||
}, [selectedCategory, fetchInitialData, selectCategory]);
|
}, [selectedCategory, fetchInitialData, selectCategory, apiBaseUrl]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedCategory && selectedCategory.tag) {
|
// 只有在 apiBaseUrl 存在时才调用 fetchInitialData,避免时序问题
|
||||||
|
if (selectedCategory && selectedCategory.tag && apiBaseUrl) {
|
||||||
fetchInitialData();
|
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(() => {
|
useEffect(() => {
|
||||||
if (!loading && contentData.length > 0) {
|
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}>
|
<View style={commonStyles.center}>
|
||||||
<ActivityIndicator size="large" />
|
<ActivityIndicator size="large" />
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ export const UPDATE_CONFIG = {
|
|||||||
CHECK_INTERVAL: 12 * 60 * 60 * 1000, // 12小时
|
CHECK_INTERVAL: 12 * 60 * 60 * 1000, // 12小时
|
||||||
|
|
||||||
// GitHub相关URL
|
// GitHub相关URL
|
||||||
GITHUB_RAW_URL: 'https://raw.githubusercontent.com/zimplexing/OrionTV/refs/heads/master/package.json',
|
GITHUB_RAW_URL: 'https://ghfast.top/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_RELEASE_URL_TEMPLATE: 'https://ghfast.top/https://github.com/zimplexing/OrionTV/releases/download/v{version}/orionTV.{version}.apk',
|
||||||
|
|
||||||
// 是否显示更新日志
|
// 是否显示更新日志
|
||||||
SHOW_RELEASE_NOTES: true,
|
SHOW_RELEASE_NOTES: true,
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ interface HomeState {
|
|||||||
loadMoreData: () => Promise<void>;
|
loadMoreData: () => Promise<void>;
|
||||||
selectCategory: (category: Category) => void;
|
selectCategory: (category: Category) => void;
|
||||||
refreshPlayRecords: () => Promise<void>;
|
refreshPlayRecords: () => Promise<void>;
|
||||||
|
clearError: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 内存缓存,应用生命周期内有效
|
// 内存缓存,应用生命周期内有效
|
||||||
@@ -261,6 +262,10 @@ const useHomeStore = create<HomeState>((set, get) => ({
|
|||||||
|
|
||||||
get().fetchInitialData();
|
get().fetchInitialData();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
clearError: () => {
|
||||||
|
set({ error: null });
|
||||||
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export default useHomeStore;
|
export default useHomeStore;
|
||||||
|
|||||||
Reference in New Issue
Block a user