mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Fix bug with initial keystroke resulting in empty search
This commit is contained in:
parent
ad01e8669d
commit
d9aa7319be
3 changed files with 9 additions and 14 deletions
|
@ -9,7 +9,7 @@ import { MediaType } from '@jellyfin/sdk/lib/generated-client/models/media-type'
|
||||||
import { BaseItemKind } from '@jellyfin/sdk/lib/generated-client/models/base-item-kind';
|
import { BaseItemKind } from '@jellyfin/sdk/lib/generated-client/models/base-item-kind';
|
||||||
import { ItemsApiGetItemsRequest } from '@jellyfin/sdk/lib/generated-client/api/items-api';
|
import { ItemsApiGetItemsRequest } from '@jellyfin/sdk/lib/generated-client/api/items-api';
|
||||||
|
|
||||||
const fetchPeople = async (
|
const fetchVideos = async (
|
||||||
api: Api,
|
api: Api,
|
||||||
userId: string,
|
userId: string,
|
||||||
params?: ItemsApiGetItemsRequest,
|
params?: ItemsApiGetItemsRequest,
|
||||||
|
@ -43,7 +43,7 @@ export const useVideoSearch = (
|
||||||
|
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ['VideoSearch', collectionType, parentId, searchTerm],
|
queryKey: ['VideoSearch', collectionType, parentId, searchTerm],
|
||||||
queryFn: ({ signal }) => fetchPeople(
|
queryFn: ({ signal }) => fetchVideos(
|
||||||
api!,
|
api!,
|
||||||
userId!,
|
userId!,
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import React, { useCallback, type FC } from 'react';
|
import React, { type FC } from 'react';
|
||||||
import { useSearchItems } from '../api/useSearchItems';
|
import { useSearchItems } from '../api/useSearchItems';
|
||||||
import globalize from '../../../../../lib/globalize';
|
import globalize from '../../../../../lib/globalize';
|
||||||
import Loading from '../../../../../components/loading/LoadingComponent';
|
import Loading from '../../../../../components/loading/LoadingComponent';
|
||||||
|
@ -6,8 +6,7 @@ import SearchResultsRow from './SearchResultsRow';
|
||||||
import { CardShape } from 'utils/card';
|
import { CardShape } from 'utils/card';
|
||||||
import { CollectionType } from '@jellyfin/sdk/lib/generated-client/models/collection-type';
|
import { CollectionType } from '@jellyfin/sdk/lib/generated-client/models/collection-type';
|
||||||
import { Section } from '../types';
|
import { Section } from '../types';
|
||||||
import LinkButton from 'elements/emby-button/LinkButton';
|
import { Link } from 'react-router-dom';
|
||||||
import { useLocation, useSearchParams } from 'react-router-dom';
|
|
||||||
|
|
||||||
interface SearchResultsProps {
|
interface SearchResultsProps {
|
||||||
parentId?: string;
|
parentId?: string;
|
||||||
|
@ -24,13 +23,6 @@ const SearchResults: FC<SearchResultsProps> = ({
|
||||||
query
|
query
|
||||||
}) => {
|
}) => {
|
||||||
const { data, isPending } = useSearchItems(parentId, collectionType, query?.trim());
|
const { data, isPending } = useSearchItems(parentId, collectionType, query?.trim());
|
||||||
const location = useLocation();
|
|
||||||
const [ searchParams ] = useSearchParams();
|
|
||||||
|
|
||||||
const getUri = useCallback(() => {
|
|
||||||
searchParams.delete('collectionType');
|
|
||||||
return `${location.pathname}?${searchParams.toString()}`;
|
|
||||||
}, [ searchParams, location.pathname ]);
|
|
||||||
|
|
||||||
if (isPending) return <Loading />;
|
if (isPending) return <Loading />;
|
||||||
|
|
||||||
|
@ -40,7 +32,10 @@ const SearchResults: FC<SearchResultsProps> = ({
|
||||||
{globalize.translate('SearchResultsEmpty', query)}
|
{globalize.translate('SearchResultsEmpty', query)}
|
||||||
{collectionType && (
|
{collectionType && (
|
||||||
<div>
|
<div>
|
||||||
<LinkButton href={getUri()}>{globalize.translate('RetryWithGlobalSearch')}</LinkButton>
|
<Link
|
||||||
|
className='emby-button'
|
||||||
|
to={`/search.html?query=${encodeURIComponent(query || '')}`}
|
||||||
|
>{globalize.translate('RetryWithGlobalSearch')}</Link>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -51,7 +51,7 @@ const Search: FC = () => {
|
||||||
className='mainAnimatedPage libraryPage allLibraryPage noSecondaryNavPage'
|
className='mainAnimatedPage libraryPage allLibraryPage noSecondaryNavPage'
|
||||||
>
|
>
|
||||||
<SearchFields query={query} onSearch={setQuery} />
|
<SearchFields query={query} onSearch={setQuery} />
|
||||||
{!query ? (
|
{!debouncedQuery ? (
|
||||||
<SearchSuggestions
|
<SearchSuggestions
|
||||||
parentId={parentIdQuery}
|
parentId={parentIdQuery}
|
||||||
/>
|
/>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue