Files
kandev/apps/web/components/task-create-dialog-multi-repo-guard.ts
T
Carlos Florêncio b9eb6ae058 refactor(web): remove legacy settings migration (#1704)
* refactor(web): remove legacy settings migration

* fix(web): hydrate portable settings from boot state

* fix(web): preserve sidebar sync contracts

* fix(web): retain portable settings filters

* fix(web): retry sidebar settings writes

* fix(web): retain sidebar boot settings

* fix(websocket): avoid shutdown teardown leaks

* fix(boot): normalize sidebar task preferences

* fix(settings): preserve saved views during hydration

* fix(jira): avoid duplicate saved-view syncs

* fix(jira): preserve saved views on fetch failure

* fix(jira): retry saved-view hydration failures

* refactor(jira): simplify hydration request cleanup

* fix(websocket): close late clients after hub shutdown
2026-07-16 00:06:41 +01:00

51 lines
1.5 KiB
TypeScript

"use client";
import { useEffect } from "react";
import type { Executor } from "@/lib/types/http";
type MultiRepoGuardOptions = {
open: boolean;
executorProfileId: string;
setExecutorProfileId: (id: string) => void;
executors: Executor[];
selectedRepoCount: number;
lastUsedExecutorProfileId: string | null;
};
export function useMultiRepoGuardEffect({
open,
executorProfileId,
setExecutorProfileId,
executors,
selectedRepoCount,
lastUsedExecutorProfileId,
}: MultiRepoGuardOptions) {
useEffect(() => {
if (!open || !executorProfileId || executors.length === 0) return;
if (selectedRepoCount <= 1) return;
const profileToType = new Map<string, string | undefined>();
const worktreeProfileIds: string[] = [];
for (const e of executors) {
for (const p of e.profiles ?? []) {
const type = p.executor_type ?? e.type;
profileToType.set(p.id, type);
if (type === "worktree") worktreeProfileIds.push(p.id);
}
}
if (worktreeProfileIds.length === 0) return;
if (profileToType.get(executorProfileId) === "worktree") return;
const preferredProfileId =
lastUsedExecutorProfileId && worktreeProfileIds.includes(lastUsedExecutorProfileId)
? lastUsedExecutorProfileId
: worktreeProfileIds[0];
void Promise.resolve().then(() => setExecutorProfileId(preferredProfileId));
}, [
open,
executorProfileId,
executors,
selectedRepoCount,
setExecutorProfileId,
lastUsedExecutorProfileId,
]);
}