diff --git a/src/renderer/api/query-keys.ts b/src/renderer/api/query-keys.ts index db53c3ec..ad96655a 100644 --- a/src/renderer/api/query-keys.ts +++ b/src/renderer/api/query-keys.ts @@ -1,4 +1,5 @@ import { QueryFunctionContext } from '@tanstack/react-query'; +import { LyricSource } from './types'; import type { AlbumListQuery, SongListQuery, @@ -108,6 +109,9 @@ export const queryKeys: Record< if (query) return [serverId, 'song', 'lyrics', query] as const; return [serverId, 'song', 'lyrics'] as const; }, + lyricsByRemoteId: (searchQuery: { remoteSongId: string; remoteSource: LyricSource }) => { + return ['song', 'lyrics', 'remote', searchQuery] as const; + }, lyricsSearch: (query?: LyricSearchQuery) => { if (query) return ['lyrics', 'search', query] as const; return ['lyrics', 'search'] as const; diff --git a/src/renderer/features/lyrics/components/lyrics-search-form.tsx b/src/renderer/features/lyrics/components/lyrics-search-form.tsx index 5b4bd952..00a81448 100644 --- a/src/renderer/features/lyrics/components/lyrics-search-form.tsx +++ b/src/renderer/features/lyrics/components/lyrics-search-form.tsx @@ -1,32 +1,40 @@ import { useMemo } from 'react'; -import { Divider, Group, Stack, UnstyledButton } from '@mantine/core'; +import { Divider, Group, Stack } from '@mantine/core'; import { useForm } from '@mantine/form'; import { useDebouncedValue } from '@mantine/hooks'; import { openModal } from '@mantine/modals'; import styled from 'styled-components'; -import { InternetProviderLyricSearchResponse } from '../../../api/types'; +import { + InternetProviderLyricSearchResponse, + LyricSource, + LyricsOverride, +} from '../../../api/types'; import { useLyricSearch } from '../queries/lyric-search-query'; import { Badge, ScrollArea, Spinner, Text, TextInput } from '/@/renderer/components'; -const SearchItem = styled(UnstyledButton)` +const SearchItem = styled.button` + all: unset; + box-sizing: border-box !important; + padding: 0.5rem; + border-radius: 5px; + cursor: pointer; + &:hover, &:focus-visible { color: var(--btn-default-fg-hover); background: var(--btn-default-bg-hover); } - - padding: 0.5rem; - border-radius: 5px; `; interface SearchResultProps { artist?: string; name?: string; + onClick?: () => void; source?: string; } -const SearchResult = ({ name, artist, source }: SearchResultProps) => { +const SearchResult = ({ name, artist, source, onClick }: SearchResultProps) => { return ( - + { maw="65%" spacing={0} > - {name} + + {name} + {artist} {source} @@ -47,10 +60,10 @@ const SearchResult = ({ name, artist, source }: SearchResultProps) => { interface LyricSearchFormProps { artist?: string; name?: string; - onSelect?: (lyrics: InternetProviderLyricSearchResponse) => void; + onSearchOverride?: (params: LyricsOverride) => void; } -export const LyricsSearchForm = ({ artist, name }: LyricSearchFormProps) => { +export const LyricsSearchForm = ({ artist, name, onSearchOverride }: LyricSearchFormProps) => { const form = useForm({ initialValues: { artist: artist || '', @@ -69,8 +82,6 @@ export const LyricsSearchForm = ({ artist, name }: LyricSearchFormProps) => { const searchResults = useMemo(() => { if (!data) return []; - console.log('data', data); - const results: InternetProviderLyricSearchResponse[] = []; Object.keys(data).forEach((key) => { (data[key as keyof typeof data] || []).forEach((result) => results.push(result)); @@ -102,7 +113,7 @@ export const LyricsSearchForm = ({ artist, name }: LyricSearchFormProps) => { ) : ( @@ -112,6 +123,15 @@ export const LyricsSearchForm = ({ artist, name }: LyricSearchFormProps) => { artist={result.artist} name={result.name} source={result.source} + onClick={() => { + onSearchOverride?.({ + artist: result.artist, + id: result.id, + name: result.name, + remote: true, + source: result.source as LyricSource, + }); + }} /> ))} @@ -121,12 +141,13 @@ export const LyricsSearchForm = ({ artist, name }: LyricSearchFormProps) => { ); }; -export const openLyricSearchModal = ({ artist, name }: LyricSearchFormProps) => { +export const openLyricSearchModal = ({ artist, name, onSearchOverride }: LyricSearchFormProps) => { openModal({ children: ( ), size: 'lg', diff --git a/src/renderer/features/lyrics/lyrics-actions.tsx b/src/renderer/features/lyrics/lyrics-actions.tsx index 221bc271..bd15a449 100644 --- a/src/renderer/features/lyrics/lyrics-actions.tsx +++ b/src/renderer/features/lyrics/lyrics-actions.tsx @@ -1,19 +1,26 @@ import { RiAddFill, RiSubtractFill } from 'react-icons/ri'; +import { LyricsOverride } from '/@/renderer/api/types'; import { Button, NumberInput } from '/@/renderer/components'; import { openLyricSearchModal } from '/@/renderer/features/lyrics/components/lyrics-search-form'; import { useCurrentSong } from '/@/renderer/store'; -export const LyricsActions = () => { +interface LyricsActionsProps { + onSearchOverride?: (params: LyricsOverride) => void; +} + +export const LyricsActions = ({ onSearchOverride }: LyricsActionsProps) => { const currentSong = useCurrentSong(); return ( <> @@ -31,12 +38,13 @@ export const LyricsActions = () => { />