2023-06-03 18:03:32 -07:00
|
|
|
import { Center, Group } from '@mantine/core';
|
2023-05-22 17:38:31 -07:00
|
|
|
import { ErrorBoundary } from 'react-error-boundary';
|
2023-06-02 23:54:34 -07:00
|
|
|
import { RiInformationFill } from 'react-icons/ri';
|
2023-06-05 02:50:01 -07:00
|
|
|
import { useSongLyrics } from './queries/lyric-query';
|
2023-06-03 18:03:32 -07:00
|
|
|
import { SynchronizedLyrics } from './synchronized-lyrics';
|
2023-06-05 02:50:01 -07:00
|
|
|
import { Spinner, TextTitle } from '/@/renderer/components';
|
|
|
|
|
import { ErrorFallback } from '/@/renderer/features/action-required';
|
|
|
|
|
import { UnsynchronizedLyrics } from '/@/renderer/features/lyrics/unsynchronized-lyrics';
|
|
|
|
|
import { getServerById, useCurrentSong } from '/@/renderer/store';
|
2023-05-22 17:38:31 -07:00
|
|
|
|
|
|
|
|
export const Lyrics = () => {
|
|
|
|
|
const currentSong = useCurrentSong();
|
2023-06-03 07:15:02 -07:00
|
|
|
const currentServer = getServerById(currentSong?.serverId);
|
2023-05-22 17:38:31 -07:00
|
|
|
|
2023-06-05 02:50:01 -07:00
|
|
|
const { data, isLoading } = useSongLyrics(
|
|
|
|
|
{
|
|
|
|
|
query: { songId: currentSong?.id || '' },
|
|
|
|
|
serverId: currentServer?.id,
|
|
|
|
|
},
|
|
|
|
|
currentSong,
|
|
|
|
|
);
|
2023-05-22 17:38:31 -07:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<ErrorBoundary FallbackComponent={ErrorFallback}>
|
2023-06-05 02:50:01 -07:00
|
|
|
{isLoading ? (
|
|
|
|
|
<Spinner
|
|
|
|
|
container
|
|
|
|
|
size={25}
|
|
|
|
|
/>
|
|
|
|
|
) : !data?.lyrics ? (
|
2023-06-04 16:20:21 -07:00
|
|
|
<Center p="2rem">
|
2023-06-02 23:54:34 -07:00
|
|
|
<Group>
|
|
|
|
|
<RiInformationFill size="2rem" />
|
|
|
|
|
<TextTitle
|
|
|
|
|
order={3}
|
|
|
|
|
weight={700}
|
|
|
|
|
>
|
|
|
|
|
No lyrics found
|
|
|
|
|
</TextTitle>
|
|
|
|
|
</Group>
|
|
|
|
|
</Center>
|
2023-06-04 16:20:21 -07:00
|
|
|
) : (
|
|
|
|
|
<>
|
2023-06-05 02:50:01 -07:00
|
|
|
{Array.isArray(data.lyrics) ? (
|
2023-06-04 16:20:21 -07:00
|
|
|
<SynchronizedLyrics
|
2023-06-05 02:50:01 -07:00
|
|
|
lyrics={data.lyrics}
|
|
|
|
|
override={null}
|
|
|
|
|
source={data.source}
|
|
|
|
|
onRemoveLyric={() => {}}
|
2023-06-04 16:20:21 -07:00
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<UnsynchronizedLyrics
|
2023-06-05 02:50:01 -07:00
|
|
|
lyrics={data.lyrics}
|
|
|
|
|
override={null}
|
|
|
|
|
source={data.source}
|
|
|
|
|
onRemoveLyric={() => {}}
|
2023-06-04 16:20:21 -07:00
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
2023-06-02 23:54:34 -07:00
|
|
|
)}
|
2023-05-22 17:38:31 -07:00
|
|
|
</ErrorBoundary>
|
|
|
|
|
);
|
|
|
|
|
};
|