mirror of
https://github.com/stackblitz/bolt.new
synced 2025-02-06 04:48:04 +00:00
Update useSettings.tsx
if it has not been set by the user yet set it correctly for them
This commit is contained in:
parent
69b1dc4c9a
commit
c5c3eee267
@ -11,6 +11,7 @@ import { useCallback, useEffect, useState } from 'react';
|
|||||||
import Cookies from 'js-cookie';
|
import Cookies from 'js-cookie';
|
||||||
import type { IProviderSetting, ProviderInfo } from '~/types/model';
|
import type { IProviderSetting, ProviderInfo } from '~/types/model';
|
||||||
import { logStore } from '~/lib/stores/logs'; // assuming logStore is imported from this location
|
import { logStore } from '~/lib/stores/logs'; // assuming logStore is imported from this location
|
||||||
|
import commit from '~/commit.json';
|
||||||
|
|
||||||
export function useSettings() {
|
export function useSettings() {
|
||||||
const providers = useStore(providersStore);
|
const providers = useStore(providersStore);
|
||||||
@ -20,6 +21,22 @@ export function useSettings() {
|
|||||||
const useLatest = useStore(useLatestBranch);
|
const useLatest = useStore(useLatestBranch);
|
||||||
const [activeProviders, setActiveProviders] = useState<ProviderInfo[]>([]);
|
const [activeProviders, setActiveProviders] = useState<ProviderInfo[]>([]);
|
||||||
|
|
||||||
|
// Function to check if we're on stable version
|
||||||
|
const checkIsStableVersion = async () => {
|
||||||
|
try {
|
||||||
|
const stableResponse = await fetch('https://raw.githubusercontent.com/stackblitz-labs/bolt.diy/stable/app/commit.json');
|
||||||
|
if (!stableResponse.ok) {
|
||||||
|
console.warn('Failed to fetch stable commit info');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const stableData = await stableResponse.json();
|
||||||
|
return commit.commit === stableData.commit;
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Error checking stable version:', error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// reading values from cookies on mount
|
// reading values from cookies on mount
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const savedProviders = Cookies.get('providers');
|
const savedProviders = Cookies.get('providers');
|
||||||
@ -63,10 +80,16 @@ export function useSettings() {
|
|||||||
isLocalModelsEnabled.set(savedLocalModels === 'true');
|
isLocalModelsEnabled.set(savedLocalModels === 'true');
|
||||||
}
|
}
|
||||||
|
|
||||||
// load latest branch setting from cookies
|
// load latest branch setting from cookies or determine based on version
|
||||||
const savedLatestBranch = Cookies.get('useLatestBranch');
|
const savedLatestBranch = Cookies.get('useLatestBranch');
|
||||||
|
if (savedLatestBranch === undefined) {
|
||||||
if (savedLatestBranch) {
|
// If setting hasn't been set by user, check version
|
||||||
|
checkIsStableVersion().then(isStable => {
|
||||||
|
const shouldUseLatest = !isStable;
|
||||||
|
useLatestBranch.set(shouldUseLatest);
|
||||||
|
Cookies.set('useLatestBranch', String(shouldUseLatest));
|
||||||
|
});
|
||||||
|
} else {
|
||||||
useLatestBranch.set(savedLatestBranch === 'true');
|
useLatestBranch.set(savedLatestBranch === 'true');
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
Loading…
Reference in New Issue
Block a user