import { useParams } from 'common' import { motion } from 'framer-motion' import { ChevronRight, Plus, SquareCode } from 'lucide-react' import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader' import { EXPLORER_SECTIONS, ExplorerResourceType, LEVEL_OFFSET, LEVEL_TRANSITION, rowClassName, } from './ExplorerLayout.constants' import { formatRelativeTimeShort, getRecentlyUpdatedItems } from './ExplorerNavHome.utils' import { ExplorerNavItem } from './ExplorerNavItem' import { useExplorerDeleteItem } from './ExplorerProvider' import { ExplorerSqlEditorFooter } from './ExplorerSqlEditorFooter' import { useCreateQuery } from '@/components/interfaces/Explorer/hooks' import { useContentCountQuery } from '@/data/content/content-count-query' import { useNotebooksInfiniteQuery } from '@/data/content/notebooks/notebooks-infinite-query' import { useAiAssistantChatList } from '@/state/ai-assistant-state' import { createTabId, useTabsStateSnapshot } from '@/state/tabs' export const ExplorerNavHome = ({ onSelectSection, }: { onSelectSection: (section: ExplorerResourceType) => void }) => { const { id, ref } = useParams() const tabs = useTabsStateSnapshot() const { createQuery } = useCreateQuery() const { onSelectDelete } = useExplorerDeleteItem() const { data: notebooksData } = useNotebooksInfiniteQuery({ projectRef: ref, limit: 100 }) const notebooks = notebooksData?.pages.flatMap((page) => page.content) ?? [] const chats = useAiAssistantChatList() const { data: notebookCountData, isPending } = useContentCountQuery({ projectRef: ref, type: 'notebook', }) // [Joshen] Notebooks are all shared by default, none private const notebookCount = notebookCountData?.shared ?? 0 const recentItems = getRecentlyUpdatedItems({ notebooks, chats }) return (

Recently updated

{recentItems.length === 0 ? (

Nothing edited yet

) : ( recentItems.map((item) => { const isActive = id === item.id const href = item.type === 'chat' ? `/project/${ref}/explorer/chat/${item.id}` : `/project/${ref}/explorer/notebook/${item.id}` const onDoubleClick = () => { if (item.type === 'chat') { tabs.makeTabPermanent(createTabId('chat', { id: item.id })) } else { tabs.makeTabPermanent(createTabId('notebook', { id: item.id })) } } return ( onSelectDelete({ id: item.id, type: item.type, name: item.label }) } description={formatRelativeTimeShort(item.updatedAt)} /> ) }) )}
) }