supermemory/apps/web/hooks/use-project-name.ts
2025-08-21 08:40:44 -07:00

26 lines
884 B
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use client";
import { useQueryClient } from "@tanstack/react-query";
import { useMemo } from "react";
import { useProject } from "@/stores";
/**
* Returns the display name of the currently selected project.
* Falls back to the containerTag / id if a matching project record
* hasnt been fetched yet.
*/
export function useProjectName() {
const { selectedProject } = useProject();
const queryClient = useQueryClient();
// This query is populated by ProjectsView we just read from the cache.
const projects = queryClient.getQueryData(["projects"]) as
| Array<{ name: string; containerTag: string }>
| undefined;
return useMemo(() => {
if (selectedProject === "sm_project_default") return "Default Project";
const found = projects?.find((p) => p.containerTag === selectedProject);
return found?.name ?? selectedProject;
}, [projects, selectedProject]);
}