添加赔率设置功能,支持选择博彩公司并展示赔率信息;优化状态管理和国际化文本

This commit is contained in:
yuchenglong
2026-01-19 17:24:09 +08:00
parent e1320a67e4
commit 7024b03c30
7 changed files with 439 additions and 51 deletions

View File

@@ -1,10 +1,18 @@
import React, { createContext, ReactNode, useContext, useState } from "react";
import { OddsSettings, storage } from "@/lib/storage";
import React, {
createContext,
ReactNode,
useContext,
useEffect,
useState,
} from "react";
interface AppState {
selectedSportId: number | null;
selectedDate: Date;
selectedLeagueKey: string | null;
timezone: string;
oddsSettings: OddsSettings;
}
interface AppStateContextType {
@@ -13,10 +21,11 @@ interface AppStateContextType {
updateDate: (date: Date) => void;
updateLeagueKey: (leagueKey: string | null) => void;
updateTimezone: (timezone: string) => void;
updateOddsSettings: (settings: OddsSettings) => void;
}
const AppStateContext = createContext<AppStateContextType | undefined>(
undefined
undefined,
);
export function AppStateProvider({ children }: { children: ReactNode }) {
@@ -25,8 +34,16 @@ export function AppStateProvider({ children }: { children: ReactNode }) {
selectedDate: new Date(),
selectedLeagueKey: null,
timezone: "UTC",
oddsSettings: { enabled: false, selectedBookmakers: [] },
});
useEffect(() => {
// Initial load of odds settings
storage.getOddsSettings().then((settings) => {
setState((prev) => ({ ...prev, oddsSettings: settings }));
});
}, []);
const updateSportId = (sportId: number | null) => {
setState((prev) => ({ ...prev, selectedSportId: sportId }));
};
@@ -43,6 +60,11 @@ export function AppStateProvider({ children }: { children: ReactNode }) {
setState((prev) => ({ ...prev, timezone }));
};
const updateOddsSettings = (settings: OddsSettings) => {
setState((prev) => ({ ...prev, oddsSettings: settings }));
storage.setOddsSettings(settings);
};
return (
<AppStateContext.Provider
value={{
@@ -51,6 +73,7 @@ export function AppStateProvider({ children }: { children: ReactNode }) {
updateDate,
updateLeagueKey,
updateTimezone,
updateOddsSettings,
}}
>
{children}