为多个组件和API添加用户登录状态检查,确保只有在用户登录后才能查询和修改收藏状态
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { ThemedText } from "@/components/themed-text";
|
||||
import { IconSymbol } from "@/components/ui/icon-symbol";
|
||||
import { addFavorite, checkFavorite, removeFavorite } from "@/lib/api";
|
||||
import { storage } from "@/lib/storage";
|
||||
import { LiveScoreMatch } from "@/types/api";
|
||||
import { LinearGradient } from "expo-linear-gradient";
|
||||
import { useRouter } from "expo-router";
|
||||
@@ -46,6 +47,8 @@ export function LiveScoreHeader({ match, topInset }: LiveScoreHeaderProps) {
|
||||
// 检查收藏状态
|
||||
React.useEffect(() => {
|
||||
const loadFavStatus = async () => {
|
||||
const token = await storage.getAccessToken();
|
||||
if (!token) return;
|
||||
try {
|
||||
const res = await checkFavorite("match", match.event_key.toString());
|
||||
setIsFav(res.isFavorite);
|
||||
@@ -59,6 +62,8 @@ export function LiveScoreHeader({ match, topInset }: LiveScoreHeaderProps) {
|
||||
// 检查主队收藏状态
|
||||
React.useEffect(() => {
|
||||
const loadHomeFav = async () => {
|
||||
const token = await storage.getAccessToken();
|
||||
if (!token) return;
|
||||
try {
|
||||
const res = await checkFavorite("team", match.home_team_key.toString());
|
||||
setIsHomeFav(res.isFavorite);
|
||||
@@ -74,6 +79,8 @@ export function LiveScoreHeader({ match, topInset }: LiveScoreHeaderProps) {
|
||||
// 检查客队收藏状态
|
||||
React.useEffect(() => {
|
||||
const loadAwayFav = async () => {
|
||||
const token = await storage.getAccessToken();
|
||||
if (!token) return;
|
||||
try {
|
||||
const res = await checkFavorite("team", match.away_team_key.toString());
|
||||
setIsAwayFav(res.isFavorite);
|
||||
|
||||
Reference in New Issue
Block a user