2024-06-11 14:27:59 +02:00
|
|
|
import {
|
2024-06-28 12:40:44 +02:00
|
|
|
CommandResultGroup,
|
|
|
|
RecentlyVisitedFeatureButton,
|
|
|
|
RecentlyVisitedPathButton,
|
|
|
|
RecentlyVisitedProjectButton,
|
|
|
|
} from './RecentlyVisited/CommandResultGroup';
|
2024-07-01 10:35:02 +02:00
|
|
|
import {
|
|
|
|
useRecentlyVisited,
|
|
|
|
type LastViewedPage,
|
|
|
|
} from 'hooks/useRecentlyVisited';
|
2024-06-11 14:27:59 +02:00
|
|
|
|
2024-06-14 11:22:55 +02:00
|
|
|
const toListItemButton = (
|
|
|
|
item: LastViewedPage,
|
|
|
|
routes: Record<string, { path: string; route: string; title: string }>,
|
|
|
|
index: number,
|
2024-07-03 13:41:23 +02:00
|
|
|
onClick: () => void,
|
2024-06-14 11:22:55 +02:00
|
|
|
) => {
|
|
|
|
const key = `recently-visited-${index}`;
|
|
|
|
if (item.featureId && item.projectId) {
|
|
|
|
return (
|
|
|
|
<RecentlyVisitedFeatureButton
|
2024-07-05 08:24:51 +02:00
|
|
|
keyName={key}
|
2024-06-14 11:22:55 +02:00
|
|
|
key={key}
|
|
|
|
featureId={item.featureId}
|
|
|
|
projectId={item.projectId}
|
2024-07-03 13:41:23 +02:00
|
|
|
onClick={onClick}
|
2024-06-14 11:22:55 +02:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (item.projectId) {
|
|
|
|
return (
|
|
|
|
<RecentlyVisitedProjectButton
|
2024-07-05 08:24:51 +02:00
|
|
|
keyName={key}
|
2024-06-14 11:22:55 +02:00
|
|
|
key={key}
|
|
|
|
projectId={item.projectId}
|
2024-07-03 13:41:23 +02:00
|
|
|
onClick={onClick}
|
2024-06-14 11:22:55 +02:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (!item.pathName) return null;
|
|
|
|
const name = routes[item.pathName]?.title ?? item.pathName;
|
|
|
|
return (
|
2024-07-03 13:41:23 +02:00
|
|
|
<RecentlyVisitedPathButton
|
2024-07-05 08:24:51 +02:00
|
|
|
keyName={key}
|
2024-07-03 13:41:23 +02:00
|
|
|
key={key}
|
|
|
|
path={item.pathName}
|
|
|
|
name={name}
|
|
|
|
onClick={onClick}
|
|
|
|
/>
|
2024-06-14 11:22:55 +02:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2024-07-02 12:59:18 +02:00
|
|
|
export const CommandQuickSuggestions = ({
|
2024-06-14 11:22:55 +02:00
|
|
|
routes,
|
2024-07-02 10:12:08 +02:00
|
|
|
onClick,
|
2024-06-14 11:22:55 +02:00
|
|
|
}: {
|
2024-07-02 10:12:08 +02:00
|
|
|
onClick: () => void;
|
2024-06-14 11:22:55 +02:00
|
|
|
routes: Record<string, { path: string; route: string; title: string }>;
|
|
|
|
}) => {
|
2024-07-01 10:35:02 +02:00
|
|
|
const { lastVisited } = useRecentlyVisited();
|
2024-06-14 11:22:55 +02:00
|
|
|
const buttons = lastVisited.map((item, index) =>
|
2024-07-03 13:41:23 +02:00
|
|
|
toListItemButton(item, routes, index, onClick),
|
2024-06-14 11:22:55 +02:00
|
|
|
);
|
2024-06-11 14:27:59 +02:00
|
|
|
return (
|
2024-07-02 10:12:08 +02:00
|
|
|
<CommandResultGroup
|
|
|
|
icon='default'
|
|
|
|
groupName='Quick suggestions'
|
|
|
|
onClick={onClick}
|
|
|
|
>
|
2024-07-02 11:33:37 +02:00
|
|
|
{buttons}
|
2024-06-28 12:40:44 +02:00
|
|
|
</CommandResultGroup>
|
2024-06-11 14:27:59 +02:00
|
|
|
);
|
|
|
|
};
|