mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 08:23:34 +00:00
Add blossom.ditto.pub and blossom.dreamith.to to the top of all blossom server lists. Add relay.dreamith.to below relay.ditto.pub and remove relay.damus.io and purplerelay.com from deploy relay lists.
84 lines
2.4 KiB
TypeScript
84 lines
2.4 KiB
TypeScript
import { useState, useEffect, useMemo, type ReactNode } from 'react';
|
|
import { DeploySettingsContext, type DeploySettings, type DeployProvider } from '@/contexts/DeploySettingsContext';
|
|
import { useFS } from '@/hooks/useFS';
|
|
import { useFSPaths } from '@/hooks/useFSPaths';
|
|
import { readDeploySettings, writeDeploySettings } from '@/lib/configUtils';
|
|
import { DEFAULT_NSITE_PROVIDER } from '@/lib/deployProviderPresets';
|
|
|
|
const DEFAULT_SETTINGS: DeploySettings = {
|
|
providers: [DEFAULT_NSITE_PROVIDER],
|
|
};
|
|
|
|
export function DeploySettingsProvider({ children }: { children: ReactNode }) {
|
|
const { fs } = useFS();
|
|
const { configPath } = useFSPaths();
|
|
const [settings, setSettings] = useState<DeploySettings>(DEFAULT_SETTINGS);
|
|
const [isInitialized, setIsInitialized] = useState(false);
|
|
|
|
// Initialize settings from VFS on mount
|
|
useEffect(() => {
|
|
const initializeSettings = async () => {
|
|
try {
|
|
const settings = await readDeploySettings(fs, configPath);
|
|
setSettings(settings);
|
|
} catch (error) {
|
|
console.error('Failed to initialize deploy settings:', error);
|
|
setSettings(DEFAULT_SETTINGS);
|
|
} finally {
|
|
setIsInitialized(true);
|
|
}
|
|
};
|
|
|
|
initializeSettings();
|
|
}, [fs, configPath]);
|
|
|
|
// Save settings to VFS whenever they change (but not during initialization)
|
|
useEffect(() => {
|
|
if (!isInitialized) return;
|
|
|
|
const saveSettings = async () => {
|
|
try {
|
|
await writeDeploySettings(fs, settings, configPath);
|
|
} catch (error) {
|
|
console.error('Failed to save deploy settings:', error);
|
|
}
|
|
};
|
|
|
|
saveSettings();
|
|
}, [fs, settings, isInitialized, configPath]);
|
|
|
|
const updateSettings = (updates: Partial<DeploySettings>) => {
|
|
setSettings(prev => ({ ...prev, ...updates }));
|
|
};
|
|
|
|
const removeProvider = (index: number) => {
|
|
setSettings(prev => ({
|
|
...prev,
|
|
providers: prev.providers.filter((_, i) => i !== index),
|
|
}));
|
|
};
|
|
|
|
const setProviders = (providers: DeployProvider[]) => {
|
|
setSettings(prev => ({ ...prev, providers }));
|
|
};
|
|
|
|
const isConfigured = useMemo(() => {
|
|
return settings.providers.length > 0;
|
|
}, [settings.providers]);
|
|
|
|
const value = {
|
|
settings,
|
|
updateSettings,
|
|
removeProvider,
|
|
setProviders,
|
|
isConfigured,
|
|
isInitialized,
|
|
};
|
|
|
|
return (
|
|
<DeploySettingsContext.Provider value={value}>
|
|
{children}
|
|
</DeploySettingsContext.Provider>
|
|
);
|
|
}
|