fix(settings): sync auto-settle and other shared preferences across environments (#9147)
Co-authored-by: Claude Fable 5.1 <[email protected]>
This commit is contained in:
1 parent
5014e5fcdd
commit
8efd4e95fc
10 files changed
+489
-44
No files matched your search
@@ -19,7 +19,7 @@ import {
|
||||
squashAtomCommandFailure,
|
||||
} from "@t3tools/client-runtime/state/runtime";
|
||||
import { AndroidScreenHeader } from "../../components/AndroidScreenHeader";
|
||||
import { AppText as Text } from "../../components/AppText";
|
||||
import { AppText as Text, AppTextInput as TextInput } from "../../components/AppText";
|
||||
import { supportsAgentAwarenessPush } from "../agent-awareness/capabilities";
|
||||
import { setLiveActivityUpdatesEnabled } from "../agent-awareness/liveActivityPreferences";
|
||||
import { requestAgentNotificationPermission } from "../agent-awareness/notificationPermissions";
|
||||
@@ -36,7 +36,17 @@ import { runtime } from "../../lib/runtime";
|
||||
import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../state/preferences";
|
||||
import { serverEnvironment } from "../../state/server";
|
||||
import { useAtomCommand } from "../../state/use-atom-command";
|
||||
import type { EnvironmentId } from "@t3tools/contracts";
|
||||
import { useEnvironments } from "../../state/environments";
|
||||
import {
|
||||
DEFAULT_SERVER_SETTINGS,
|
||||
MAX_SIDEBAR_AUTO_SETTLE_AFTER_DAYS,
|
||||
MIN_SIDEBAR_AUTO_SETTLE_AFTER_DAYS,
|
||||
type ServerSettingsPatch,
|
||||
} from "@t3tools/contracts";
|
||||
import {
|
||||
findSharedSettingsMismatches,
|
||||
pickSharedServerSettings,
|
||||
} from "@t3tools/client-runtime/state/shared-settings";
|
||||
import { useThreadListV2Enabled } from "../threads/use-thread-list-v2-enabled";
|
||||
import {
|
||||
type AppUpdateCheckState,
|
||||
@@ -530,51 +540,136 @@ function ConfiguredSettingsRouteScreen() {
|
||||
}
|
||||
|
||||
function GeneralSettingsSection() {
|
||||
const { savedConnectionsById } = useSavedRemoteConnections();
|
||||
const connections = Object.values(savedConnectionsById).sort((left, right) =>
|
||||
left.environmentLabel.localeCompare(right.environmentLabel),
|
||||
);
|
||||
|
||||
return (
|
||||
<SettingsSection title="General">
|
||||
<SettingsRow icon="folder" label="Project Grouping" target="SettingsProjectGrouping" />
|
||||
{connections.map((connection) => (
|
||||
<EnvironmentAutoSettleSwitch
|
||||
key={connection.environmentId}
|
||||
environmentId={connection.environmentId}
|
||||
environmentLabel={connection.environmentLabel}
|
||||
/>
|
||||
))}
|
||||
<AutoSettleSettingsRows />
|
||||
<SettingsRow icon="chart.bar.xaxis" label="Usage" target="SettingsUsage" />
|
||||
</SettingsSection>
|
||||
);
|
||||
}
|
||||
|
||||
function EnvironmentAutoSettleSwitch(props: {
|
||||
readonly environmentId: EnvironmentId;
|
||||
readonly environmentLabel: string;
|
||||
}) {
|
||||
const settings = useAtomValue(serverEnvironment.settingsValueAtom(props.environmentId));
|
||||
const config = useAtomValue(serverEnvironment.configValueAtom(props.environmentId));
|
||||
const AUTO_SETTLE_DEFAULT_DAYS = DEFAULT_SERVER_SETTINGS.sidebarAutoSettleAfterDays ?? 3;
|
||||
|
||||
/**
|
||||
* Auto-settlement is a user preference that every server has to hold. Mobile
|
||||
* has no primary environment, so the first connected environment that
|
||||
* supports it is the reference value. Edits fan out to every connected
|
||||
* environment, and a mismatch row lets the user push the reference out.
|
||||
*/
|
||||
function AutoSettleSettingsRows() {
|
||||
const { environments } = useEnvironments();
|
||||
const updateSettings = useAtomCommand(serverEnvironment.updateSettings, {
|
||||
label: "auto-settle settings update",
|
||||
label: "server settings update",
|
||||
reportFailure: true,
|
||||
});
|
||||
if (config?.environment.capabilities.threadAutoSettlement !== true || settings === null) {
|
||||
|
||||
const connected = environments.filter(
|
||||
(environment) =>
|
||||
environment.connection.phase === "connected" &&
|
||||
environment.serverConfig?.environment.capabilities.threadAutoSettlement === true,
|
||||
);
|
||||
const reference = connected[0] ?? null;
|
||||
const referenceSettings = reference?.serverConfig?.settings ?? null;
|
||||
|
||||
const [daysDraft, setDaysDraft] = useState<string | null>(null);
|
||||
|
||||
if (reference === null || referenceSettings === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const writeToAll = (patch: ServerSettingsPatch) => {
|
||||
for (const environment of connected) {
|
||||
void updateSettings({ environmentId: environment.environmentId, input: { patch } });
|
||||
}
|
||||
};
|
||||
|
||||
const mismatches = findSharedSettingsMismatches({
|
||||
primaryEnvironmentId: reference.environmentId,
|
||||
primarySettings: referenceSettings,
|
||||
environments: environments.map((environment) => ({
|
||||
environmentId: environment.environmentId,
|
||||
label: environment.label,
|
||||
connected: environment.connection.phase === "connected",
|
||||
settings: environment.serverConfig?.settings ?? null,
|
||||
})),
|
||||
});
|
||||
|
||||
const afterDays = referenceSettings.sidebarAutoSettleAfterDays;
|
||||
const commitDays = () => {
|
||||
const draft = (daysDraft ?? "").trim();
|
||||
setDaysDraft(null);
|
||||
// Whole-string check so "3.5" and "3days" are rejected instead of
|
||||
// silently becoming 3 on every connected environment.
|
||||
const parsed = /^\d+$/.test(draft) ? Number(draft) : Number.NaN;
|
||||
if (
|
||||
Number.isInteger(parsed) &&
|
||||
parsed >= MIN_SIDEBAR_AUTO_SETTLE_AFTER_DAYS &&
|
||||
parsed <= MAX_SIDEBAR_AUTO_SETTLE_AFTER_DAYS &&
|
||||
parsed !== afterDays
|
||||
) {
|
||||
writeToAll({ sidebarAutoSettleAfterDays: parsed });
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<SettingsSwitchRow
|
||||
icon="arrow.triangle.branch"
|
||||
label={`Auto-settle merged threads · ${props.environmentLabel}`}
|
||||
value={settings?.sidebarAutoSettleOnMerge ?? true}
|
||||
onValueChange={(value) => {
|
||||
void updateSettings({
|
||||
environmentId: props.environmentId,
|
||||
input: { patch: { sidebarAutoSettleOnMerge: value } },
|
||||
});
|
||||
}}
|
||||
/>
|
||||
<>
|
||||
<SettingsSwitchRow
|
||||
icon="arrow.triangle.branch"
|
||||
label="Auto-settle merged threads"
|
||||
value={referenceSettings.sidebarAutoSettleOnMerge}
|
||||
onValueChange={(value) => writeToAll({ sidebarAutoSettleOnMerge: value })}
|
||||
/>
|
||||
<SettingsSwitchRow
|
||||
icon="clock"
|
||||
label="Auto-settle inactive threads"
|
||||
subtitle={afterDays === null ? undefined : `After ${afterDays} days without activity`}
|
||||
value={afterDays !== null}
|
||||
onValueChange={(value) =>
|
||||
writeToAll({ sidebarAutoSettleAfterDays: value ? AUTO_SETTLE_DEFAULT_DAYS : null })
|
||||
}
|
||||
/>
|
||||
{afterDays !== null ? (
|
||||
<View className="flex-row items-center gap-4 border-t border-border-subtle p-4">
|
||||
<Text className="flex-1 text-lg text-foreground">Days before auto-settle</Text>
|
||||
<TextInput
|
||||
className="min-h-10 w-20 rounded-xl px-3 py-2 text-center text-base"
|
||||
keyboardType="number-pad"
|
||||
returnKeyType="done"
|
||||
value={daysDraft ?? String(afterDays)}
|
||||
onChangeText={setDaysDraft}
|
||||
onBlur={commitDays}
|
||||
onSubmitEditing={commitDays}
|
||||
accessibilityLabel="Days before auto-settle"
|
||||
/>
|
||||
</View>
|
||||
) : null}
|
||||
{mismatches.length > 0 ? (
|
||||
<View className="flex-row items-center gap-4 border-t border-border-subtle p-4">
|
||||
<View className="min-w-0 flex-1">
|
||||
<Text className="text-lg text-foreground">Settings differ</Text>
|
||||
<Text className="text-sm text-foreground-muted">
|
||||
{mismatches.map((mismatch) => mismatch.label).join(", ")}
|
||||
</Text>
|
||||
</View>
|
||||
<Pressable
|
||||
accessibilityRole="button"
|
||||
onPress={() => {
|
||||
const patch = pickSharedServerSettings(referenceSettings);
|
||||
for (const mismatch of mismatches) {
|
||||
void updateSettings({
|
||||
environmentId: mismatch.environmentId,
|
||||
input: { patch },
|
||||
});
|
||||
}
|
||||
}}
|
||||
className="rounded-full bg-subtle px-4 py-2 active:opacity-70"
|
||||
>
|
||||
<Text className="text-base font-t3-medium text-foreground">Apply to all</Text>
|
||||
</Pressable>
|
||||
</View>
|
||||
) : null}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user