feat: add installation configuration support with pythonIndexUrl in settings (#67)

This commit is contained in:
samanhappy
2025-05-10 21:33:35 +08:00
committed by GitHub
parent 7c43ca359e
commit 7af3c8a2ba
9 changed files with 183 additions and 15 deletions

View File

@@ -17,18 +17,34 @@ const SettingsPage: React.FC = () => {
setCurrentLanguage(i18n.language);
}, [i18n.language]);
const [installConfig, setInstallConfig] = useState<{
pythonIndexUrl: string;
}>({
pythonIndexUrl: '',
});
const {
routingConfig,
installConfig: savedInstallConfig,
loading,
updateRoutingConfig
updateRoutingConfig,
updateInstallConfig
} = useSettingsData();
// Update local installConfig when savedInstallConfig changes
useEffect(() => {
if (savedInstallConfig) {
setInstallConfig(savedInstallConfig);
}
}, [savedInstallConfig]);
const [sectionsVisible, setSectionsVisible] = useState({
routingConfig: false,
installConfig: false,
password: false
});
const toggleSection = (section: 'routingConfig' | 'password') => {
const toggleSection = (section: 'routingConfig' | 'installConfig' | 'password') => {
setSectionsVisible(prev => ({
...prev,
[section]: !prev[section]
@@ -39,6 +55,17 @@ const SettingsPage: React.FC = () => {
await updateRoutingConfig(key, value);
};
const handleInstallConfigChange = (value: string) => {
setInstallConfig({
...installConfig,
pythonIndexUrl: value
});
};
const saveInstallConfig = async () => {
await updateInstallConfig('pythonIndexUrl', installConfig.pythonIndexUrl);
};
const handlePasswordChangeSuccess = () => {
setTimeout(() => {
navigate('/');
@@ -124,6 +151,47 @@ const SettingsPage: React.FC = () => {
)}
</div>
{/* Installation Configuration Settings */}
<div className="bg-white shadow rounded-lg py-4 px-6 mb-6">
<div
className="flex justify-between items-center cursor-pointer"
onClick={() => toggleSection('installConfig')}
>
<h2 className="font-semibold text-gray-800">{t('settings.installConfig')}</h2>
<span className="text-gray-500">
{sectionsVisible.installConfig ? '▼' : '►'}
</span>
</div>
{sectionsVisible.installConfig && (
<div className="space-y-4 mt-4">
<div className="p-3 bg-gray-50 rounded-md">
<div className="mb-2">
<h3 className="font-medium text-gray-700">{t('settings.pythonIndexUrl')}</h3>
<p className="text-sm text-gray-500">{t('settings.pythonIndexUrlDescription')}</p>
</div>
<div className="flex items-center gap-3">
<input
type="text"
value={installConfig.pythonIndexUrl}
onChange={(e) => handleInstallConfigChange(e.target.value)}
placeholder={t('settings.pythonIndexUrlPlaceholder')}
className="flex-1 mt-1 block w-full py-2 px-3 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm"
disabled={loading}
/>
<button
onClick={saveInstallConfig}
disabled={loading}
className="mt-1 px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-md text-sm font-medium disabled:opacity-50"
>
{t('common.save')}
</button>
</div>
</div>
</div>
)}
</div>
{/* Change Password */}
<div className="bg-white shadow rounded-lg py-4 px-6 mb-6">
<div