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.

890 B
Raw Blame
import { useMemo } from "react";
import { getApiUrl } from "@/fetchers/get-api-url";
import { useUserPreferencesStore } from "@/store/user-preferences";

export type UseProjectBackground = {
  backgroundVersion?: string | null;
  projectId?: string;
  viewMode?: "list" | "board";
};

export function useProjectBackground({
  backgroundVersion,
  viewMode,
  projectId,
}: UseProjectBackground): string | null {
  const { showProjectBackgrounds } = useUserPreferencesStore();
  const shouldShowBackground =
    showProjectBackgrounds &&
    backgroundVersion &&
    viewMode === "board" &&
    projectId;

  const backgroundUrl = useMemo(() => {
    if (!shouldShowBackground) return null;
    return getApiUrl(
      `project/${projectId}/background?v=${encodeURIComponent(backgroundVersion)}`,
    );
  }, [shouldShowBackground, backgroundVersion, projectId]);

  return backgroundUrl;
}