Files
OrionTV/stores/settingsStore.ts
zimplexing 08e24dd748 Refactor components to use Zustand for state management
- Updated EpisodeSelectionModal to utilize Zustand for episode selection state.
- Refactored PlayerControls to manage playback state and controls using Zustand.
- Simplified SettingsModal to handle settings state with Zustand.
- Introduced homeStore for managing home screen categories and content data.
- Created playerStore for managing video playback and episode details.
- Added settingsStore for managing API settings and modal visibility.
- Updated package.json to include Zustand as a dependency.
- Cleaned up code formatting and improved readability across components.
2025-07-06 20:45:42 +08:00

32 lines
997 B
TypeScript

import { create } from 'zustand';
import { SettingsManager } from '@/services/storage';
import { api } from '@/services/api';
interface SettingsState {
apiBaseUrl: string;
isModalVisible: boolean;
loadSettings: () => Promise<void>;
setApiBaseUrl: (url: string) => void;
saveSettings: () => Promise<void>;
showModal: () => void;
hideModal: () => void;
}
export const useSettingsStore = create<SettingsState>((set, get) => ({
apiBaseUrl: '',
isModalVisible: false,
loadSettings: async () => {
const settings = await SettingsManager.get();
set({ apiBaseUrl: settings.apiBaseUrl });
api.setBaseUrl(settings.apiBaseUrl);
},
setApiBaseUrl: (url) => set({ apiBaseUrl: url }),
saveSettings: async () => {
const { apiBaseUrl } = get();
await SettingsManager.save({ apiBaseUrl });
api.setBaseUrl(apiBaseUrl);
set({ isModalVisible: false });
},
showModal: () => set({ isModalVisible: true }),
hideModal: () => set({ isModalVisible: false }),
}));