添加角球设置功能,更新状态管理和界面显示逻辑

This commit is contained in:
yuchenglong
2026-01-20 13:56:58 +08:00
parent fa13b3c17d
commit bb3cb3b821
6 changed files with 151 additions and 5 deletions

View File

@@ -38,6 +38,7 @@ export function MatchCard({
const oddsSettings = state.oddsSettings;
const cardsSettings = state.cardsSettings;
const cornerSettings = state.cornerSettings;
useEffect(() => {
if (
@@ -59,9 +60,13 @@ export function MatchCard({
match.odds,
]);
// Fetch live score detail for cards info
// Fetch live score detail for cards and corners info
useEffect(() => {
if (cardsSettings.enabled && isLive && match.leagueKey) {
if (
(cardsSettings.enabled || cornerSettings.enabled) &&
isLive &&
match.leagueKey
) {
fetchLiveScore(match.sportId || 1, Number(match.leagueKey))
.then((matches) => {
const detail = matches.find((m) => String(m.event_key) === match.id);
@@ -71,7 +76,13 @@ export function MatchCard({
})
.catch((err) => console.log("Fetch live detail for cards error:", err));
}
}, [cardsSettings.enabled, match.id, match.leagueKey, match.sportId]);
}, [
cardsSettings.enabled,
cornerSettings.enabled,
match.id,
match.leagueKey,
match.sportId,
]);
// 当外部传入的 match.fav 改变时,更新内部状态
useEffect(() => {
@@ -158,6 +169,26 @@ export function MatchCard({
return { homeYellow, homeRed, awayYellow, awayRed };
}, [liveDetail, cardsSettings.enabled]);
const extraStats = React.useMemo(() => {
if (!liveDetail?.statistics || !cornerSettings.enabled) {
return { home: "", away: "" };
}
const corners = liveDetail.statistics.find((s) => s.type === "Corners");
if (corners) {
return { home: corners.home, away: corners.away };
}
const dangerousAttacks = liveDetail.statistics.find(
(s) => s.type === "Dangerous Attacks",
);
if (dangerousAttacks) {
return { home: dangerousAttacks.home, away: dangerousAttacks.away };
}
return { home: "", away: "" };
}, [liveDetail, cornerSettings.enabled]);
const handlePress = () => {
if (onPress) {
onPress(match);
@@ -384,6 +415,17 @@ export function MatchCard({
<View style={styles.scoreBoxPlaceholder} />
)}
{(extraStats.home !== "" || extraStats.away !== "") && (
<View style={styles.extraStatsColumn}>
<ThemedText style={styles.extraStatText}>
{extraStats.home}
</ThemedText>
<ThemedText style={styles.extraStatText}>
{extraStats.away}
</ThemedText>
</View>
)}
<TouchableOpacity
onPress={(e) => {
e.stopPropagation();
@@ -539,6 +581,17 @@ const styles = StyleSheet.create({
cardBadgeRed: {
backgroundColor: "#FF3B30",
},
extraStatsColumn: {
alignItems: "center",
justifyContent: "space-between",
height: 48,
paddingVertical: 2,
},
extraStatText: {
fontSize: 12,
fontWeight: "500",
opacity: 0.6,
},
cardBadgeText: {
fontSize: 10,
fontWeight: "900",