mirror of
https://github.com/zimplexing/OrionTV.git
synced 2026-05-22 01:57:28 +08:00
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.
This commit is contained in:
32
stores/settingsStore.ts
Normal file
32
stores/settingsStore.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
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 }),
|
||||
}));
|
||||
Reference in New Issue
Block a user