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.1 KB
Raw Blame
import {
  type TasksDataSource,
  type TasksDataSourceInput,
  type UseTasksDataSourceOptions,
  useTasksDataSource,
} from '@app/features/tasks-view/queries/use-tasks-query';
import { SYSTEM_PROPERTY_IDS } from '@property/identifiers';
import type { ProjectSource } from '../context/projects-context';

/**
 * The standard Tasks source scoped to tasks whose Project property names the
 * project, enabled only while the project itself is readable.
 */
export function createProjectTasksDataSource(
  projectId: string,
  project: ProjectSource,
  state: TasksDataSourceInput,
  options: UseTasksDataSourceOptions
): TasksDataSource {
  const source = useTasksDataSource(state, {
    ...options,
    reference: () => ({
      propertyDefinitionId: SYSTEM_PROPERTY_IDS.PROJECT,
      entityId: projectId,
    }),
    enabled: () => Boolean(project.project()),
  });
  return {
    ...source,
    isLoading: () =>
      project.loading() || (Boolean(project.project()) && source.isLoading()),
    error: () => project.error() ?? source.error(),
    refresh: async () => {
      await project.refresh();
      if (project.project()) await source.refresh();
    },
  };
}