Open History to see the last commit
1import { useMemo } from "react";
2import { AuthAccessWriteScope } from "@t3tools/contracts";
3
4import { hasCloudPublicConfig } from "~/cloud/publicConfig";
5import { isElectron } from "~/env";
6import { desktopWslStateAtom } from "~/state/desktopWslState";
7import { useEnvironments, usePrimaryEnvironmentId } from "~/state/environments";
8import { useEnvironmentQuery } from "~/state/query";
9import { usePrimarySessionState } from "~/environments/primary";
10import { isWslSettingsRowVisible } from "./ConnectionsSettings.logic";
11import { isProviderSettingsEnvironmentAvailable } from "./ProviderSettingsPanel.logic";
12import { filterAvailableSettingsSearchItems } from "./settingsSearch";
13
14export function useAvailableSettingsSearchItems() {
15 const primaryEnvironmentId = usePrimaryEnvironmentId();
16 const { environments } = useEnvironments();
17 const primarySessionState = usePrimarySessionState();
18 const desktopWsl = useEnvironmentQuery(isElectron ? desktopWslStateAtom : null);
19 const canManageLocalBackend =
20 isElectron ||
21 ((primarySessionState.data?.authenticated &&
22 primarySessionState.data.scopes?.includes(AuthAccessWriteScope)) ??
23 false);
24
25 return useMemo(
26 () =>
27 filterAvailableSettingsSearchItems({
28 hasCloudPublicConfig: hasCloudPublicConfig(),
29 hasPrimaryEnvironment: primaryEnvironmentId !== null,
30 hasProviderSettingsEnvironment: environments.some((environment) =>
31 isProviderSettingsEnvironmentAvailable({
32 connectionPhase: environment.connection.phase,
33 hasServerConfig: environment.serverConfig !== null,
34 }),
35 ),
36 canManageLocalBackend,
37 isWslSettingsRowVisible: isWslSettingsRowVisible({
38 state: desktopWsl.data,
39 error: desktopWsl.error,
40 }),
41 }),
42 [canManageLocalBackend, desktopWsl.data, desktopWsl.error, environments, primaryEnvironmentId],
43 );
44}