generated from kevisual/vite-react-template
- Implement CreateRepoDialog for creating new repositories with form validation. - Implement EditRepoDialog for editing existing repository details. - Implement SyncRepoDialog for syncing repositories with Gitea, including repository creation if necessary. - Implement WorkspaceDetailDialog for managing workspace links and actions. - Enhance the repo store with new state management for repository actions, including creating, editing, and syncing repositories. - Add build configuration utilities for repository synchronization. - Create a new page for repository management, integrating all dialogs and functionalities. - Add login route for authentication.
51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
import { create } from 'zustand';
|
|
import type { GiteaConfig } from './schema';
|
|
|
|
type GiteaConfigState = {
|
|
config: GiteaConfig;
|
|
setConfig: (config: Partial<GiteaConfig>) => void;
|
|
resetConfig: () => void;
|
|
};
|
|
|
|
const DEFAULT_CONFIG: GiteaConfig = {
|
|
GITEA_TOKEN: '',
|
|
GITEA_URL: 'https://git.xiongxiao.me',
|
|
};
|
|
|
|
const loadInitialConfig = (): GiteaConfig => {
|
|
try {
|
|
const token = localStorage.getItem('GITEA_TOKEN') || '';
|
|
const url = localStorage.getItem('GITEA_URL') || DEFAULT_CONFIG.GITEA_URL;
|
|
return {
|
|
GITEA_TOKEN: token,
|
|
GITEA_URL: url,
|
|
};
|
|
} catch {
|
|
// Ignore parse errors
|
|
}
|
|
return DEFAULT_CONFIG;
|
|
};
|
|
|
|
const saveConfig = (config: GiteaConfig) => {
|
|
try {
|
|
localStorage.setItem('GITEA_TOKEN', config.GITEA_TOKEN);
|
|
localStorage.setItem('GITEA_URL', config.GITEA_URL);
|
|
} catch (error) {
|
|
console.error('Failed to save config:', error);
|
|
}
|
|
};
|
|
|
|
export const useGiteaConfigStore = create<GiteaConfigState>()((set) => ({
|
|
config: loadInitialConfig(),
|
|
setConfig: (newConfig) =>
|
|
set((state) => {
|
|
const updatedConfig = { ...state.config, ...newConfig };
|
|
saveConfig(updatedConfig);
|
|
return { config: updatedConfig };
|
|
}),
|
|
resetConfig: () => {
|
|
saveConfig(DEFAULT_CONFIG);
|
|
return set({ config: DEFAULT_CONFIG });
|
|
},
|
|
}));
|