2023-05-19 22:26:43 -07:00
|
|
|
import type { AgGridReact as AgGridReactType } from '@ag-grid-community/react/lib/agGridReact';
|
2025-05-18 14:03:18 -07:00
|
|
|
|
2023-05-19 22:26:43 -07:00
|
|
|
import debounce from 'lodash/debounce';
|
2025-05-18 14:03:18 -07:00
|
|
|
import { ChangeEvent, MutableRefObject } from 'react';
|
2024-02-03 15:05:33 -08:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2023-05-19 22:26:43 -07:00
|
|
|
import { generatePath, Link, useParams, useSearchParams } from 'react-router-dom';
|
2025-05-18 14:03:18 -07:00
|
|
|
|
2025-06-24 00:04:36 -07:00
|
|
|
import { PageHeader } from '/@/renderer/components/page-header/page-header';
|
2023-05-19 22:26:43 -07:00
|
|
|
import { FilterBar, LibraryHeaderBar } from '/@/renderer/features/shared';
|
2025-06-24 00:04:36 -07:00
|
|
|
import { SearchInput } from '/@/renderer/features/shared/components/search-input';
|
2023-05-19 22:26:43 -07:00
|
|
|
import { useContainerQuery } from '/@/renderer/hooks';
|
2023-07-20 00:37:05 -07:00
|
|
|
import { useListFilterRefresh } from '/@/renderer/hooks/use-list-filter-refresh';
|
2023-05-19 22:26:43 -07:00
|
|
|
import { AppRoute } from '/@/renderer/router/routes';
|
2025-05-20 19:23:36 -07:00
|
|
|
import { useCurrentServer, useListStoreByKey } from '/@/renderer/store';
|
2025-06-24 00:04:36 -07:00
|
|
|
import { Button } from '/@/shared/components/button/button';
|
|
|
|
|
import { Flex } from '/@/shared/components/flex/flex';
|
|
|
|
|
import { Group } from '/@/shared/components/group/group';
|
|
|
|
|
import { Stack } from '/@/shared/components/stack/stack';
|
2025-05-20 19:23:36 -07:00
|
|
|
import {
|
|
|
|
|
AlbumArtistListQuery,
|
|
|
|
|
AlbumListQuery,
|
|
|
|
|
LibraryItem,
|
|
|
|
|
SongListQuery,
|
|
|
|
|
} from '/@/shared/types/domain-types';
|
2023-05-19 22:26:43 -07:00
|
|
|
|
|
|
|
|
interface SearchHeaderProps {
|
2023-07-01 19:10:05 -07:00
|
|
|
navigationId: string;
|
|
|
|
|
tableRef: MutableRefObject<AgGridReactType | null>;
|
2023-05-19 22:26:43 -07:00
|
|
|
}
|
|
|
|
|
|
2025-05-18 14:03:18 -07:00
|
|
|
export const SearchHeader = ({ navigationId, tableRef }: SearchHeaderProps) => {
|
2024-02-03 15:05:33 -08:00
|
|
|
const { t } = useTranslation();
|
2023-07-01 19:10:05 -07:00
|
|
|
const { itemType } = useParams() as { itemType: LibraryItem };
|
|
|
|
|
const [searchParams, setSearchParams] = useSearchParams();
|
|
|
|
|
const cq = useContainerQuery();
|
2023-07-20 00:37:05 -07:00
|
|
|
const server = useCurrentServer();
|
2025-05-18 14:03:18 -07:00
|
|
|
const { filter } = useListStoreByKey<AlbumArtistListQuery | AlbumListQuery | SongListQuery>({
|
2024-09-26 04:23:08 +00:00
|
|
|
key: itemType,
|
|
|
|
|
});
|
2023-07-20 00:37:05 -07:00
|
|
|
|
|
|
|
|
const { handleRefreshTable } = useListFilterRefresh({
|
|
|
|
|
itemType,
|
|
|
|
|
server,
|
|
|
|
|
});
|
2023-05-19 22:26:43 -07:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const handleSearch = debounce((e: ChangeEvent<HTMLInputElement>) => {
|
|
|
|
|
setSearchParams({ query: e.target.value }, { replace: true, state: { navigationId } });
|
2024-03-31 13:20:01 -07:00
|
|
|
handleRefreshTable(tableRef, { ...filter, searchTerm: e.target.value });
|
2023-07-01 19:10:05 -07:00
|
|
|
}, 200);
|
2023-05-19 22:26:43 -07:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
return (
|
|
|
|
|
<Stack
|
2025-06-24 00:04:36 -07:00
|
|
|
gap={0}
|
2023-07-01 19:10:05 -07:00
|
|
|
ref={cq.ref}
|
2023-05-19 22:26:43 -07:00
|
|
|
>
|
2023-07-01 19:10:05 -07:00
|
|
|
<PageHeader>
|
|
|
|
|
<Flex
|
|
|
|
|
justify="space-between"
|
|
|
|
|
w="100%"
|
|
|
|
|
>
|
|
|
|
|
<LibraryHeaderBar>
|
|
|
|
|
<LibraryHeaderBar.Title>Search</LibraryHeaderBar.Title>
|
|
|
|
|
</LibraryHeaderBar>
|
|
|
|
|
<Group>
|
|
|
|
|
<SearchInput
|
|
|
|
|
defaultValue={searchParams.get('query') || ''}
|
|
|
|
|
onChange={handleSearch}
|
|
|
|
|
/>
|
|
|
|
|
</Group>
|
|
|
|
|
</Flex>
|
|
|
|
|
</PageHeader>
|
|
|
|
|
<FilterBar>
|
|
|
|
|
<Group>
|
|
|
|
|
<Button
|
|
|
|
|
component={Link}
|
|
|
|
|
fw={600}
|
2025-05-18 14:03:18 -07:00
|
|
|
replace
|
2025-06-24 00:04:36 -07:00
|
|
|
size="compact-md"
|
2023-07-01 19:10:05 -07:00
|
|
|
state={{ navigationId }}
|
|
|
|
|
to={{
|
|
|
|
|
pathname: generatePath(AppRoute.SEARCH, { itemType: LibraryItem.SONG }),
|
|
|
|
|
search: searchParams.toString(),
|
|
|
|
|
}}
|
|
|
|
|
variant={itemType === LibraryItem.SONG ? 'filled' : 'subtle'}
|
|
|
|
|
>
|
2024-02-03 15:05:33 -08:00
|
|
|
{t('entity.track_other', { postProcess: 'sentenceCase' })}
|
2023-07-01 19:10:05 -07:00
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
component={Link}
|
|
|
|
|
fw={600}
|
2025-05-18 14:03:18 -07:00
|
|
|
replace
|
2025-06-24 00:04:36 -07:00
|
|
|
size="compact-md"
|
2023-07-01 19:10:05 -07:00
|
|
|
state={{ navigationId }}
|
|
|
|
|
to={{
|
|
|
|
|
pathname: generatePath(AppRoute.SEARCH, {
|
|
|
|
|
itemType: LibraryItem.ALBUM,
|
|
|
|
|
}),
|
|
|
|
|
search: searchParams.toString(),
|
|
|
|
|
}}
|
|
|
|
|
variant={itemType === LibraryItem.ALBUM ? 'filled' : 'subtle'}
|
|
|
|
|
>
|
2024-02-03 15:05:33 -08:00
|
|
|
{t('entity.album_other', { postProcess: 'sentenceCase' })}
|
2023-07-01 19:10:05 -07:00
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
component={Link}
|
|
|
|
|
fw={600}
|
2025-05-18 14:03:18 -07:00
|
|
|
replace
|
2025-06-24 00:04:36 -07:00
|
|
|
size="compact-md"
|
2023-07-01 19:10:05 -07:00
|
|
|
state={{ navigationId }}
|
|
|
|
|
to={{
|
|
|
|
|
pathname: generatePath(AppRoute.SEARCH, {
|
|
|
|
|
itemType: LibraryItem.ALBUM_ARTIST,
|
|
|
|
|
}),
|
|
|
|
|
search: searchParams.toString(),
|
|
|
|
|
}}
|
|
|
|
|
variant={itemType === LibraryItem.ALBUM_ARTIST ? 'filled' : 'subtle'}
|
|
|
|
|
>
|
2024-02-03 15:05:33 -08:00
|
|
|
{t('entity.artist_other', { postProcess: 'sentenceCase' })}
|
2023-07-01 19:10:05 -07:00
|
|
|
</Button>
|
|
|
|
|
</Group>
|
|
|
|
|
</FilterBar>
|
|
|
|
|
</Stack>
|
|
|
|
|
);
|
2023-05-19 22:26:43 -07:00
|
|
|
};
|