2025-05-18 14:03:18 -07:00
|
|
|
import { closeAllModals, openModal } from '@mantine/modals';
|
2023-05-19 22:24:15 -07:00
|
|
|
import { nanoid } from 'nanoid/non-secure';
|
2025-05-18 14:03:18 -07:00
|
|
|
import { Dispatch, useCallback } from 'react';
|
2023-10-30 19:22:45 -07:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2023-05-19 22:24:15 -07:00
|
|
|
import { generatePath, useNavigate } from 'react-router';
|
|
|
|
|
import { createSearchParams } from 'react-router-dom';
|
2025-05-18 14:03:18 -07:00
|
|
|
|
2023-05-18 02:10:34 -07:00
|
|
|
import { CreatePlaylistForm } from '/@/renderer/features/playlists';
|
|
|
|
|
import { Command, CommandPalettePages } from '/@/renderer/features/search/components/command';
|
|
|
|
|
import { AppRoute } from '/@/renderer/router/routes';
|
|
|
|
|
import { useCurrentServer } from '/@/renderer/store';
|
2025-05-20 19:23:36 -07:00
|
|
|
import { LibraryItem, ServerType } from '/@/shared/types/domain-types';
|
2023-05-18 02:10:34 -07:00
|
|
|
|
|
|
|
|
interface HomeCommandsProps {
|
2023-07-01 19:10:05 -07:00
|
|
|
handleClose: () => void;
|
|
|
|
|
pages: CommandPalettePages[];
|
|
|
|
|
query: string;
|
|
|
|
|
setPages: Dispatch<CommandPalettePages[]>;
|
|
|
|
|
setQuery: Dispatch<string>;
|
2023-05-18 02:10:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const HomeCommands = ({
|
2025-05-18 14:03:18 -07:00
|
|
|
handleClose,
|
2023-07-01 19:10:05 -07:00
|
|
|
pages,
|
2025-05-18 14:03:18 -07:00
|
|
|
query,
|
2023-07-01 19:10:05 -07:00
|
|
|
setPages,
|
2025-05-18 14:03:18 -07:00
|
|
|
setQuery,
|
2023-05-18 02:10:34 -07:00
|
|
|
}: HomeCommandsProps) => {
|
2023-10-30 19:22:45 -07:00
|
|
|
const { t } = useTranslation();
|
2023-07-01 19:10:05 -07:00
|
|
|
const navigate = useNavigate();
|
|
|
|
|
const server = useCurrentServer();
|
2023-05-18 02:10:34 -07:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const handleCreatePlaylistModal = useCallback(() => {
|
|
|
|
|
handleClose();
|
2023-05-18 02:10:34 -07:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
openModal({
|
|
|
|
|
children: <CreatePlaylistForm onCancel={() => closeAllModals()} />,
|
|
|
|
|
size: server?.type === ServerType?.NAVIDROME ? 'xl' : 'sm',
|
2023-10-30 19:22:45 -07:00
|
|
|
title: t('form.createPlaylist.title', { postProcess: 'sentenceCase' }),
|
2023-07-01 19:10:05 -07:00
|
|
|
});
|
2023-10-30 19:22:45 -07:00
|
|
|
}, [handleClose, server?.type, t]);
|
2023-05-18 02:10:34 -07:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const handleSearch = () => {
|
|
|
|
|
navigate(
|
|
|
|
|
{
|
|
|
|
|
pathname: generatePath(AppRoute.SEARCH, { itemType: LibraryItem.SONG }),
|
|
|
|
|
search: createSearchParams({
|
|
|
|
|
query,
|
|
|
|
|
}).toString(),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
state: {
|
|
|
|
|
navigationId: nanoid(),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
handleClose();
|
|
|
|
|
setQuery('');
|
|
|
|
|
};
|
2023-05-18 02:10:34 -07:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
return (
|
|
|
|
|
<>
|
2023-10-30 19:22:45 -07:00
|
|
|
<Command.Group heading={t('page.globalSearch.title', { postProcess: 'titleCase' })}>
|
2023-07-01 19:10:05 -07:00
|
|
|
<Command.Item
|
|
|
|
|
onSelect={handleSearch}
|
2025-05-18 14:03:18 -07:00
|
|
|
value={t('common.search', { postProcess: 'sentenceCase' })}
|
2023-07-01 19:10:05 -07:00
|
|
|
>
|
2023-10-30 19:22:45 -07:00
|
|
|
{query
|
|
|
|
|
? t('page.globalSearch.commands.searchFor', {
|
|
|
|
|
postProcess: 'sentenceCase',
|
|
|
|
|
query,
|
|
|
|
|
})
|
|
|
|
|
: `${t('common.search', { postProcess: 'sentenceCase' })}...`}
|
|
|
|
|
</Command.Item>
|
|
|
|
|
<Command.Item onSelect={handleCreatePlaylistModal}>
|
|
|
|
|
{t('action.createPlaylist', { postProcess: 'sentenceCase' })}...
|
2023-07-01 19:10:05 -07:00
|
|
|
</Command.Item>
|
|
|
|
|
<Command.Item onSelect={() => setPages([...pages, CommandPalettePages.GO_TO])}>
|
2023-10-30 19:22:45 -07:00
|
|
|
{t('page.globalSearch.commands.goToPage', { postProcess: 'sentenceCase' })}...
|
2023-07-01 19:10:05 -07:00
|
|
|
</Command.Item>
|
|
|
|
|
<Command.Item
|
|
|
|
|
onSelect={() => setPages([...pages, CommandPalettePages.MANAGE_SERVERS])}
|
|
|
|
|
>
|
2023-10-30 19:22:45 -07:00
|
|
|
{t('page.globalSearch.commands.serverCommands', {
|
|
|
|
|
postProcess: 'sentenceCase',
|
|
|
|
|
})}
|
|
|
|
|
...
|
2023-07-01 19:10:05 -07:00
|
|
|
</Command.Item>
|
|
|
|
|
</Command.Group>
|
|
|
|
|
</>
|
|
|
|
|
);
|
2023-05-18 02:10:34 -07:00
|
|
|
};
|