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.

1.1 KB
Raw Blame
import type { QueryClient } from "@tanstack/react-query";
import getProjects from "@/fetchers/project/get-projects";
import { collectCachedProjects } from "./collect-cached-projects";
import { evictProjectCache } from "./evict-project-cache";
import { findRemovedProjectIds } from "./find-removed-project-ids";

export function reconcileProjectAccess(
  client: QueryClient,
  workspaceId: string,
  isActive: () => boolean,
) {
  const before = collectCachedProjects(client, workspaceId);
  if (before.length === 0) return;
  void client
    .fetchQuery({
      queryKey: ["projects", workspaceId, "including-archived"],
      queryFn: () => getProjects({ workspaceId, includeArchived: "true" }),
    })
    .then((after) => {
      if (!isActive()) return;
      const removed = findRemovedProjectIds(before, after);
      for (const projectId of removed) evictProjectCache(client, projectId);
      if (removed.length > 0) {
        void client.invalidateQueries({ queryKey: ["projects", workspaceId] });
        void client.invalidateQueries({ queryKey: ["notifications"] });
      }
    })
    .catch(() => {});
}