feishin/src/renderer/features/lyrics/queries/lyric-search-query.ts

25 lines
833 B
TypeScript
Raw Normal View History

2023-06-08 03:40:34 -07:00
import { useQuery } from '@tanstack/react-query';
import isElectron from 'is-electron';
import { queryKeys } from '/@/renderer/api/query-keys';
import {
InternetProviderLyricSearchResponse,
LyricSearchQuery,
LyricSource,
} from '/@/renderer/api/types';
2023-06-08 03:40:34 -07:00
import { QueryHookArgs } from '/@/renderer/lib/react-query';
const lyricsIpc = isElectron() ? window.electron.lyrics : null;
export const useLyricSearch = (args: Omit<QueryHookArgs<LyricSearchQuery>, 'serverId'>) => {
const { options, query } = args;
return useQuery<Record<LyricSource, InternetProviderLyricSearchResponse[]>>({
cacheTime: 1000 * 60 * 1,
2023-06-09 04:08:33 -07:00
enabled: !!query.artist || !!query.name,
2023-06-08 03:40:34 -07:00
queryFn: () => lyricsIpc?.searchRemoteLyrics(query),
queryKey: queryKeys.songs.lyricsSearch(query),
staleTime: 1000 * 60 * 1,
...options,
});
};