Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

1.4 KB
Raw Blame
import type { SetPredicatesInput } from '@app/features/next-soup/filters/filter-store/predicates-store';
import type { Query } from '@app/features/next-soup/filters/filter-store/types';
import type { SplitId } from '@components/app/split-layout/layoutManager';

type SearchSplitOverrides = {
  query: string;
  filters: Query;
  clientFilters: SetPredicatesInput<string>;
};

type SearchSplitController = {
  applyOverrides: (overrides: SearchSplitOverrides) => void;
  focus: () => void;
};

const registry = new Map<SplitId, SearchSplitController>();
const pendingFocusBySplit = new Set<SplitId>();

export function registerSearchSplit(
  splitId: SplitId,
  controller: SearchSplitController
): () => void {
  registry.set(splitId, controller);
  if (pendingFocusBySplit.delete(splitId)) {
    controller.focus();
  }
  return () => {
    if (registry.get(splitId) === controller) registry.delete(splitId);
  };
}

export function getSearchSplit(
  splitId: SplitId
): SearchSplitController | undefined {
  return registry.get(splitId);
}

/**
 * Focus the search bar in the given split. If the split's search controller
 * is already registered, focus immediately; otherwise queue the request and
 * focus once the controller registers (e.g. after the SoupView mounts).
 */
export function requestSearchFocus(splitId: SplitId) {
  const controller = registry.get(splitId);
  if (controller) {
    controller.focus();
    return;
  }
  pendingFocusBySplit.add(splitId);
}