import { connectionStatusText } from "@t3tools/client-runtime/connection"; import { useClientSettings, useClientSettingsHydrated, useUpdateClientSettings, } from "~/hooks/useSettings"; import type { EnvironmentPresentation } from "~/state/environments"; import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../ui/select"; import { Switch } from "../ui/switch"; import { SettingsRow, SettingsSection } from "./settingsLayout"; import { searchableSetting } from "./settingsSearch"; const preferences = [ { value: 100, label: "Prefer" }, { value: 50, label: "Normal" }, { value: 25, label: "Less often" }, { value: 0, label: "Manual only" }, ]; export function LoadBalancingSettings({ environments, }: { environments: ReadonlyArray; }) { const settings = useClientSettings(); const settingsHydrated = useClientSettingsHydrated(); const updateSettings = useUpdateClientSettings(); if (environments.length < 2) { return (

Connect another machine to automatically balance load across environments.

); } return ( updateSettings({ loadBalancingEnabled })} /> } /> {environments.map((environment) => { const weight = settings.loadBalancingWeights[environment.environmentId] ?? 50; // Keep saved slider weights until the user chooses a different preference. const preference = weight === 0 ? 0 : weight < 50 ? 25 : weight === 50 ? 50 : 100; return ( { if (value !== null) { updateSettings({ loadBalancingWeights: { ...settings.loadBalancingWeights, [environment.environmentId]: value, }, }); } }} > {preferences.map(({ value, label }) => ( {label} ))} } /> ); })} ); }