1 import { type FC } from 'react';
2 import { useSelector } from 'react-redux';
3 import { Redirect } from 'react-router-dom';
5 import { useItems } from '@proton/pass/components/Item/Context/ItemsProvider';
6 import { useNavigation } from '@proton/pass/components/Navigation/NavigationProvider';
7 import { getItemRoute, getLocalPath } from '@proton/pass/components/Navigation/routing';
8 import { selectShare } from '@proton/pass/store/selectors';
10 export const Autoselect: FC = () => {
11 const { matchTrash: trashed, preserveSearch, filters } = useNavigation();
12 const { filtered } = useItems();
13 const autoselect = filtered[0];
15 /** Check if we should preserve the current filters (selected vault exists) */
16 const selectedVault = useSelector(selectShare(filters.selectedShareId));
17 const clearFilters = filters.selectedShareId !== null && selectedVault === undefined;
20 if (autoselect) return preserveSearch(getItemRoute(autoselect.shareId, autoselect.itemId, { trashed }));
21 if (clearFilters) return getLocalPath();
25 return to ? <Redirect exact to={to} push={false} /> : null;