import { useRef, useState } from "react"; import { observer } from "mobx-react-lite"; // ui import { Search, X } from "lucide-react"; // components import { ListLayout } from "@/components/core/list"; import { EmptyState } from "@/components/empty-state"; import { ViewListLoader } from "@/components/ui"; import { ProjectViewListItem } from "@/components/views"; // constants import { EmptyStateType } from "@/constants/empty-state"; // helper import { cn } from "@/helpers/common.helper"; // hooks import { useCommandPalette, useProjectView } from "@/hooks/store"; import useOutsideClickDetector from "@/hooks/use-outside-click-detector"; export const ProjectViewsList = observer(() => { // states const [searchQuery, setSearchQuery] = useState(""); const [isSearchOpen, setIsSearchOpen] = useState(searchQuery !== "" ? true : false); // refs const inputRef = useRef(null); // store hooks const { toggleCreateViewModal } = useCommandPalette(); const { projectViewIds, getViewById, loader } = useProjectView(); // outside click detector hook useOutsideClickDetector(inputRef, () => { if (isSearchOpen && searchQuery.trim() === "") setIsSearchOpen(false); }); if (loader || !projectViewIds) return ; // derived values const viewsList = projectViewIds.map((viewId) => getViewById(viewId)); const filteredViewsList = viewsList.filter((v) => v?.name.toLowerCase().includes(searchQuery.toLowerCase())); // handlers const handleInputKeyDown = (e: React.KeyboardEvent) => { if (e.key === "Escape") { if (searchQuery && searchQuery.trim() !== "") setSearchQuery(""); else { setIsSearchOpen(false); inputRef.current?.blur(); } } }; return ( <> {viewsList.length > 0 ? (
Project Views
{!isSearchOpen && ( )}
setSearchQuery(e.target.value)} onKeyDown={handleInputKeyDown} /> {isSearchOpen && ( )}
{filteredViewsList.length > 0 ? ( filteredViewsList.map((view) => ) ) : (

No results found

)}
) : ( toggleCreateViewModal(true)} /> )} ); });