🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
'use client';
import { Empty, Flexbox, SearchBar } from '@lobehub/ui';
import { SearchIcon } from 'lucide-react';
import { memo, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import SkeletonList from '@/features/NavPanel/components/SkeletonList';
import SideBarDrawer from '@/features/NavPanel/SideBarDrawer';
import { useHomeStore } from '@/store/home';
import { homeRecentSelectors } from '@/store/home/selectors';
import { createRecentQueryKey } from '@/store/home/slices/recent/initialState';
import { useDensityTokens } from '@/styles/density';
import ConnectedItem from './ConnectedItem';
interface AllRecentsDrawerProps {
onClose: () => void;
open: boolean;
}
const AllRecentsDrawer = memo<AllRecentsDrawerProps>(({ open, onClose }) => {
const { t } = useTranslation('common');
const { pagePaddingBlockEnd } = useDensityTokens();
const [searchKeyword, setSearchKeyword] = useState('');
const useFetchAllRecents = useHomeStore((s) => s.useFetchAllRecents);
const queryKey = createRecentQueryKey(50);
const items = useHomeStore(homeRecentSelectors.query(queryKey));
const { isHydrated, isValidating } = useFetchAllRecents(open);
const isLoading = !isHydrated || isValidating;
const filteredItems = useMemo(() => {
const keyword = searchKeyword.trim().toLowerCase();
if (!keyword) return items ?? [];
return items?.filter((item) => item.title.toLowerCase().includes(keyword)) ?? [];
}, [items, searchKeyword]);
return (
<SideBarDrawer
open={open}
title={t('recents')}
subHeader={
<Flexbox paddingBlock={'0 8px'} paddingInline={8}>
<SearchBar
allowClear
defaultValue={searchKeyword}
placeholder={t('navPanel.searchRecent')}
onSearch={(keyword) => setSearchKeyword(keyword)}
onInputChange={(keyword) => {
setSearchKeyword(keyword);
}}
/>
</Flexbox>
}
onClose={onClose}
>
<Flexbox gap={1} paddingBlock={1} paddingInline={4}>
{isLoading && !items ? (
<SkeletonList rows={5} />
) : filteredItems.length === 0 && searchKeyword.trim() ? (
<Empty
description={t('navPanel.searchResultEmpty')}
icon={SearchIcon}
style={{ paddingBlock: pagePaddingBlockEnd }}
/>
) : (
filteredItems.map((item) => {
const itemRef = `${item.type}:${item.id}` as const;
return <ConnectedItem itemRef={itemRef} key={itemRef} queryKey={queryKey} />;
})
)}
</Flexbox>
</SideBarDrawer>
);
});
AllRecentsDrawer.displayName = 'AllRecentsDrawer';
export default AllRecentsDrawer;