Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

894 B
Raw Blame
import type { ProjectWithTasks } from "@/types/project";

export function selectReorderBoard(
  projectId: string,
  _taskId: string,
  cached: ProjectWithTasks | undefined,
  stored: ProjectWithTasks | null | undefined,
) {
  const current = cached?.id === projectId ? cached : undefined;
  const local = stored?.id === projectId ? stored : undefined;
  if (!current) return local;
  if (!local) return current;
  const ids = new Set(
    current.columns.flatMap((column) => column.tasks.map((task) => task.id)),
  );
  const created = local.columns
    .flatMap((column) => column.tasks)
    .filter((task) => !ids.has(task.id));
  if (!created.length) return current;
  return {
    ...current,
    columns: current.columns.map((column) => ({
      ...column,
      tasks: [
        ...column.tasks,
        ...created.filter((task) => task.status === column.slug),
      ],
    })),
  };
}