fix(ui): re-sync settings/thread forms on loaded record
This commit is contained in:
1 parent
bca86196fb
commit
a3ec04ad99
3 files changed
+216
-2
No files matched your search
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { useMutation, useQuery } from 'convex/react';
|
||||
import { Bot } from 'lucide-react';
|
||||
import { toast } from 'sonner';
|
||||
@@ -33,6 +33,7 @@ const runtimeLabels: Record<RuntimeName, string> = {
|
||||
};
|
||||
|
||||
type AgentSettings = {
|
||||
_id?: Id<'spoonAgentSettings'>;
|
||||
enabled: boolean;
|
||||
runtime?: RuntimeName | 'openai_direct';
|
||||
defaultBaseBranch?: string;
|
||||
@@ -127,6 +128,46 @@ export const SpoonAgentSettingsForm = ({
|
||||
: settings.reasoningEffort,
|
||||
);
|
||||
|
||||
// The parent gates rendering on a different query than `settings`, so this
|
||||
// form can mount before the agent settings record resolves. Re-seed every
|
||||
// field once the real record arrives (and again if the parent swaps to a
|
||||
// different spoon) so a Save cannot persist the initial defaults over the
|
||||
// user's saved configuration.
|
||||
const hydratedSpoonId = useRef<Id<'spoons'> | null>(null);
|
||||
useEffect(() => {
|
||||
if (!settings || hydratedSpoonId.current === spoon._id) return;
|
||||
const timeout = window.setTimeout(() => {
|
||||
setEnabled(settings.enabled);
|
||||
setDefaultBaseBranch(
|
||||
settings.defaultBaseBranch ??
|
||||
spoon.forkDefaultBranch ??
|
||||
spoon.upstreamDefaultBranch,
|
||||
);
|
||||
setBranchPrefix(settings.branchPrefix);
|
||||
setInstallCommand(settings.installCommand ?? '');
|
||||
setCheckCommand(settings.checkCommand ?? '');
|
||||
setTestCommand(settings.testCommand ?? '');
|
||||
setEnvFilePath(settings.envFilePath ?? '.env.local');
|
||||
setCustomEnvFilePath(settings.customEnvFilePath ?? '');
|
||||
setMaterializeEnvFileByDefault(
|
||||
settings.materializeEnvFileByDefault ?? false,
|
||||
);
|
||||
setAutoDetectCommands(settings.autoDetectCommands ?? true);
|
||||
setAllowUserFileEditing(settings.allowUserFileEditing ?? true);
|
||||
setAiProviderProfileId(settings.aiProviderProfileId ?? '__default');
|
||||
setAgentModel(settings.aiProviderProfileId ? settings.agentModel : '');
|
||||
setReasoningEffort(
|
||||
!settings.aiProviderProfileId
|
||||
? 'medium'
|
||||
: settings.reasoningEffort === 'none'
|
||||
? 'minimal'
|
||||
: settings.reasoningEffort,
|
||||
);
|
||||
hydratedSpoonId.current = spoon._id;
|
||||
}, 0);
|
||||
return () => window.clearTimeout(timeout);
|
||||
}, [settings, spoon]);
|
||||
|
||||
const supportedRuntimes = (selectedProfile?.supportedRuntimes ??
|
||||
[]) as RuntimeName[];
|
||||
const settingsRuntime = settings?.runtime as RuntimeName | undefined;
|
||||
|
||||
Reference in new issue
Block a user